X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index ce16744..9782a3e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -27,8 +27,7 @@ public class Scanner implements IScanner, ITerminalSymbols { * stream - currentPosition-1 gives the sourceEnd position into the stream */ // 1.4 feature -// private boolean assertMode; - + // private boolean assertMode; public boolean useAssertAsAnIndentifier = false; // flag indicating if processed source contains occurrences of keyword assert @@ -40,9 +39,13 @@ public class Scanner implements IScanner, ITerminalSymbols { public boolean phpMode = false; - public boolean phpExpressionTag = false; - - // public Stack encapsedStringStack = null; + /** + * 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 char currentCharacter; @@ -199,6 +202,7 @@ public class Scanner implements IScanner, ITerminalSymbols { ObviousIdentCharNatures['"'] = C_SEPARATOR; ObviousIdentCharNatures['\''] = C_SEPARATOR; } + static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' }; static final int TableSize = 30, InternalTableSize = 6; @@ -285,10 +289,11 @@ public class Scanner implements IScanner, ITerminalSymbols { */ public static boolean isPHPIdentOrVarStart(char ch) { if (ch < MAX_OBVIOUS) { - return ObviousIdentCharNatures[ch]==C_LETTER || ObviousIdentCharNatures[ch]==C_DOLLAR; + return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DOLLAR; } return false; - //return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <= ch && ch <= 0xFF); + // return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <= + // ch && ch <= 0xFF); } /** @@ -299,10 +304,11 @@ public class Scanner implements IScanner, ITerminalSymbols { */ public static boolean isPHPIdentifierStart(char ch) { if (ch < MAX_OBVIOUS) { - return ObviousIdentCharNatures[ch]==C_LETTER; + return ObviousIdentCharNatures[ch] == C_LETTER; } return false; -// return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); + // return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= + // 0xFF); } /** @@ -311,15 +317,16 @@ public class Scanner implements IScanner, ITerminalSymbols { */ public static boolean isPHPIdentifierPart(char ch) { if (ch < MAX_OBVIOUS) { - return ObviousIdentCharNatures[ch]==C_LETTER || ObviousIdentCharNatures[ch]==C_DIGIT; + return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT; } return false; -// return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); + // return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch + // <= 0xFF); } public static boolean isSQLIdentifierPart(char ch) { if (ch < MAX_OBVIOUS) { - return ObviousIdentCharNatures[ch]==C_LETTER || ObviousIdentCharNatures[ch]==C_DIGIT; + return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT; } return false; } @@ -424,7 +431,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } for (int i = 0; i < word.length; i++) { - if (word[i]!=source[startPosition+i]){ + if (word[i] != source[startPosition + i]) { return false; } } @@ -901,8 +908,9 @@ public class Scanner implements IScanner, ITerminalSymbols { do { currentCharacter = source[currentPosition++]; } while (currentCharacter == ' ' || currentCharacter == '\t'); - while (ObviousIdentCharNatures[currentCharacter]==C_LETTER) { - // while((currentCharacter >= 'a' && currentCharacter <= 'z') || (currentCharacter >= 'A' && currentCharacter <= 'Z')) { + while (ObviousIdentCharNatures[currentCharacter] == C_LETTER) { + // while((currentCharacter >= 'a' && currentCharacter <= 'z') || + // (currentCharacter >= 'A' && currentCharacter <= 'Z')) { buf.append(currentCharacter); currentCharacter = source[currentPosition++]; } @@ -1208,11 +1216,11 @@ public class Scanner implements IScanner, ITerminalSymbols { public void consumeStringLiteral() throws InvalidInputException { try { - boolean openDollarBrace = false; + int openDollarBrace = 0; // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; - while (currentCharacter != '"' || openDollarBrace) { + while (currentCharacter != '"' || openDollarBrace>0) { /** ** in PHP \r and \n are valid in string literals *** */ if (currentCharacter == '\\') { int escapeSize = currentPosition; @@ -1234,11 +1242,11 @@ public class Scanner implements IScanner, ITerminalSymbols { } } } else if (currentCharacter == '$' && source[currentPosition] == '{') { - openDollarBrace = true; + openDollarBrace++; } else if (currentCharacter == '{' && source[currentPosition] == '$') { - openDollarBrace = true; + openDollarBrace++; } else if (currentCharacter == '}') { - openDollarBrace = false; + openDollarBrace--; } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) { if (recordLineSeparator) { pushLineSeparator(); @@ -1284,11 +1292,16 @@ public class Scanner implements IScanner, ITerminalSymbols { } public int getNextToken() throws InvalidInputException { - phpExpressionTag = false; if (!phpMode) { return getInlinedHTMLToken(currentPosition); - } - if (phpMode) { + } else { + if (fFillerToken != TokenNameEOF) { + int tempToken; + startPosition = currentPosition; + tempToken = fFillerToken; + fFillerToken = TokenNameEOF; + return tempToken; + } this.wasAcr = false; if (diet) { jumpOverMethodBody(); @@ -1298,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) { @@ -1454,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 @@ -1947,6 +1817,7 @@ public class Scanner implements IScanner, ITerminalSymbols { * @throws InvalidInputException */ private int getInlinedHTMLToken(int start) throws InvalidInputException { + boolean phpShortTag = false; // true, if source.length) { currentPosition = source.length; return TokenNameEOF; @@ -1961,27 +1832,39 @@ public class Scanner implements IScanner, ITerminalSymbols { if ((currentCharacter != 'P') && (currentCharacter != 'p')) { if (currentCharacter != '=') { // =0) { + if (getNextChar('M','m')>=0) { + if (getNextChar('L','l')>=0) { + foundXML=true; + } + } + } + if (!foundXML) { + phpMode = true; + } + if (phpShortTag) { + fFillerToken = TokenNameECHO_INVISIBLE; + } 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) { + if (getNextChar('H', 'h') >= 0) { + if (getNextChar('P', 'p') >= 0) { //