X-Git-Url: http://git.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 bef873a..ff11fa1 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 @@ -131,6 +131,7 @@ public class Scanner implements IScanner, ITerminalSymbols { public char[][] taskTags = null; public char[][] taskPriorities = null; public static final boolean DEBUG = false; + public static final boolean TRACE = false; public Scanner() { this(false, false); } @@ -675,66 +676,136 @@ public class Scanner implements IScanner, ITerminalSymbols { return false; } } - public int getNextToken() throws InvalidInputException { - int htmlPosition = currentPosition; + public int getCastOrParen() { + int tempPosition = currentPosition; + char tempCharacter = currentCharacter; + int tempToken = TokenNameLPAREN; + boolean found = false; + StringBuffer buf = new StringBuffer(); try { - while (!phpMode) { + do { currentCharacter = source[currentPosition++]; - if (currentCharacter == '<') { - if (getNextChar('?')) { - currentCharacter = source[currentPosition++]; - if ((currentCharacter == ' ') - || Character.isWhitespace(currentCharacter)) { - // = 'a' && currentCharacter <= 'z') + || (currentCharacter >= 'A' && currentCharacter <= 'Z')) { + buf.append(currentCharacter); + currentCharacter = source[currentPosition++]; + } + if (buf.length() >= 3 && buf.length() <= 7) { + char[] data = buf.toString().toCharArray(); + int index = 0; + switch (data.length) { + case 3 : + // int + if ((data[index] == 'i') && (data[++index] == 'n') + && (data[++index] == 't')) { + found = true; + tempToken = TokenNameintCAST; + } + break; + case 4 : + // bool real + if ((data[index] == 'b') && (data[++index] == 'o') + && (data[++index] == 'o') && (data[++index] == 'l')) { + found = true; + tempToken = TokenNameboolCAST; + } else { + index = 0; + if ((data[index] == 'r') && (data[++index] == 'e') + && (data[++index] == 'a') && (data[++index] == 'l')) { + found = true; + tempToken = TokenNamedoubleCAST; } + } + break; + case 5 : + // array unset float + if ((data[index] == 'a') && (data[++index] == 'r') + && (data[++index] == 'r') && (data[++index] == 'a') + && (data[++index] == 'y')) { + found = true; + tempToken = TokenNamearrayCAST; } else { - boolean phpStart = (currentCharacter == 'P') - || (currentCharacter == 'p'); - if (phpStart) { - int test = getNextChar('H', 'h'); - if (test >= 0) { - test = getNextChar('P', 'p'); - if (test >= 0) { - // 0) { - if (getNextChar('=')) - return TokenNameLEFT_SHIFT_EQUAL; - if (getNextChar('<')) { - int heredocStart = currentPosition; - int heredocLength = 0; - currentCharacter = source[currentPosition++]; - if (isPHPIdentifierStart(currentCharacter)) { - currentCharacter = source[currentPosition++]; - } else { - return TokenNameERROR; - } - while (isPHPIdentifierPart(currentCharacter)) { + int oldPosition = currentPosition; + try { + currentCharacter = source[currentPosition++]; + } catch (IndexOutOfBoundsException e) { + currentPosition = oldPosition; + return TokenNameLESS; + } + switch (currentCharacter) { + case '=' : + return TokenNameLESS_EQUAL; + case '>' : + return TokenNameNOT_EQUAL; + case '<' : + if (getNextChar('=')) + return TokenNameLEFT_SHIFT_EQUAL; + if (getNextChar('<')) { + int heredocStart = currentPosition; + int heredocLength = 0; currentCharacter = source[currentPosition++]; - } - heredocLength = currentPosition - heredocStart - 1; - // heredoc end-tag determination - boolean endTag = true; - char ch; - do { - ch = source[currentPosition++]; - if (ch == '\r' || ch == '\n') { - if (recordLineSeparator) { - pushLineSeparator(); - } else { - currentLine = null; - } - for (int i = 0; i < heredocLength; i++) { - if (source[currentPosition + i] != source[heredocStart - + i]) { - endTag = false; - break; + if (isPHPIdentifierStart(currentCharacter)) { + currentCharacter = source[currentPosition++]; + } else { + return TokenNameERROR; + } + while (isPHPIdentifierPart(currentCharacter)) { + currentCharacter = source[currentPosition++]; + } + heredocLength = currentPosition - heredocStart - 1; + // heredoc end-tag determination + boolean endTag = true; + char ch; + do { + ch = source[currentPosition++]; + if (ch == '\r' || ch == '\n') { + if (recordLineSeparator) { + pushLineSeparator(); + } else { + currentLine = null; + } + for (int i = 0; i < heredocLength; i++) { + if (source[currentPosition + i] != source[heredocStart + + i]) { + endTag = false; + break; + } + } + if (endTag) { + currentPosition += heredocLength - 1; + currentCharacter = source[currentPosition++]; + break; // do...while loop + } else { + endTag = true; } } - if (endTag) { - currentPosition += heredocLength - 1; - currentCharacter = source[currentPosition++]; - break; // do...while loop - } else { - endTag = true; - } - } - } while (true); - return TokenNameHEREDOC; - } - return TokenNameLEFT_SHIFT; + } while (true); + return TokenNameHEREDOC; + } + return TokenNameLEFT_SHIFT; } + currentPosition = oldPosition; return TokenNameLESS; } case '>' : @@ -941,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 ':' : @@ -1330,9 +1417,12 @@ public class Scanner implements IScanner, ITerminalSymbols { case '#' : case '/' : { + char startChar = currentCharacter; + if (getNextChar('=')) { + return TokenNameDIVIDE_EQUAL; + } int test; - if ((currentCharacter == '#') - || (test = getNextChar('/', '*')) == 0) { + if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) { //line comment int endPositionForLineComment = 0; try { //get the next char @@ -1379,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 @@ -1546,8 +1636,6 @@ public class Scanner implements IScanner, ITerminalSymbols { } break; } - if (getNextChar('=')) - return TokenNameDIVIDE_EQUAL; return TokenNameDIVIDE; } case '\u001a' : @@ -1558,13 +1646,19 @@ public class Scanner implements IScanner, ITerminalSymbols { throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$ default : if (currentCharacter == '$') { - while ((currentCharacter = source[currentPosition++]) == '$') { + int oldPosition = currentPosition; + try { + currentCharacter = source[currentPosition++]; + if (isPHPIdentifierStart(currentCharacter)) { + return scanIdentifierOrKeyword(true); + } else { + currentPosition = oldPosition; + return TokenNameDOLLAR; + } + } catch (IndexOutOfBoundsException e) { + currentPosition = oldPosition; + return TokenNameDOLLAR; } - if (currentCharacter == '{') - return TokenNameDOLLAR_LBRACE; - if (isPHPIdentifierStart(currentCharacter)) - return scanIdentifierOrKeyword(true); - return TokenNameERROR; } if (isPHPIdentifierStart(currentCharacter)) return scanIdentifierOrKeyword(false); @@ -1579,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)) { + // = 0) { + test = getNextChar('P', 'p'); + if (test >= 0) { + //