Fix bug #1385272: Improved version for "Parsing of short open tags not fully compatib...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Scanner.java
index 30e835c..803f878 100644 (file)
@@ -39,10 +39,13 @@ public class Scanner implements IScanner, ITerminalSymbols {
 
        public boolean phpMode = false;
 
-//     public boolean phpExpressionTag = false;
-
+       /**
+        * This token is set to TokenNameecho if a short tag block begins (i.e. >?= ... )
+        * Directly after the "=" character the getNextToken() method returns TokenNameINLINE_HTML
+        * In the next call to the getNextToken() method the value of fFillerToken (==TokenNameecho) is returned
+        *
+        */
        int fFillerToken = TokenNameEOF;
-       // public Stack encapsedStringStack = null;
 
        public char currentCharacter;
 
@@ -1292,10 +1295,11 @@ public class Scanner implements IScanner, ITerminalSymbols {
                if (!phpMode) {
                        return getInlinedHTMLToken(currentPosition);
                } else {
-                       if (fFillerToken!=TokenNameEOF) {
+                       if (fFillerToken != TokenNameEOF) {
                                int tempToken;
+                               startPosition = currentPosition;
                                tempToken = fFillerToken;
-                               fFillerToken=TokenNameEOF;
+                               fFillerToken = TokenNameEOF;
                                return tempToken;
                        }
                        this.wasAcr = false;
@@ -1307,154 +1311,14 @@ public class Scanner implements IScanner, ITerminalSymbols {
                        try {
                                while (true) {
                                        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;
-                                       // }
                                        // ---------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;
-                                       // }
-                                       // }
-                                       // boolean isWhiteSpace;
 
                                        while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
                                                startPosition = currentPosition;
                                                currentCharacter = source[currentPosition++];
-                                               // if (((currentCharacter = source[currentPosition++]) == '\\')
-                                               // && (source[currentPosition] == 'u')) {
-                                               // isWhiteSpace = jumpOverUnicodeWhiteSpace();
-                                               // } else {
                                                if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
                                                        checkNonExternalizeString();
                                                        if (recordLineSeparator) {
@@ -1463,9 +1327,6 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                                                currentLine = null;
                                                        }
                                                }
-                                               // isWhiteSpace = (currentCharacter == ' ')
-                                               // || Character.isWhitespace(currentCharacter);
-                                               // }
                                        }
                                        if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
                                                // reposition scanner in case we are interested by spaces as tokens
@@ -1956,7 +1817,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
         * @throws InvalidInputException
         */
        private int getInlinedHTMLToken(int start) throws InvalidInputException {
-               boolean phpShortTag = false;  // true, if <?= detected
+               boolean phpShortTag = false; // true, if <?= detected
                if (currentPosition > source.length) {
                        currentPosition = source.length;
                        return TokenNameEOF;
@@ -1980,14 +1841,14 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                                                if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
                                                                        phpMode = true;
                                                                        if (phpShortTag) {
-                                                                               fFillerToken = TokenNameecho;
+                                                                               fFillerToken = TokenNameECHO_INVISIBLE;
                                                                        }
                                                                        return TokenNameINLINE_HTML;
                                                                }
                                                        } else {
                                                                phpMode = true;
                                                                if (phpShortTag) {
-                                                                       fFillerToken = TokenNameecho;
+                                                                       fFillerToken = TokenNameECHO_INVISIBLE;
                                                                }
                                                                return TokenNameINLINE_HTML;
                                                        }
@@ -3545,11 +3406,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
                case 's':
                        // self static switch
                        switch (length) {
-//                     case 4:
-//                             if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index] == 'f')) {
-//                                     return TokenNameself;
-//                             }
-//                             return TokenNameIdentifier;
+                       // case 4:
+                       // if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index]
+                       // == 'f')) {
+                       // return TokenNameself;
+                       // }
+                       // return TokenNameIdentifier;
                        case 6:
                                if (data[++index] == 't')
                                        if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
@@ -3843,6 +3705,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                initialPosition = currentPosition = 0;
                containsAssertKeyword = false;
                withoutUnicodeBuffer = new char[this.source.length];
+               fFillerToken = TokenNameEOF;
                // encapsedStringStack = new Stack();
        }
 
@@ -3875,6 +3738,9 @@ public class Scanner implements IScanner, ITerminalSymbols {
                // //$NON-NLS-1$
                case TokenNameINLINE_HTML:
                        return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+               case    TokenNameECHO_INVISIBLE:
+                       //0-length token
+                       return "";
                case TokenNameIdentifier:
                        return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
                case TokenNameVariable:
@@ -3977,8 +3843,8 @@ public class Scanner implements IScanner, ITerminalSymbols {
                        return "require_once"; //$NON-NLS-1$
                case TokenNamereturn:
                        return "return"; //$NON-NLS-1$
-//             case TokenNameself:
-//                     return "self"; //$NON-NLS-1$
+                       // case TokenNameself:
+                       // return "self"; //$NON-NLS-1$
                case TokenNamestatic:
                        return "static"; //$NON-NLS-1$
                case TokenNameswitch: