Simplified parsing for double quoted strings
authoraxelcl <axelcl>
Sun, 15 May 2005 23:32:28 +0000 (23:32 +0000)
committeraxelcl <axelcl>
Sun, 15 May 2005 23:32:28 +0000 (23:32 +0000)
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java

index 8b6a74e..7b3cbcd 100644 (file)
@@ -1,10 +1,10 @@
 /**********************************************************************
  Copyright (c) 2002 IBM Corp. and others.
- All rights reserved.   This program and the accompanying materials
+ All rights reserved. � This program and the accompanying materials
  are made available under the terms of the Common Public License v0.5
  which accompanies this distribution, and is available at
  http://www.eclipse.org/legal/cpl-v05.html
-  
+ �
  Contributors:
  IBM Corporation - initial API and implementation
  **********************************************************************/
@@ -100,12 +100,12 @@ public interface ITerminalSymbols {
   final static int TokenNameobjectCAST = 179;
   final static int TokenNameunsetCAST = 180;
   
-  // ´
+  // �
   final static int TokenNameEncapsedString0 = 190;
   // '
-  final static int TokenNameEncapsedString1 = 191;
+//  final static int TokenNameEncapsedString1 = 191;
   // "
-  final static int TokenNameEncapsedString2 = 192;
+//  final static int TokenNameEncapsedString2 = 192;
   
   final static int TokenNameSTRING = 193;
   
index 8770f4a..fb1b3cc 100644 (file)
@@ -789,7 +789,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
         expr();
         if (token == TokenNameSEMICOLON) {
           getNextToken();
-        } 
+        }
         if (token != TokenNameINLINE_HTML) {
           throwSyntaxError("Missing '?>' for open PHP expression block ('<?=').");
         }
@@ -2360,68 +2360,68 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
       //       | '`' encaps_list '`'
       //  | common_scalar
       //       | '`' encaps_list '`'
-      case TokenNameEncapsedString0:
-        scanner.encapsedStringStack.push(new Character('`'));
-        getNextToken();
-        try {
-          if (token == TokenNameEncapsedString0) {
-          } else {
-            encaps_list();
-            if (token != TokenNameEncapsedString0) {
-              throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
-            }
-          }
-        } finally {
-          scanner.encapsedStringStack.pop();
-          getNextToken();
-        }
-        break;
-      //      | '\'' encaps_list '\''
-      case TokenNameEncapsedString1:
-        scanner.encapsedStringStack.push(new Character('\''));
-        getNextToken();
-        try {
-          exprSourceStart = scanner.getCurrentTokenStartPosition();
-          if (token == TokenNameEncapsedString1) {
-            expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
-                .getCurrentTokenEndPosition());
-          } else {
-            encaps_list();
-            if (token != TokenNameEncapsedString1) {
-              throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
-            } else {
-              expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
-                  .getCurrentTokenEndPosition());
-            }
-          }
-        } finally {
-          scanner.encapsedStringStack.pop();
-          getNextToken();
-        }
-        break;
-      //| '"' encaps_list '"'
-      case TokenNameEncapsedString2:
-        scanner.encapsedStringStack.push(new Character('"'));
-        getNextToken();
-        try {
-          exprSourceStart = scanner.getCurrentTokenStartPosition();
-          if (token == TokenNameEncapsedString2) {
-            expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
-                .getCurrentTokenEndPosition());
-          } else {
-            encaps_list();
-            if (token != TokenNameEncapsedString2) {
-              throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
-            } else {
-              expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
-                  .getCurrentTokenEndPosition());
-            }
-          }
-        } finally {
-          scanner.encapsedStringStack.pop();
-          getNextToken();
-        }
-        break;
+      //      case TokenNameEncapsedString0:
+      //        scanner.encapsedStringStack.push(new Character('`'));
+      //        getNextToken();
+      //        try {
+      //          if (token == TokenNameEncapsedString0) {
+      //          } else {
+      //            encaps_list();
+      //            if (token != TokenNameEncapsedString0) {
+      //              throwSyntaxError("\'`\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
+      //            }
+      //          }
+      //        } finally {
+      //          scanner.encapsedStringStack.pop();
+      //          getNextToken();
+      //        }
+      //        break;
+      //      // | '\'' encaps_list '\''
+      //      case TokenNameEncapsedString1:
+      //        scanner.encapsedStringStack.push(new Character('\''));
+      //        getNextToken();
+      //        try {
+      //          exprSourceStart = scanner.getCurrentTokenStartPosition();
+      //          if (token == TokenNameEncapsedString1) {
+      //            expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
+      //                .getCurrentTokenEndPosition());
+      //          } else {
+      //            encaps_list();
+      //            if (token != TokenNameEncapsedString1) {
+      //              throwSyntaxError("\'\'\' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
+      //            } else {
+      //              expression = new StringLiteralSQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
+      //                  .getCurrentTokenEndPosition());
+      //            }
+      //          }
+      //        } finally {
+      //          scanner.encapsedStringStack.pop();
+      //          getNextToken();
+      //        }
+      //        break;
+      //      //| '"' encaps_list '"'
+      //      case TokenNameEncapsedString2:
+      //        scanner.encapsedStringStack.push(new Character('"'));
+      //        getNextToken();
+      //        try {
+      //          exprSourceStart = scanner.getCurrentTokenStartPosition();
+      //          if (token == TokenNameEncapsedString2) {
+      //            expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
+      //                .getCurrentTokenEndPosition());
+      //          } else {
+      //            encaps_list();
+      //            if (token != TokenNameEncapsedString2) {
+      //              throwSyntaxError("'\"' expected at end of string" + "(Found token: " + scanner.toStringAction(token) + " )");
+      //            } else {
+      //              expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(exprSourceStart), exprSourceStart, scanner
+      //                  .getCurrentTokenEndPosition());
+      //            }
+      //          }
+      //        } finally {
+      //          scanner.encapsedStringStack.pop();
+      //          getNextToken();
+      //        }
+      //        break;
       case TokenNameStringDoubleQuote:
         expression = new StringLiteralDQ(scanner.getCurrentStringLiteralSource(), scanner.getCurrentTokenStartPosition(), scanner
             .getCurrentTokenEndPosition());
@@ -3401,223 +3401,223 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
     getNextToken();
   }
 
-  private void encaps_list() {
-    //                 encaps_list encaps_var
-    //         | encaps_list T_STRING
-    //         | encaps_list T_NUM_STRING
-    //         | encaps_list T_ENCAPSED_AND_WHITESPACE
-    //         | encaps_list T_CHARACTER
-    //         | encaps_list T_BAD_CHARACTER
-    //         | encaps_list '['
-    //         | encaps_list ']'
-    //         | encaps_list '{'
-    //         | encaps_list '}'
-    //         | encaps_list T_OBJECT_OPERATOR
-    //         | /* empty */
-    while (true) {
-      switch (token) {
-      case TokenNameSTRING:
-        getNextToken();
-        break;
-      case TokenNameLBRACE:
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-        break;
-      case TokenNameRBRACE:
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-        break;
-      case TokenNameLBRACKET:
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-        break;
-      case TokenNameRBRACKET:
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-        break;
-      case TokenNameMINUS_GREATER:
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-        break;
-      case TokenNameVariable:
-      case TokenNameDOLLAR_LBRACE:
-      case TokenNameLBRACE_DOLLAR:
-        encaps_var();
-        break;
-      default:
-        char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
-        if (encapsedChar == '$') {
-          scanner.encapsedStringStack.pop();
-          encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
-          switch (encapsedChar) {
-          case '`':
-            if (token == TokenNameEncapsedString0) {
-              return;
-            }
-            token = TokenNameSTRING;
-            continue;
-          case '\'':
-            if (token == TokenNameEncapsedString1) {
-              return;
-            }
-            token = TokenNameSTRING;
-            continue;
-          case '"':
-            if (token == TokenNameEncapsedString2) {
-              return;
-            }
-            token = TokenNameSTRING;
-            continue;
-          }
-        }
-        return;
-      }
-    }
-  }
+  //  private void encaps_list() {
+  //    // encaps_list encaps_var
+  //    // | encaps_list T_STRING
+  //    // | encaps_list T_NUM_STRING
+  //    // | encaps_list T_ENCAPSED_AND_WHITESPACE
+  //    // | encaps_list T_CHARACTER
+  //    // | encaps_list T_BAD_CHARACTER
+  //    // | encaps_list '['
+  //    // | encaps_list ']'
+  //    // | encaps_list '{'
+  //    // | encaps_list '}'
+  //    // | encaps_list T_OBJECT_OPERATOR
+  //    // | /* empty */
+  //    while (true) {
+  //      switch (token) {
+  //      case TokenNameSTRING:
+  //        getNextToken();
+  //        break;
+  //      case TokenNameLBRACE:
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //        break;
+  //      case TokenNameRBRACE:
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //        break;
+  //      case TokenNameLBRACKET:
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //        break;
+  //      case TokenNameRBRACKET:
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //        break;
+  //      case TokenNameMINUS_GREATER:
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //        break;
+  //      case TokenNameVariable:
+  //      case TokenNameDOLLAR_LBRACE:
+  //      case TokenNameLBRACE_DOLLAR:
+  //        encaps_var();
+  //        break;
+  //      default:
+  //        char encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
+  //        if (encapsedChar == '$') {
+  //          scanner.encapsedStringStack.pop();
+  //          encapsedChar = ((Character) scanner.encapsedStringStack.peek()).charValue();
+  //          switch (encapsedChar) {
+  //          case '`':
+  //            if (token == TokenNameEncapsedString0) {
+  //              return;
+  //            }
+  //            token = TokenNameSTRING;
+  //            continue;
+  //          case '\'':
+  //            if (token == TokenNameEncapsedString1) {
+  //              return;
+  //            }
+  //            token = TokenNameSTRING;
+  //            continue;
+  //          case '"':
+  //            if (token == TokenNameEncapsedString2) {
+  //              return;
+  //            }
+  //            token = TokenNameSTRING;
+  //            continue;
+  //          }
+  //        }
+  //        return;
+  //      }
+  //    }
+  //  }
 
-  private void encaps_var() {
-    //                 T_VARIABLE
-    //         | T_VARIABLE '[' encaps_var_offset ']'
-    //         | T_VARIABLE T_OBJECT_OPERATOR T_STRING
-    //         | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
-    //         | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
-    //         | T_CURLY_OPEN variable '}'
-    switch (token) {
-    case TokenNameVariable:
-      getNextToken();
-      if (token == TokenNameLBRACKET) {
-        getNextToken();
-        expr(); //encaps_var_offset();
-        if (token != TokenNameRBRACKET) {
-          throwSyntaxError("']' expected after variable.");
-        }
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-        //          }
-      } else if (token == TokenNameMINUS_GREATER) {
-        getNextToken();
-        if (token != TokenNameIdentifier) {
-          throwSyntaxError("Identifier expected after '->'.");
-        }
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-      }
-      //        else {
-      //          // scanner.encapsedStringStack.pop();
-      //          int tempToken = TokenNameSTRING;
-      //          if (!scanner.encapsedStringStack.isEmpty()
-      //              && (token == TokenNameEncapsedString0
-      //                  || token == TokenNameEncapsedString1
-      //                  || token == TokenNameEncapsedString2 || token ==
-      // TokenNameERROR)) {
-      //            char encapsedChar = ((Character)
-      // scanner.encapsedStringStack.peek())
-      //                .charValue();
-      //            switch (token) {
-      //              case TokenNameEncapsedString0 :
-      //                if (encapsedChar == '`') {
-      //                  tempToken = TokenNameEncapsedString0;
-      //                }
-      //                break;
-      //              case TokenNameEncapsedString1 :
-      //                if (encapsedChar == '\'') {
-      //                  tempToken = TokenNameEncapsedString1;
-      //                }
-      //                break;
-      //              case TokenNameEncapsedString2 :
-      //                if (encapsedChar == '"') {
-      //                  tempToken = TokenNameEncapsedString2;
-      //                }
-      //                break;
-      //              case TokenNameERROR :
-      //                if (scanner.source[scanner.currentPosition - 1] == '\\') {
-      //                  scanner.currentPosition--;
-      //                  getNextToken();
-      //                }
-      //                break;
-      //            }
-      //          }
-      //          token = tempToken;
-      //        }
-      break;
-    case TokenNameDOLLAR_LBRACE:
-      getNextToken();
-      if (token == TokenNameDOLLAR_LBRACE) {
-        encaps_var();
-      } else if (token == TokenNameIdentifier) {
-        getNextToken();
-        if (token == TokenNameLBRACKET) {
-          getNextToken();
-          //            if (token == TokenNameRBRACKET) {
-          //              getNextToken();
-          //            } else {
-          expr();
-          if (token != TokenNameRBRACKET) {
-            throwSyntaxError("']' expected after '${'.");
-          }
-          getNextToken();
-          //            }
-        }
-      } else {
-        expr();
-      }
-      if (token != TokenNameRBRACE) {
-        throwSyntaxError("'}' expected.");
-      }
-      getNextToken();
-      break;
-    case TokenNameLBRACE_DOLLAR:
-      getNextToken();
-      if (token == TokenNameLBRACE_DOLLAR) {
-        encaps_var();
-      } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
-        getNextToken();
-        if (token == TokenNameLBRACKET) {
-          getNextToken();
-          //            if (token == TokenNameRBRACKET) {
-          //              getNextToken();
-          //            } else {
-          expr();
-          if (token != TokenNameRBRACKET) {
-            throwSyntaxError("']' expected.");
-          }
-          getNextToken();
-          //            }
-        } else if (token == TokenNameMINUS_GREATER) {
-          getNextToken();
-          if (token != TokenNameIdentifier && token != TokenNameVariable) {
-            throwSyntaxError("String or Variable token expected.");
-          }
-          getNextToken();
-          if (token == TokenNameLBRACKET) {
-            getNextToken();
-            //            if (token == TokenNameRBRACKET) {
-            //              getNextToken();
-            //            } else {
-            expr();
-            if (token != TokenNameRBRACKET) {
-              throwSyntaxError("']' expected after '${'.");
-            }
-            getNextToken();
-            //            }
-          }
-        }
-        //          if (token != TokenNameRBRACE) {
-        //            throwSyntaxError("'}' expected after '{$'.");
-        //          }
-        //          // scanner.encapsedStringStack.pop();
-        //          getNextToken();
-      } else {
-        expr();
-        if (token != TokenNameRBRACE) {
-          throwSyntaxError("'}' expected.");
-        }
-        //          scanner.encapsedStringStack.pop();
-        getNextToken();
-      }
-      break;
-    }
-  }
+  //  private void encaps_var() {
+  //    // T_VARIABLE
+  //    // | T_VARIABLE '[' encaps_var_offset ']'
+  //    // | T_VARIABLE T_OBJECT_OPERATOR T_STRING
+  //    // | T_DOLLAR_OPEN_CURLY_BRACES expr '}'
+  //    // | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'
+  //    // | T_CURLY_OPEN variable '}'
+  //    switch (token) {
+  //    case TokenNameVariable:
+  //      getNextToken();
+  //      if (token == TokenNameLBRACKET) {
+  //        getNextToken();
+  //        expr(); //encaps_var_offset();
+  //        if (token != TokenNameRBRACKET) {
+  //          throwSyntaxError("']' expected after variable.");
+  //        }
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //        // }
+  //      } else if (token == TokenNameMINUS_GREATER) {
+  //        getNextToken();
+  //        if (token != TokenNameIdentifier) {
+  //          throwSyntaxError("Identifier expected after '->'.");
+  //        }
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //      }
+  //      // else {
+  //      // // scanner.encapsedStringStack.pop();
+  //      // int tempToken = TokenNameSTRING;
+  //      // if (!scanner.encapsedStringStack.isEmpty()
+  //      // && (token == TokenNameEncapsedString0
+  //      // || token == TokenNameEncapsedString1
+  //      // || token == TokenNameEncapsedString2 || token ==
+  //      // TokenNameERROR)) {
+  //      // char encapsedChar = ((Character)
+  //      // scanner.encapsedStringStack.peek())
+  //      // .charValue();
+  //      // switch (token) {
+  //      // case TokenNameEncapsedString0 :
+  //      // if (encapsedChar == '`') {
+  //      // tempToken = TokenNameEncapsedString0;
+  //      // }
+  //      // break;
+  //      // case TokenNameEncapsedString1 :
+  //      // if (encapsedChar == '\'') {
+  //      // tempToken = TokenNameEncapsedString1;
+  //      // }
+  //      // break;
+  //      // case TokenNameEncapsedString2 :
+  //      // if (encapsedChar == '"') {
+  //      // tempToken = TokenNameEncapsedString2;
+  //      // }
+  //      // break;
+  //      // case TokenNameERROR :
+  //      // if (scanner.source[scanner.currentPosition - 1] == '\\') {
+  //      // scanner.currentPosition--;
+  //      // getNextToken();
+  //      // }
+  //      // break;
+  //      // }
+  //      // }
+  //      // token = tempToken;
+  //      // }
+  //      break;
+  //    case TokenNameDOLLAR_LBRACE:
+  //      getNextToken();
+  //      if (token == TokenNameDOLLAR_LBRACE) {
+  //        encaps_var();
+  //      } else if (token == TokenNameIdentifier) {
+  //        getNextToken();
+  //        if (token == TokenNameLBRACKET) {
+  //          getNextToken();
+  //          // if (token == TokenNameRBRACKET) {
+  //          // getNextToken();
+  //          // } else {
+  //          expr();
+  //          if (token != TokenNameRBRACKET) {
+  //            throwSyntaxError("']' expected after '${'.");
+  //          }
+  //          getNextToken();
+  //          // }
+  //        }
+  //      } else {
+  //        expr();
+  //      }
+  //      if (token != TokenNameRBRACE) {
+  //        throwSyntaxError("'}' expected.");
+  //      }
+  //      getNextToken();
+  //      break;
+  //    case TokenNameLBRACE_DOLLAR:
+  //      getNextToken();
+  //      if (token == TokenNameLBRACE_DOLLAR) {
+  //        encaps_var();
+  //      } else if (token == TokenNameIdentifier || token > TokenNameKEYWORD) {
+  //        getNextToken();
+  //        if (token == TokenNameLBRACKET) {
+  //          getNextToken();
+  //          // if (token == TokenNameRBRACKET) {
+  //          // getNextToken();
+  //          // } else {
+  //          expr();
+  //          if (token != TokenNameRBRACKET) {
+  //            throwSyntaxError("']' expected.");
+  //          }
+  //          getNextToken();
+  //          // }
+  //        } else if (token == TokenNameMINUS_GREATER) {
+  //          getNextToken();
+  //          if (token != TokenNameIdentifier && token != TokenNameVariable) {
+  //            throwSyntaxError("String or Variable token expected.");
+  //          }
+  //          getNextToken();
+  //          if (token == TokenNameLBRACKET) {
+  //            getNextToken();
+  //            // if (token == TokenNameRBRACKET) {
+  //            // getNextToken();
+  //            // } else {
+  //            expr();
+  //            if (token != TokenNameRBRACKET) {
+  //              throwSyntaxError("']' expected after '${'.");
+  //            }
+  //            getNextToken();
+  //            // }
+  //          }
+  //        }
+  //        // if (token != TokenNameRBRACE) {
+  //        // throwSyntaxError("'}' expected after '{$'.");
+  //        // }
+  //        // // scanner.encapsedStringStack.pop();
+  //        // getNextToken();
+  //      } else {
+  //        expr();
+  //        if (token != TokenNameRBRACE) {
+  //          throwSyntaxError("'}' expected.");
+  //        }
+  //        // scanner.encapsedStringStack.pop();
+  //        getNextToken();
+  //      }
+  //      break;
+  //    }
+  //  }
 
   private void encaps_var_offset() {
     //                 T_STRING
@@ -3902,33 +3902,39 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI
         throwSyntaxError("'`' expected at end of static string.");
       }
       break;
-    case TokenNameEncapsedString1:
-      try {
-        scanner.currentCharacter = scanner.source[scanner.currentPosition++];
-        while (scanner.currentCharacter != '\'') {
-          if (scanner.currentCharacter == '\\') {
-            scanner.currentPosition++;
-          }
-          scanner.currentCharacter = scanner.source[scanner.currentPosition++];
-        }
-        getNextToken();
-      } catch (IndexOutOfBoundsException e) {
-        throwSyntaxError("'\'' expected at end of static string.");
-      }
+    //    case TokenNameEncapsedString1:
+    //      try {
+    //        scanner.currentCharacter = scanner.source[scanner.currentPosition++];
+    //        while (scanner.currentCharacter != '\'') {
+    //          if (scanner.currentCharacter == '\\') {
+    //            scanner.currentPosition++;
+    //          }
+    //          scanner.currentCharacter = scanner.source[scanner.currentPosition++];
+    //        }
+    //        getNextToken();
+    //      } catch (IndexOutOfBoundsException e) {
+    //        throwSyntaxError("'\'' expected at end of static string.");
+    //      }
+    //      break;
+    //    case TokenNameEncapsedString2:
+    //      try {
+    //        scanner.currentCharacter = scanner.source[scanner.currentPosition++];
+    //        while (scanner.currentCharacter != '"') {
+    //          if (scanner.currentCharacter == '\\') {
+    //            scanner.currentPosition++;
+    //          }
+    //          scanner.currentCharacter = scanner.source[scanner.currentPosition++];
+    //        }
+    //        getNextToken();
+    //      } catch (IndexOutOfBoundsException e) {
+    //        throwSyntaxError("'\"' expected at end of static string.");
+    //      }
+    //      break;
+    case TokenNameStringSingleQuote:
+      getNextToken();
       break;
-    case TokenNameEncapsedString2:
-      try {
-        scanner.currentCharacter = scanner.source[scanner.currentPosition++];
-        while (scanner.currentCharacter != '"') {
-          if (scanner.currentCharacter == '\\') {
-            scanner.currentPosition++;
-          }
-          scanner.currentCharacter = scanner.source[scanner.currentPosition++];
-        }
-        getNextToken();
-      } catch (IndexOutOfBoundsException e) {
-        throwSyntaxError("'\"' expected at end of static string.");
-      }
+    case TokenNameStringDoubleQuote:
+      getNextToken();
       break;
     case TokenNamePLUS:
       getNextToken();
index 2965347..751e8c0 100644 (file)
@@ -38,10 +38,10 @@ public class Scanner implements IScanner, ITerminalSymbols {
   public boolean ignorePHPOneLiner = false;
 
   public boolean phpMode = false;
-  
+
   public boolean phpExpressionTag = false;
-  
-  public Stack encapsedStringStack = null;
+
+//  public Stack encapsedStringStack = null;
 
   public char currentCharacter;
 
@@ -1103,36 +1103,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
 
   public void consumeStringLiteral() throws InvalidInputException {
     try {
+      boolean openDollarBrace = false;
       // consume next character
       unicodeAsBackSlash = false;
       currentCharacter = source[currentPosition++];
-      //                if (((currentCharacter = source[currentPosition++]) == '\\')
-      //                  && (source[currentPosition] == 'u')) {
-      //                  getNextUnicodeChar();
-      //                } else {
-      //                  if (withoutUnicodePtr != 0) {
-      //                    withoutUnicodeBuffer[++withoutUnicodePtr] =
-      //                      currentCharacter;
-      //                  }
-      //                }
-      while (currentCharacter != '"') {
+      while (currentCharacter != '"' || openDollarBrace) {
         /** ** in PHP \r and \n are valid in string literals *** */
-        //                  if ((currentCharacter == '\n')
-        //                    || (currentCharacter == '\r')) {
-        //                    // relocate if finding another quote fairly close: thus unicode
-        // '/u000D' will be fully consumed
-        //                    for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
-        //                      if (currentPosition + lookAhead == source.length)
-        //                        break;
-        //                      if (source[currentPosition + lookAhead] == '\n')
-        //                        break;
-        //                      if (source[currentPosition + lookAhead] == '\"') {
-        //                        currentPosition += lookAhead + 1;
-        //                        break;
-        //                      }
-        //                    }
-        //                    throw new InvalidInputException(INVALID_CHAR_IN_STRING);
-        //                  }
         if (currentCharacter == '\\') {
           int escapeSize = currentPosition;
           boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
@@ -1152,6 +1128,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
               withoutUnicodePtr--;
             }
           }
+        } else if (currentCharacter == '$' && source[currentPosition] == '{') {
+          openDollarBrace = true;
+        } else if (currentCharacter == '{' && source[currentPosition] == '$') {
+          openDollarBrace = true;
+        } else if (currentCharacter == '}') {
+          openDollarBrace = false;
         } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
           if (recordLineSeparator) {
             pushLineSeparator();
@@ -1160,14 +1142,9 @@ public class Scanner implements IScanner, ITerminalSymbols {
         // consume next character
         unicodeAsBackSlash = false;
         currentCharacter = source[currentPosition++];
-        //                  if (((currentCharacter = source[currentPosition++]) == '\\')
-        //                    && (source[currentPosition] == 'u')) {
-        //                    getNextUnicodeChar();
-        //                  } else {
         if (withoutUnicodePtr != 0) {
           withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
         }
-        //                  }
       }
     } catch (IndexOutOfBoundsException e) {
       //    reset end position for error reporting
@@ -1218,139 +1195,139 @@ public class Scanner implements IScanner, ITerminalSymbols {
           withoutUnicodePtr = 0;
           //start with a new token
           char encapsedChar = ' ';
-          if (!encapsedStringStack.isEmpty()) {
-            encapsedChar = ((Character) encapsedStringStack.peek()).charValue();
-          }
-          if (encapsedChar != '$' && encapsedChar != ' ') {
-            currentCharacter = source[currentPosition++];
-            if (currentCharacter == encapsedChar) {
-              switch (currentCharacter) {
-              case '`':
-                return TokenNameEncapsedString0;
-              case '\'':
-                return TokenNameEncapsedString1;
-              case '"':
-                return TokenNameEncapsedString2;
-              }
-            }
-            while (currentCharacter != encapsedChar) {
-              /** ** in PHP \r and \n are valid in string literals *** */
-              switch (currentCharacter) {
-              case '\\':
-                int escapeSize = currentPosition;
-                boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
-                //scanEscapeCharacter make a side effect on this value and
-                // we need the previous value few lines down this one
-                scanDoubleQuotedEscapeCharacter();
-                escapeSize = currentPosition - escapeSize;
-                if (withoutUnicodePtr == 0) {
-                  //buffer all the entries that have been left aside....
-                  withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
-                  System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
-                  withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
-                } else { //overwrite the / in the buffer
-                  withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
-                  if (backSlashAsUnicodeInString) { //there are TWO \ in
-                    withoutUnicodePtr--;
-                  }
-                }
-                break;
-              case '\r':
-              case '\n':
-                if (recordLineSeparator) {
-                  pushLineSeparator();
-                }
-                break;
-              case '$':
-                if (isPHPIdentifierStart(source[currentPosition]) || source[currentPosition] == '{') {
-                  currentPosition--;
-                  encapsedStringStack.push(new Character('$'));
-                  return TokenNameSTRING;
-                }
-                break;
-              case '{':
-                if (source[currentPosition] == '$') { // CURLY_OPEN
-                  currentPosition--;
-                  encapsedStringStack.push(new Character('$'));
-                  return TokenNameSTRING;
-                }
-              }
-              // consume next character
-              unicodeAsBackSlash = false;
-              currentCharacter = source[currentPosition++];
-              if (withoutUnicodePtr != 0) {
-                withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
-              }
-              //                  }
-            } // end while
-            currentPosition--;
-            return TokenNameSTRING;
-          }
+          //          if (!encapsedStringStack.isEmpty()) {
+          //            encapsedChar = ((Character) encapsedStringStack.peek()).charValue();
+          //          }
+          //          if (encapsedChar != '$' && encapsedChar != ' ') {
+          //            currentCharacter = source[currentPosition++];
+          //            if (currentCharacter == encapsedChar) {
+          //              switch (currentCharacter) {
+          //              case '`':
+          //                return TokenNameEncapsedString0;
+          //              case '\'':
+          //                return TokenNameEncapsedString1;
+          //              case '"':
+          //                return TokenNameEncapsedString2;
+          //              }
+          //            }
+          //            while (currentCharacter != encapsedChar) {
+          //              /** ** in PHP \r and \n are valid in string literals *** */
+          //              switch (currentCharacter) {
+          //              case '\\':
+          //                int escapeSize = currentPosition;
+          //                boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
+          //                //scanEscapeCharacter make a side effect on this value and
+          //                // we need the previous value few lines down this one
+          //                scanDoubleQuotedEscapeCharacter();
+          //                escapeSize = currentPosition - escapeSize;
+          //                if (withoutUnicodePtr == 0) {
+          //                  //buffer all the entries that have been left aside....
+          //                  withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
+          //                  System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
+          //                  withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
+          //                } else { //overwrite the / in the buffer
+          //                  withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
+          //                  if (backSlashAsUnicodeInString) { //there are TWO \ in
+          //                    withoutUnicodePtr--;
+          //                  }
+          //                }
+          //                break;
+          //              case '\r':
+          //              case '\n':
+          //                if (recordLineSeparator) {
+          //                  pushLineSeparator();
+          //                }
+          //                break;
+          //              case '$':
+          //                if (isPHPIdentifierStart(source[currentPosition]) || source[currentPosition] == '{') {
+          //                  currentPosition--;
+          //                  encapsedStringStack.push(new Character('$'));
+          //                  return TokenNameSTRING;
+          //                }
+          //                break;
+          //              case '{':
+          //                if (source[currentPosition] == '$') { // CURLY_OPEN
+          //                  currentPosition--;
+          //                  encapsedStringStack.push(new Character('$'));
+          //                  return TokenNameSTRING;
+          //                }
+          //              }
+          //              // consume next character
+          //              unicodeAsBackSlash = false;
+          //              currentCharacter = source[currentPosition++];
+          //              if (withoutUnicodePtr != 0) {
+          //                withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
+          //              }
+          //              // }
+          //            } // end while
+          //            currentPosition--;
+          //            return TokenNameSTRING;
+          //          }
           // ---------Consume white space and handles startPosition---------
           int whiteStart = currentPosition;
           startPosition = currentPosition;
           currentCharacter = source[currentPosition++];
-          if (encapsedChar == '$') {
-            switch (currentCharacter) {
-            case '\\':
-              currentCharacter = source[currentPosition++];
-              return TokenNameSTRING;
-            case '{':
-              if (encapsedChar == '$') {
-                if (getNextChar('$'))
-                  return TokenNameLBRACE_DOLLAR;
-              }
-              return TokenNameLBRACE;
-            case '}':
-              return TokenNameRBRACE;
-            case '[':
-              return TokenNameLBRACKET;
-            case ']':
-              return TokenNameRBRACKET;
-            case '\'':
-              if (tokenizeStrings) {
-                consumeStringConstant();
-                return TokenNameStringSingleQuote;
-              }
-              return TokenNameEncapsedString1;
-            case '"':
-              return TokenNameEncapsedString2;
-            case '`':
-              if (tokenizeStrings) {
-                consumeStringInterpolated();
-                return TokenNameStringInterpolated;
-              }
-              return TokenNameEncapsedString0;
-            case '-':
-              if (getNextChar('>'))
-                return TokenNameMINUS_GREATER;
-              return TokenNameSTRING;
-            default:
-              if (currentCharacter == '$') {
-                int oldPosition = currentPosition;
-                try {
-                  currentCharacter = source[currentPosition++];
-                  if (currentCharacter == '{') {
-                    return TokenNameDOLLAR_LBRACE;
-                  }
-                  if (isPHPIdentifierStart(currentCharacter)) {
-                    return scanIdentifierOrKeyword(true);
-                  } else {
-                    currentPosition = oldPosition;
-                    return TokenNameSTRING;
-                  }
-                } catch (IndexOutOfBoundsException e) {
-                  currentPosition = oldPosition;
-                  return TokenNameSTRING;
-                }
-              }
-              if (isPHPIdentifierStart(currentCharacter))
-                return scanIdentifierOrKeyword(false);
-              if (Character.isDigit(currentCharacter))
-                return scanNumber(false);
-              return TokenNameERROR;
-            }
-          }
+          //          if (encapsedChar == '$') {
+          //            switch (currentCharacter) {
+          //            case '\\':
+          //              currentCharacter = source[currentPosition++];
+          //              return TokenNameSTRING;
+          //            case '{':
+          //              if (encapsedChar == '$') {
+          //                if (getNextChar('$'))
+          //                  return TokenNameLBRACE_DOLLAR;
+          //              }
+          //              return TokenNameLBRACE;
+          //            case '}':
+          //              return TokenNameRBRACE;
+          //            case '[':
+          //              return TokenNameLBRACKET;
+          //            case ']':
+          //              return TokenNameRBRACKET;
+          //            case '\'':
+          //              if (tokenizeStrings) {
+          //                consumeStringConstant();
+          //                return TokenNameStringSingleQuote;
+          //              }
+          //              return TokenNameEncapsedString1;
+          //            case '"':
+          //              return TokenNameEncapsedString2;
+          //            case '`':
+          //              if (tokenizeStrings) {
+          //                consumeStringInterpolated();
+          //                return TokenNameStringInterpolated;
+          //              }
+          //              return TokenNameEncapsedString0;
+          //            case '-':
+          //              if (getNextChar('>'))
+          //                return TokenNameMINUS_GREATER;
+          //              return TokenNameSTRING;
+          //            default:
+          //              if (currentCharacter == '$') {
+          //                int oldPosition = currentPosition;
+          //                try {
+          //                  currentCharacter = source[currentPosition++];
+          //                  if (currentCharacter == '{') {
+          //                    return TokenNameDOLLAR_LBRACE;
+          //                  }
+          //                  if (isPHPIdentifierStart(currentCharacter)) {
+          //                    return scanIdentifierOrKeyword(true);
+          //                  } else {
+          //                    currentPosition = oldPosition;
+          //                    return TokenNameSTRING;
+          //                  }
+          //                } catch (IndexOutOfBoundsException e) {
+          //                  currentPosition = oldPosition;
+          //                  return TokenNameSTRING;
+          //                }
+          //              }
+          //              if (isPHPIdentifierStart(currentCharacter))
+          //                return scanIdentifierOrKeyword(false);
+          //              if (Character.isDigit(currentCharacter))
+          //                return scanNumber(false);
+          //              return TokenNameERROR;
+          //            }
+          //          }
           //          boolean isWhiteSpace;
 
           while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
@@ -1569,17 +1546,17 @@ public class Scanner implements IScanner, ITerminalSymbols {
             consumeStringConstant();
             return TokenNameStringSingleQuote;
           case '"':
-            if (tokenizeStrings) {
+//            if (tokenizeStrings) {
               consumeStringLiteral();
               return TokenNameStringDoubleQuote;
-            }
-            return TokenNameEncapsedString2;
+//            }
+//            return TokenNameEncapsedString2;
           case '`':
-            if (tokenizeStrings) {
+//            if (tokenizeStrings) {
               consumeStringInterpolated();
               return TokenNameStringInterpolated;
-            }
-            return TokenNameEncapsedString0;
+//            }
+//            return TokenNameEncapsedString0;
           case '#':
           case '/': {
             char startChar = currentCharacter;
@@ -1875,7 +1852,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
               if (currentCharacter != '=') { // <?=
                 currentPosition--;
               } else {
-                phpExpressionTag = true; 
+                phpExpressionTag = true;
               }
               // <?
               if (ignorePHPOneLiner) { // for CodeFormatter
@@ -2917,20 +2894,6 @@ public class Scanner implements IScanner, ITerminalSymbols {
   }
 
   public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
-    // the string with "\\u" is a legal string of two chars \ and u
-    //thus we use a direct access to the source (for regular cases).
-    //    if (unicodeAsBackSlash) {
-    //      // consume next character
-    //      unicodeAsBackSlash = false;
-    //      if (((currentCharacter = source[currentPosition++]) == '\\')
-    //        && (source[currentPosition] == 'u')) {
-    //        getNextUnicodeChar();
-    //      } else {
-    //        if (withoutUnicodePtr != 0) {
-    //          withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
-    //        }
-    //      }
-    //    } else
     currentCharacter = source[currentPosition++];
     switch (currentCharacter) {
     //      case 'b' :
@@ -3748,7 +3711,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     initialPosition = currentPosition = 0;
     containsAssertKeyword = false;
     withoutUnicodeBuffer = new char[this.source.length];
-    encapsedStringStack = new Stack();
+//    encapsedStringStack = new Stack();
   }
 
   public String toString() {
@@ -3910,12 +3873,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
       return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
     case TokenNameEncapsedString0:
       return "`"; //$NON-NLS-1$  
-    case TokenNameEncapsedString1:
-      return "\'"; //$NON-NLS-1$  
-    case TokenNameEncapsedString2:
-      return "\""; //$NON-NLS-1$  
+//    case TokenNameEncapsedString1:
+//      return "\'"; //$NON-NLS-1$  
+//    case TokenNameEncapsedString2:
+//      return "\""; //$NON-NLS-1$  
     case TokenNameSTRING:
-      return "STRING(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+      return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
     case TokenNameHEREDOC:
       return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
     case TokenNamePLUS_PLUS:
@@ -4089,7 +4052,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     this.tokenizeStrings = tokenizeStrings;
     this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
     this.assertMode = assertMode;
-    this.encapsedStringStack = null;
+//    this.encapsedStringStack = null;
     this.taskTags = taskTags;
     this.taskPriorities = taskPriorities;
   }