php formatter based on the JDT java formatter (very early version)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Scanner.java
index 0826535..0dacb72 100644 (file)
@@ -719,9 +719,9 @@ public class Scanner implements IScanner, ITerminalSymbols {
   }
 
   public int getNextToken() throws InvalidInputException {
+    int htmlPosition = currentPosition;
     try {
       while (!phpMode) {
-        startPosition = currentPosition;
         currentCharacter = source[currentPosition++];
         if (currentCharacter == '<') {
           if (getNextChar('?')) {
@@ -731,6 +731,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
               // <?
               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');
@@ -742,6 +748,13 @@ public class Scanner implements IScanner, ITerminalSymbols {
                     // <?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;
+                    }
                   }
                 }
               }
@@ -759,6 +772,11 @@ public class Scanner implements IScanner, ITerminalSymbols {
       }
     } //-----------------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;
     }
 
@@ -1585,7 +1603,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
 
             default :
               if (currentCharacter == '$') {
-                while ( (currentCharacter = source[currentPosition++])=='$') {
+                while ((currentCharacter = source[currentPosition++]) == '$') {
                 }
                 if (currentCharacter == '{')
                   return TokenNameDOLLAR_LBRACE;
@@ -2091,6 +2109,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
         return new char[] { charOne };
     }
   }
+
   final char[] optimizedCurrentTokenSource2() {
     //try to return the same char[] build only once
 
@@ -2121,6 +2140,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     newEntry2 = max;
     return r;
   }
+
   final char[] optimizedCurrentTokenSource3() {
     //try to return the same char[] build only once
 
@@ -2153,6 +2173,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     newEntry3 = max;
     return r;
   }
+
   final char[] optimizedCurrentTokenSource4() {
     //try to return the same char[] build only once
 
@@ -2193,6 +2214,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     return r;
 
   }
+
   final char[] optimizedCurrentTokenSource5() {
     //try to return the same char[] build only once
 
@@ -2236,6 +2258,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     return r;
 
   }
+
   final char[] optimizedCurrentTokenSource6() {
     //try to return the same char[] build only once
 
@@ -2281,6 +2304,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     newEntry6 = max;
     return r;
   }
+
   public final void pushLineSeparator() throws InvalidInputException {
     //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
     final int INCREMENT = 250;
@@ -2578,7 +2602,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
     //disptach on the second char :-)...cool....but fast !
 
     useAssertAsAnIndentifier = false;
-    
+
     while (getNextCharAsJavaIdentifierPart()) {
     };