misc parser changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Scanner.java
index 041fd95..ff11fa1 100644 (file)
@@ -804,65 +804,8 @@ public class Scanner implements IScanner, ITerminalSymbols {
     return TokenNameLPAREN;
   }
   public int getNextToken() throws InvalidInputException {
-    int htmlPosition = currentPosition;
-    try {
-      while (!phpMode) {
-        currentCharacter = source[currentPosition++];
-        if (currentCharacter == '<') {
-          if (getNextChar('?')) {
-            currentCharacter = source[currentPosition++];
-            if ((currentCharacter == ' ')
-                || Character.isWhitespace(currentCharacter)) {
-              // <?
-              startPosition = currentPosition;
-              phpMode = true;
-              if (tokenizeWhiteSpace) {
-                // && (whiteStart != currentPosition - 1)) {
-                // reposition scanner in case we are interested by spaces as
-                // tokens
-                startPosition = htmlPosition;
-                return TokenNameHTML;
-              }
-            } else {
-              boolean phpStart = (currentCharacter == 'P')
-                  || (currentCharacter == 'p');
-              if (phpStart) {
-                int test = getNextChar('H', 'h');
-                if (test >= 0) {
-                  test = getNextChar('P', 'p');
-                  if (test >= 0) {
-                    // <?PHP <?php
-                    startPosition = currentPosition;
-                    phpMode = true;
-                    if (tokenizeWhiteSpace) {
-                      // && (whiteStart != currentPosition - 1)) {
-                      // reposition scanner in case we are interested by spaces
-                      // as tokens
-                      startPosition = htmlPosition;
-                      return TokenNameHTML;
-                    }
-                  }
-                }
-              }
-            }
-          }
-        }
-        if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
-          if (recordLineSeparator) {
-            pushLineSeparator();
-          } else {
-            currentLine = null;
-          }
-        }
-      }
-    } //-----------------end switch while try--------------------
-    catch (IndexOutOfBoundsException e) {
-      if (tokenizeWhiteSpace) {
-        // && (whiteStart != currentPosition - 1)) {
-        // reposition scanner in case we are interested by spaces as tokens
-        startPosition = htmlPosition;
-      }
-      return TokenNameEOF;
+    if (!phpMode) {
+      return getInlinedHTML(currentPosition);
     }
     if (phpMode) {
       this.wasAcr = false;
@@ -1081,7 +1024,11 @@ public class Scanner implements IScanner, ITerminalSymbols {
             case '?' :
               if (getNextChar('>')) {
                 phpMode = false;
-                return TokenNameStopPHP;
+                if (currentPosition==source.length) {
+                  phpMode = true;
+                  return TokenNameINLINE_HTML;
+                }
+                return getInlinedHTML(currentPosition - 2);
               }
               return TokenNameQUESTION;
             case ':' :
@@ -1522,7 +1469,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                         if (getNextChar('>')) {
                           startPosition = currentPosition - 2;
                           phpMode = false;
-                          return TokenNameStopPHP;
+                          return TokenNameINLINE_HTML;
                         }
                       }
                       //get the next char
@@ -1702,7 +1649,6 @@ public class Scanner implements IScanner, ITerminalSymbols {
                 int oldPosition = currentPosition;
                 try {
                   currentCharacter = source[currentPosition++];
-                  
                   if (isPHPIdentifierStart(currentCharacter)) {
                     return scanIdentifierOrKeyword(true);
                   } else {
@@ -1727,6 +1673,63 @@ public class Scanner implements IScanner, ITerminalSymbols {
     }
     return TokenNameEOF;
   }
+  /**
+   * @return @throws
+   *         InvalidInputException
+   */
+  private int getInlinedHTML(int start) throws InvalidInputException {
+    //    int htmlPosition = start;
+    if (currentPosition>source.length) {
+        currentPosition = source.length;
+        return TokenNameEOF;
+    }
+    startPosition = start;
+    try {
+      while (!phpMode) {
+        currentCharacter = source[currentPosition++];
+        if (currentCharacter == '<') {
+          if (getNextChar('?')) {
+            currentCharacter = source[currentPosition++];
+            if ((currentCharacter == ' ')
+                || Character.isWhitespace(currentCharacter)) {
+              // <?
+              phpMode = true;
+              return TokenNameINLINE_HTML;
+            } else {
+              boolean phpStart = (currentCharacter == 'P')
+                  || (currentCharacter == 'p');
+              if (phpStart) {
+                int test = getNextChar('H', 'h');
+                if (test >= 0) {
+                  test = getNextChar('P', 'p');
+                  if (test >= 0) {
+                    // <?PHP <?php
+                    phpMode = true;
+                    return TokenNameINLINE_HTML;
+                  }
+                }
+              }
+            }
+          }
+        }
+        if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
+          if (recordLineSeparator) {
+            pushLineSeparator();
+          } else {
+            currentLine = null;
+          }
+        }
+      } //-----------------while--------------------
+      phpMode = true;
+      return TokenNameINLINE_HTML;
+    } //-----------------try--------------------
+    catch (IndexOutOfBoundsException e) {
+      startPosition = start;
+      currentPosition--;
+    }
+    phpMode = true;
+    return TokenNameINLINE_HTML;
+  }
   //  public final void getNextUnicodeChar()
   //    throws IndexOutOfBoundsException, InvalidInputException {
   //    //VOID
@@ -3471,8 +3474,8 @@ public class Scanner implements IScanner, ITerminalSymbols {
       case TokenNameERROR :
         return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
       // //$NON-NLS-1$
-      case TokenNameStopPHP :
-        return "StopPHP(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+      case TokenNameINLINE_HTML :
+        return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
       case TokenNameIdentifier :
         return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
       case TokenNameVariable :
@@ -3714,8 +3717,9 @@ public class Scanner implements IScanner, ITerminalSymbols {
         return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
       case TokenNameCOMMENT_PHPDOC :
         return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
-      case TokenNameHTML :
-        return "HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
+        //      case TokenNameHTML :
+        //        return "HTML(" + new String(getCurrentTokenSource()) + ")";
+        // //$NON-NLS-1$
       case TokenNameFILE :
         return "__FILE__"; //$NON-NLS-1$
       case TokenNameLINE :