X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java index bcc7ba9..f13a602 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java @@ -14,19 +14,17 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; -import java.util.Stack; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; import net.sourceforge.phpeclipse.phpeditor.PHPString; -import net.sourceforge.phpeclipse.phpeditor.PHPParserAction; import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.action.IAction; import org.eclipse.ui.texteditor.MarkerUtilities; public class PHPParser extends PHPKeywords { @@ -37,6 +35,7 @@ public class PHPParser extends PHPKeywords { public static final int ERROR = 2; public static final int WARNING = 1; public static final int INFO = 0; + private IFile fileToParse; private ArrayList phpList; @@ -63,82 +62,88 @@ public class PHPParser extends PHPKeywords { Long longNumber; Double doubleNumber; + + private String stringValue; + + /** Contains the current expression. */ + private StringBuffer expression; + private boolean phpMode; - final static int TT_EOF = 0; - final static int TT_UNDEFINED = 1; - final static int TT_HTML = 2; - - final static int TT_MOD = 30; - final static int TT_NOT = 31; - final static int TT_DOT = 32; - final static int TT_POW = 33; - final static int TT_DIV = 34; - final static int TT_MULTIPLY = 35; - final static int TT_SUBTRACT = 36; - final static int TT_ADD = 37; - final static int TT_EQUAL = 38; - final static int TT_UNEQUAL = 39; - final static int TT_GREATER = 40; - final static int TT_GREATEREQUAL = 41; - final static int TT_LESS = 42; - final static int TT_LESSEQUAL = 43; - final static int TT_AND = 44; - final static int TT_OR = 45; - final static int TT_HASH = 46; - final static int TT_DDOT = 47; - final static int TT_DOTASSIGN = 48; - - final static int TT_ASSIGN = 49; - final static int TT_REF = 50; - final static int TT_FOREACH = 51; - final static int TT_AMPERSAND = 52; - final static int TT_DOLLARLISTOPEN = 53; - final static int TT_TILDE = 54; - final static int TT_TILDEASSIGN = 55; - final static int TT_MODASSIGN = 56; - final static int TT_POWASSIGN = 57; - final static int TT_RSHIFTASSIGN = 58; - final static int TT_LSHIFTASSIGN = 59; - final static int TT_ANDASSIGN = 60; - final static int TT_QUESTIONMARK = 61; - final static int TT_DDOT2 = 62; - final static int TT_AT = 63; - // final static int TT_HEREDOC = 64; - - final static int TT_DOLLAROPEN = 127; - final static int TT_ARGOPEN = 128; - final static int TT_ARGCLOSE = 129; - final static int TT_LISTOPEN = 130; - final static int TT_LISTCLOSE = 131; - final static int TT_PARTOPEN = 132; - final static int TT_PARTCLOSE = 133; - final static int TT_COMMA = 134; - - final static int TT_STRING = 136; - final static int TT_IDENTIFIER = 138; - final static int TT_DIGIT = 139; - final static int TT_SEMICOLON = 140; - final static int TT_SLOT = 141; - final static int TT_SLOTSEQUENCE = 142; - final static int TT_DECREMENT = 144; - final static int TT_INCREMENT = 145; - final static int TT_ADDTO = 146; - final static int TT_DIVIDEBY = 147; - final static int TT_SUBTRACTFROM = 148; - final static int TT_TIMESBY = 149; - final static int TT_VARIABLE = 150; - final static int TT_INT_NUMBER = 151; - final static int TT_DOUBLE_NUMBER = 152; - final static int TT_INTERPOLATED_STRING = 153; - final static int TT_STRING_CONSTANT = 154; - - final static int TT_LSHIFT = 155; - final static int TT_RSHIFT = 156; - final static int TT_EX_EQUAL = 157; - final static int TT_EX_UNEQUAL = 158; - final static int TT_LINE = 159; - // final static int TT_AT = 153; // @ + final static int TokenNameEOF = 0; + final static int TokenNameERROR = 1; + final static int TokenNameHTML = 2; + + final static int TokenNameREMAINDER = 30; + final static int TokenNameNOT = 31; + final static int TokenNameDOT = 32; + final static int TokenNameXOR = 33; + final static int TokenNameDIVIDE = 34; + final static int TokenNameMULTIPLY = 35; + final static int TokenNameMINUS = 36; + final static int TokenNamePLUS = 37; + final static int TokenNameEQUAL_EQUAL = 38; + final static int TokenNameNOT_EQUAL = 39; + final static int TokenNameGREATER = 40; + final static int TokenNameGREATER_EQUAL = 41; + final static int TokenNameLESS = 42; + final static int TokenNameLESS_EQUAL = 43; + final static int TokenNameAND_AND = 44; + final static int TokenNameOR_OR = 45; + // final static int TokenNameHASH = 46; + final static int TokenNameCOLON = 47; + final static int TokenNameDOT_EQUAL = 48; + + final static int TokenNameEQUAL = 49; + final static int TokenNameMINUS_GREATER = 50; // -> + final static int TokenNameFOREACH = 51; + final static int TokenNameAND = 52; + //final static int TokenNameDOLLARLISTOPEN = 53; + final static int TokenNameTWIDDLE = 54; + final static int TokenNameTWIDDLE_EQUAL = 55; + final static int TokenNameREMAINDER_EQUAL = 56; + final static int TokenNameXOR_EQUAL = 57; + final static int TokenNameRIGHT_SHIFT_EQUAL = 58; + final static int TokenNameLEFT_SHIFT_EQUAL = 59; + final static int TokenNameAND_EQUAL = 60; + final static int TokenNameQUESTION = 61; + final static int TokenNameCOLON_COLON = 62; + final static int TokenNameAT = 63; + // final static int TokenNameHEREDOC = 64; + + final static int TokenNameDOLLAROPEN = 127; + final static int TokenNameLPAREN = 128; + final static int TokenNameRPAREN = 129; + final static int TokenNameLBRACE = 130; + final static int TokenNameRBRACE = 131; + final static int TokenNameLBRACKET = 132; + final static int TokenNameRBRACKET = 133; + final static int TokenNameCOMMA = 134; + + final static int TokenNameStringLiteral = 136; + final static int TokenNameIdentifier = 138; + // final static int TokenNameDIGIT = 139; + final static int TokenNameSEMICOLON = 140; + // final static int TokenNameSLOT = 141; + // final static int TokenNameSLOTSEQUENCE = 142; + final static int TokenNameMINUS_MINUS = 144; + final static int TokenNamePLUS_PLUS = 145; + final static int TokenNamePLUS_EQUAL = 146; + final static int TokenNameDIVIDE_EQUAL = 147; + final static int TokenNameMINUS_EQUAL = 148; + final static int TokenNameMULTIPLY_EQUAL = 149; + final static int TokenNameVariable = 150; + final static int TokenNameIntegerLiteral = 151; + final static int TokenNameDoubleLiteral = 152; + final static int TokenNameStringInterpolated = 153; + final static int TokenNameStringConstant = 154; + + final static int TokenNameLEFT_SHIFT = 155; + final static int TokenNameRIGHT_SHIFT = 156; + final static int TokenNameEQUAL_EQUAL_EQUAL = 157; + final static int TokenNameNOT_EQUAL_EQUAL = 158; + final static int TokenNameOR = 159; + // final static int TokenNameAT = 153; // @ /** * Class Constructor. * @@ -157,7 +162,7 @@ public class PHPParser extends PHPKeywords { this.fileToParse = fileToParse; this.phpList = null; this.str = ""; - this.token = TT_EOF; + this.token = TokenNameEOF; this.chIndx = 0; this.rowCount = 1; this.columnCount = 0; @@ -193,6 +198,12 @@ public class PHPParser extends PHPKeywords { } } + /** + * This method will throw the SyntaxError. + * It will add the good lines and columns to the Error + * @param error the error message + * @throws SyntaxError the error raised + */ private void throwSyntaxError(String error) { if (str.length() < chIndx) { @@ -210,8 +221,13 @@ public class PHPParser extends PHPKeywords { throw new SyntaxError(rowCount, chIndx - columnCount + 1, str.substring(columnCount, eol), error); } + /** + * This method will throw the SyntaxError. + * It will add the good lines and columns to the Error + * @param error the error message + * @throws SyntaxError the error raised + */ private void throwSyntaxError(String error, int startRow) { - throw new SyntaxError(startRow, 0, " ", error); } @@ -229,508 +245,508 @@ public class PHPParser extends PHPKeywords { chIndx = str.length() + 1; ch = ' '; - // token = TT_EOF; + // token = TokenNameEOF; phpEnd = true; } - private void getNextToken_OldVersion() throws CoreException { - phpEnd = false; - - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - token = TT_UNDEFINED; - if (ch == '\n') { - rowCount++; - columnCount = chIndx; - continue; // while loop - } - if (str.length() == chIndx) { - phpEnd = true; - } - if (!Character.isWhitespace(ch)) { - if (ch == '$') { - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '{') { - chIndx++; - token = TT_DOLLAROPEN; - return; - } - } - getIdentifier(); - return; - } - if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$')) { - getIdentifier(); - return; - } - if (ch >= '0' && ch <= '9') { - getNumber(); - return; - } - if (ch == '/') { - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '/') { - chIndx++; - // read comment until end of line: - while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { - chIndx++; - } - continue; - } else if (str.charAt(chIndx) == '*') { - chIndx++; - // multi line comment: - while (str.length() > chIndx) { - if (str.charAt(chIndx) == '*' && (str.length() > (chIndx + 1)) && str.charAt(chIndx + 1) == '/') { - chIndx += 2; - break; - } - ch = str.charAt(chIndx++); - if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - continue; - } - } - } else if (ch == '#') { - // read comment until end of line: - while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { - chIndx++; - } - continue; - } else if (ch == '"') { - // read string until end - boolean openString = true; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '"') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character '\"' at end of file."); - } - token = TT_INTERPOLATED_STRING; - return; - } else if (ch == '\'') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '\'') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"'\" at end of file.", startRow); - } - token = TT_STRING_CONSTANT; - return; - } else if (ch == '`') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '`') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"`\" at end of file.", startRow); - } - token = TT_STRING_CONSTANT; - return; - } - - switch (ch) { - - case '(' : - token = TT_ARGOPEN; - - break; - case ')' : - token = TT_ARGCLOSE; - - break; - case '{' : - token = TT_LISTOPEN; - - break; - case '}' : - token = TT_LISTCLOSE; - - break; - case '[' : - token = TT_PARTOPEN; - - break; - case ']' : - token = TT_PARTCLOSE; - - break; - case ',' : - token = TT_COMMA; - - break; - case '?' : - token = TT_QUESTIONMARK; - break; - case '@' : - token = TT_AT; - break; - case '~' : - token = TT_TILDE; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_TILDEASSIGN; - - break; - } - } - break; - case '.' : - token = TT_DOT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_DOTASSIGN; - - break; - } - } - - break; - case '"' : - token = TT_STRING; - - break; - case '%' : - token = TT_MOD; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_MODASSIGN; - - break; - } - } - break; - case ';' : - token = TT_SEMICOLON; - - break; - case '^' : - token = TT_POW; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_POWASSIGN; - - break; - } - } - break; - case '/' : - token = TT_DIV; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_DIVIDEBY; - - break; - } - } - - break; - case '*' : - token = TT_MULTIPLY; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '*') { - chIndx++; - token = TT_POW; - - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_TIMESBY; - - break; - } - } - - break; - case '+' : - token = TT_ADD; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '+') { - chIndx++; - token = TT_INCREMENT; - - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_ADDTO; - - break; - } - } - break; - case '-' : - token = TT_SUBTRACT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '-') { - chIndx++; - token = TT_DECREMENT; - - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_SUBTRACTFROM; - - break; - } - if (str.charAt(chIndx) == '>') { - chIndx++; - token = TT_REF; - - break; - } - } - - break; - case '=' : - token = TT_ASSIGN; - - if (str.length() > chIndx) { - ch = str.charAt(chIndx); - - if (ch == '=') { - chIndx++; - token = TT_EQUAL; - if (str.length() > chIndx) { - ch = str.charAt(chIndx); - - if (ch == '=') { - chIndx++; - token = TT_EX_EQUAL; - } - } - break; - } - if (ch == '>') { - chIndx++; - token = TT_FOREACH; - - break; - } - } - - break; - case '!' : - token = TT_NOT; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_UNEQUAL; - if (str.length() > chIndx) { - ch = str.charAt(chIndx); - - if (ch == '=') { - chIndx++; - token = TT_EX_UNEQUAL; - } - } - break; - } - } - - break; - case '>' : - token = TT_GREATER; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_GREATEREQUAL; - break; - } - if (str.charAt(chIndx) == '>') { - chIndx++; - token = TT_RSHIFT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_RSHIFTASSIGN; - break; - } - } - break; - } - } - - break; - case '<' : - token = TT_LESS; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_LESSEQUAL; - - break; - } - if (str.charAt(chIndx) == '<') { - chIndx++; - token = TT_LSHIFT; - if (str.charAt(chIndx) == '<') { - // heredoc - int startRow = rowCount; - if (str.length() > chIndx) { - - ch = str.charAt(++chIndx); - if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) { - chIndx++; - getIdentifier(); - token = TT_STRING_CONSTANT; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\n') { - if (str.length() >= chIndx + identifier.length()) { - if (str.substring(chIndx, chIndx + identifier.length()).equals(identifier)) { - chIndx += identifier.length(); - return; - } - } - } - } - } - } - throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow); - } else if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_LSHIFTASSIGN; - break; - } - break; - } - } - - break; - - case '|' : - token = TT_LINE; - - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '|') { - chIndx++; - token = TT_OR; - - break; - } - } - - break; - case '&' : - token = TT_AMPERSAND; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == '&') { - chIndx++; - token = TT_AND; - break; - } - if (str.charAt(chIndx) == '=') { - chIndx++; - token = TT_ANDASSIGN; - break; - } - break; - } - - break; - case ':' : - token = TT_DDOT; - if (str.length() > chIndx) { - if (str.charAt(chIndx) == ':') { - chIndx++; - token = TT_DDOT2; - } - } - break; - case '#' : - token = TT_HASH; - - break; - // case '@' : - // token = TT_AT; - // - // break; - default : - throwSyntaxError("unexpected character: '" + ch + "'"); - } - - if (token == TT_UNDEFINED) { - throwSyntaxError("token not found"); - } - - return; - } - } - - chIndx = str.length() + 1; - ch = ' '; - token = TT_EOF; - phpEnd = true; - PHPString temp; - if (phpList != null) { - if (currentPHPString < phpList.size()) { - token = TT_UNDEFINED; - temp = (PHPString) phpList.get(currentPHPString++); - this.str = temp.getPHPString(); - this.token = TT_EOF; - this.chIndx = 0; - this.rowCount = temp.getLineNumber(); - this.columnCount = 0; - getNextToken(); - phpEnd = true; - } else { - token = TT_UNDEFINED; - return; - } - } - } +// private void getNextToken_OldVersion() throws CoreException { +// phpEnd = false; +// +// while (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// token = TokenNameERROR; +// if (ch == '\n') { +// rowCount++; +// columnCount = chIndx; +// continue; // while loop +// } +// if (str.length() == chIndx) { +// phpEnd = true; +// } +// if (!Character.isWhitespace(ch)) { +// if (ch == '$') { +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '{') { +// chIndx++; +// token = TokenNameDOLLAROPEN; +// return; +// } +// } +// getIdentifier(); +// return; +// } +// if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$')) { +// getIdentifier(); +// return; +// } +// if (ch >= '0' && ch <= '9') { +// getNumber(); +// return; +// } +// if (ch == '/') { +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '/') { +// chIndx++; +// // read comment until end of line: +// while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { +// chIndx++; +// } +// continue; +// } else if (str.charAt(chIndx) == '*') { +// chIndx++; +// // multi line comment: +// while (str.length() > chIndx) { +// if (str.charAt(chIndx) == '*' && (str.length() > (chIndx + 1)) && str.charAt(chIndx + 1) == '/') { +// chIndx += 2; +// break; +// } +// ch = str.charAt(chIndx++); +// if (ch == '\n') { +// rowCount++; +// columnCount = chIndx; +// } +// } +// continue; +// } +// } +// } else if (ch == '#') { +// // read comment until end of line: +// while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { +// chIndx++; +// } +// continue; +// } else if (ch == '"') { +// // read string until end +// boolean openString = true; +// while (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// if (ch == '\\') { +// if (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// } +// } else if (ch == '"') { +// openString = false; +// break; +// } else if (ch == '\n') { +// rowCount++; +// columnCount = chIndx; +// } +// } +// if (openString) { +// throwSyntaxError("Open string character '\"' at end of file."); +// } +// token = TokenNameINTERPOLATED_STRING; +// return; +// } else if (ch == '\'') { +// // read string until end +// boolean openString = true; +// int startRow = rowCount; +// while (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// if (ch == '\\') { +// if (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// } +// } else if (ch == '\'') { +// openString = false; +// break; +// } else if (ch == '\n') { +// rowCount++; +// columnCount = chIndx; +// } +// } +// if (openString) { +// throwSyntaxError("Open string character \"'\" at end of file.", startRow); +// } +// token = TokenNameStringConstant; +// return; +// } else if (ch == '`') { +// // read string until end +// boolean openString = true; +// int startRow = rowCount; +// while (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// if (ch == '\\') { +// if (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// } +// } else if (ch == '`') { +// openString = false; +// break; +// } else if (ch == '\n') { +// rowCount++; +// columnCount = chIndx; +// } +// } +// if (openString) { +// throwSyntaxError("Open string character \"`\" at end of file.", startRow); +// } +// token = TokenNameStringConstant; +// return; +// } +// +// switch (ch) { +// +// case '(' : +// token = TokenNameLPAREN; +// +// break; +// case ')' : +// token = TokenNameRPAREN; +// +// break; +// case '{' : +// token = TokenNameLBRACE; +// +// break; +// case '}' : +// token = TokenNameRBRACE; +// +// break; +// case '[' : +// token = TokenNameLBRACKET; +// +// break; +// case ']' : +// token = TokenNameRBRACKET; +// +// break; +// case ',' : +// token = TokenNameCOMMA; +// +// break; +// case '?' : +// token = TokenNameQUESTION; +// break; +// case '@' : +// token = TokenNameAT; +// break; +// case '~' : +// token = TokenNameTWIDDLE; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameTWIDDLE_EQUAL; +// +// break; +// } +// } +// break; +// case '.' : +// token = TokenNameDOT; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameDOT_EQUAL; +// +// break; +// } +// } +// +// break; +// case '"' : +// token = TokenNameStringLiteral; +// +// break; +// case '%' : +// token = TokenNameREMAINDER; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameREMAINDER_EQUAL; +// +// break; +// } +// } +// break; +// case ';' : +// token = TokenNameSEMICOLON; +// +// break; +// case '^' : +// token = TokenNameXOR; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameXOR_EQUAL; +// +// break; +// } +// } +// break; +// case '/' : +// token = TokenNameDIVIDE; +// +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameDIVIDE_EQUAL; +// +// break; +// } +// } +// +// break; +// case '*' : +// token = TokenNameMULTIPLY; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '*') { +// chIndx++; +// token = TokenNameXOR; +// +// break; +// } +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameMULTIPLY_EQUAL; +// +// break; +// } +// } +// +// break; +// case '+' : +// token = TokenNamePLUS; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '+') { +// chIndx++; +// token = TokenNamePLUS_PLUS; +// +// break; +// } +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNamePLUS_EQUAL; +// +// break; +// } +// } +// break; +// case '-' : +// token = TokenNameMINUS; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '-') { +// chIndx++; +// token = TokenNameMINUS_MINUS; +// +// break; +// } +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameMINUS_EQUAL; +// +// break; +// } +// if (str.charAt(chIndx) == '>') { +// chIndx++; +// token = TokenNameMINUS_GREATER; +// +// break; +// } +// } +// +// break; +// case '=' : +// token = TokenNameEQUAL; +// +// if (str.length() > chIndx) { +// ch = str.charAt(chIndx); +// +// if (ch == '=') { +// chIndx++; +// token = TokenNameEQUAL_EQUAL; +// if (str.length() > chIndx) { +// ch = str.charAt(chIndx); +// +// if (ch == '=') { +// chIndx++; +// token = TokenNameEQUAL_EQUAL_EQUAL; +// } +// } +// break; +// } +// if (ch == '>') { +// chIndx++; +// token = TokenNameFOREACH; +// +// break; +// } +// } +// +// break; +// case '!' : +// token = TokenNameNOT; +// +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameNOT_EQUAL; +// if (str.length() > chIndx) { +// ch = str.charAt(chIndx); +// +// if (ch == '=') { +// chIndx++; +// token = TokenNameNOT_EQUAL_EQUAL; +// } +// } +// break; +// } +// } +// +// break; +// case '>' : +// token = TokenNameGREATER; +// +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameGREATER_EQUAL; +// break; +// } +// if (str.charAt(chIndx) == '>') { +// chIndx++; +// token = TokenNameRIGHT_SHIFT; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameRIGHT_SHIFT_EQUAL; +// break; +// } +// } +// break; +// } +// } +// +// break; +// case '<' : +// token = TokenNameLESS; +// +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameLESS_EQUAL; +// +// break; +// } +// if (str.charAt(chIndx) == '<') { +// chIndx++; +// token = TokenNameLEFT_SHIFT; +// if (str.charAt(chIndx) == '<') { +// // heredoc +// int startRow = rowCount; +// if (str.length() > chIndx) { +// +// ch = str.charAt(++chIndx); +// if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) { +// chIndx++; +// getIdentifier(); +// token = TokenNameStringConstant; +// while (str.length() > chIndx) { +// ch = str.charAt(chIndx++); +// if (ch == '\n') { +// if (str.length() >= chIndx + identifier.length()) { +// if (str.substring(chIndx, chIndx + identifier.length()).equals(identifier)) { +// chIndx += identifier.length(); +// return; +// } +// } +// } +// } +// } +// } +// throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow); +// } else if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameLEFT_SHIFT_EQUAL; +// break; +// } +// break; +// } +// } +// +// break; +// +// case '|' : +// token = TokenNameOR; +// +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '|') { +// chIndx++; +// token = TokenNameOR_OR; +// +// break; +// } +// } +// +// break; +// case '&' : +// token = TokenNameAND; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == '&') { +// chIndx++; +// token = TokenNameAND_AND; +// break; +// } +// if (str.charAt(chIndx) == '=') { +// chIndx++; +// token = TokenNameAND_EQUAL; +// break; +// } +// break; +// } +// +// break; +// case ':' : +// token = TokenNameCOLON; +// if (str.length() > chIndx) { +// if (str.charAt(chIndx) == ':') { +// chIndx++; +// token = TokenNameCOLON_COLON; +// } +// } +// break; +// case '#' : +// token = TokenNameHASH; +// +// break; +// // case '@' : +// // token = TokenNameAT; +// // +// // break; +// default : +// throwSyntaxError("unexpected character: '" + ch + "'"); +// } +// +// if (token == TokenNameERROR) { +// throwSyntaxError("token not found"); +// } +// +// return; +// } +// } +// +// chIndx = str.length() + 1; +// ch = ' '; +// token = TokenNameEOF; +// phpEnd = true; +// PHPString temp; +// if (phpList != null) { +// if (currentPHPString < phpList.size()) { +// token = TokenNameERROR; +// temp = (PHPString) phpList.get(currentPHPString++); +// this.str = temp.getPHPString(); +// this.token = TokenNameEOF; +// this.chIndx = 0; +// this.rowCount = temp.getLineNumber(); +// this.columnCount = 0; +// getNextToken(); +// phpEnd = true; +// } else { +// token = TokenNameERROR; +// return; +// } +// } +// } /** * gets the next token from input */ @@ -743,7 +759,7 @@ public class PHPParser extends PHPKeywords { if (!phpMode) { while (str.length() > chIndx) { - token = TT_UNDEFINED; + token = TokenNameERROR; ch = str.charAt(chIndx++); if (ch == '\n') { @@ -758,23 +774,11 @@ public class PHPParser extends PHPKeywords { phpMode = true; phpFound = true; break; - } else if (ch2 == 'p') { + } else if (ch2 == 'p' || ch2 == 'P') { ch2 = str.charAt(chIndx++); - if (ch2 == 'h') { + if (ch2 == 'h' || ch2 == 'H') { ch2 = str.charAt(chIndx++); - if (ch2 == 'p') { - phpMode = true; - phpFound = true; - break; - } - chIndx--; - } - chIndx--; - } else if (ch2 == 'P') { - ch2 = str.charAt(chIndx++); - if (ch2 == 'H') { - ch2 = str.charAt(chIndx++); - if (ch2 == 'P') { + if (ch2 == 'p' || ch2 == 'P') { phpMode = true; phpFound = true; break; @@ -794,7 +798,7 @@ public class PHPParser extends PHPKeywords { if (phpMode) { while (str.length() > chIndx) { ch = str.charAt(chIndx++); - token = TT_UNDEFINED; + token = TokenNameERROR; if (ch == '\n') { rowCount++; columnCount = chIndx; @@ -808,7 +812,7 @@ public class PHPParser extends PHPKeywords { if (str.length() > chIndx) { if (str.charAt(chIndx) == '{') { chIndx++; - token = TT_DOLLAROPEN; + token = TokenNameDOLLAROPEN; return; } } @@ -835,7 +839,7 @@ public class PHPParser extends PHPKeywords { ch2 = str.charAt(chIndx); if (ch2 == '>') { chIndx++; - token = TT_HTML; + token = TokenNameHTML; // php end phpMode = false; phpEnd = true; @@ -871,7 +875,7 @@ public class PHPParser extends PHPKeywords { ch2 = str.charAt(chIndx); if (ch2 == '>') { chIndx++; - token = TT_HTML; + token = TokenNameHTML; // php end phpMode = false; phpEnd = true; @@ -883,112 +887,53 @@ public class PHPParser extends PHPKeywords { continue; } else if (ch == '"') { - // read string until end - boolean openString = true; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '"') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character '\"' at end of file."); - } - token = TT_INTERPOLATED_STRING; + getString('"',TokenNameStringInterpolated,"Open string character '\"' at end of file."); return; } else if (ch == '\'') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '\'') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"'\" at end of file.", startRow); - } - token = TT_STRING_CONSTANT; + getString('\'',TokenNameStringConstant,"Open string character \"'\" at end of file."); return; } else if (ch == '`') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '`') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"`\" at end of file.", startRow); - } + getString('`',TokenNameStringConstant,"Open string character \"`\" at end of file."); setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO); - token = TT_STRING_CONSTANT; return; } switch (ch) { case '(' : - token = TT_ARGOPEN; + token = TokenNameLPAREN; break; case ')' : - token = TT_ARGCLOSE; + token = TokenNameRPAREN; break; case '{' : - token = TT_LISTOPEN; + token = TokenNameLBRACE; break; case '}' : - token = TT_LISTCLOSE; + token = TokenNameRBRACE; break; case '[' : - token = TT_PARTOPEN; + token = TokenNameLBRACKET; break; case ']' : - token = TT_PARTCLOSE; + token = TokenNameRBRACKET; break; case ',' : - token = TT_COMMA; + token = TokenNameCOMMA; break; case '?' : - token = TT_QUESTIONMARK; + token = TokenNameQUESTION; if (str.length() > chIndx) { if (str.charAt(chIndx) == '>') { chIndx++; - token = TT_HTML; + token = TokenNameHTML; // php end phpMode = false; phpEnd = true; @@ -998,25 +943,25 @@ public class PHPParser extends PHPKeywords { break; case '@' : - token = TT_AT; + token = TokenNameAT; break; case '~' : - token = TT_TILDE; + token = TokenNameTWIDDLE; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_TILDEASSIGN; + token = TokenNameTWIDDLE_EQUAL; break; } } break; case '.' : - token = TT_DOT; + token = TokenNameDOT; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_DOTASSIGN; + token = TokenNameDOT_EQUAL; break; } @@ -1024,42 +969,42 @@ public class PHPParser extends PHPKeywords { break; case '"' : - token = TT_STRING; + token = TokenNameStringLiteral; break; case '%' : - token = TT_MOD; + token = TokenNameREMAINDER; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_MODASSIGN; + token = TokenNameREMAINDER_EQUAL; break; } } break; case ';' : - token = TT_SEMICOLON; + token = TokenNameSEMICOLON; break; case '^' : - token = TT_POW; + token = TokenNameXOR; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_POWASSIGN; + token = TokenNameXOR_EQUAL; break; } } break; case '/' : - token = TT_DIV; + token = TokenNameDIVIDE; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_DIVIDEBY; + token = TokenNameDIVIDE_EQUAL; break; } @@ -1067,17 +1012,17 @@ public class PHPParser extends PHPKeywords { break; case '*' : - token = TT_MULTIPLY; + token = TokenNameMULTIPLY; if (str.length() > chIndx) { if (str.charAt(chIndx) == '*') { chIndx++; - token = TT_POW; + token = TokenNameXOR; break; } if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_TIMESBY; + token = TokenNameMULTIPLY_EQUAL; break; } @@ -1085,40 +1030,40 @@ public class PHPParser extends PHPKeywords { break; case '+' : - token = TT_ADD; + token = TokenNamePLUS; if (str.length() > chIndx) { if (str.charAt(chIndx) == '+') { chIndx++; - token = TT_INCREMENT; + token = TokenNamePLUS_PLUS; break; } if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_ADDTO; + token = TokenNamePLUS_EQUAL; break; } } break; case '-' : - token = TT_SUBTRACT; + token = TokenNameMINUS; if (str.length() > chIndx) { if (str.charAt(chIndx) == '-') { chIndx++; - token = TT_DECREMENT; + token = TokenNameMINUS_MINUS; break; } if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_SUBTRACTFROM; + token = TokenNameMINUS_EQUAL; break; } if (str.charAt(chIndx) == '>') { chIndx++; - token = TT_REF; + token = TokenNameMINUS_GREATER; break; } @@ -1126,27 +1071,27 @@ public class PHPParser extends PHPKeywords { break; case '=' : - token = TT_ASSIGN; + token = TokenNameEQUAL; if (str.length() > chIndx) { ch = str.charAt(chIndx); if (ch == '=') { chIndx++; - token = TT_EQUAL; + token = TokenNameEQUAL_EQUAL; if (str.length() > chIndx) { ch = str.charAt(chIndx); if (ch == '=') { chIndx++; - token = TT_EX_EQUAL; + token = TokenNameEQUAL_EQUAL_EQUAL; } } break; } if (ch == '>') { chIndx++; - token = TT_FOREACH; + token = TokenNameFOREACH; break; } @@ -1154,18 +1099,18 @@ public class PHPParser extends PHPKeywords { break; case '!' : - token = TT_NOT; + token = TokenNameNOT; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_UNEQUAL; + token = TokenNameNOT_EQUAL; if (str.length() > chIndx) { ch = str.charAt(chIndx); if (ch == '=') { chIndx++; - token = TT_EX_UNEQUAL; + token = TokenNameNOT_EQUAL_EQUAL; } } break; @@ -1174,21 +1119,21 @@ public class PHPParser extends PHPKeywords { break; case '>' : - token = TT_GREATER; + token = TokenNameGREATER; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_GREATEREQUAL; + token = TokenNameGREATER_EQUAL; break; } if (str.charAt(chIndx) == '>') { chIndx++; - token = TT_RSHIFT; + token = TokenNameRIGHT_SHIFT; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_RSHIFTASSIGN; + token = TokenNameRIGHT_SHIFT_EQUAL; break; } } @@ -1198,18 +1143,18 @@ public class PHPParser extends PHPKeywords { break; case '<' : - token = TT_LESS; + token = TokenNameLESS; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_LESSEQUAL; + token = TokenNameLESS_EQUAL; break; } if (str.charAt(chIndx) == '<') { chIndx++; - token = TT_LSHIFT; + token = TokenNameLEFT_SHIFT; if (str.charAt(chIndx) == '<') { // heredoc int startRow = rowCount; @@ -1219,7 +1164,7 @@ public class PHPParser extends PHPKeywords { if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_')) { chIndx++; getIdentifier(); - token = TT_STRING_CONSTANT; + token = TokenNameStringConstant; while (str.length() > chIndx) { ch = str.charAt(chIndx++); if (ch == '\n') { @@ -1236,7 +1181,7 @@ public class PHPParser extends PHPKeywords { throwSyntaxError("Open heredoc syntax after operator '<<<'.", startRow); } else if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_LSHIFTASSIGN; + token = TokenNameLEFT_SHIFT_EQUAL; break; } break; @@ -1246,12 +1191,12 @@ public class PHPParser extends PHPKeywords { break; case '|' : - token = TT_LINE; + token = TokenNameOR; if (str.length() > chIndx) { if (str.charAt(chIndx) == '|') { chIndx++; - token = TT_OR; + token = TokenNameOR_OR; break; } @@ -1259,16 +1204,16 @@ public class PHPParser extends PHPKeywords { break; case '&' : - token = TT_AMPERSAND; + token = TokenNameAND; if (str.length() > chIndx) { if (str.charAt(chIndx) == '&') { chIndx++; - token = TT_AND; + token = TokenNameAND_AND; break; } if (str.charAt(chIndx) == '=') { chIndx++; - token = TT_ANDASSIGN; + token = TokenNameAND_EQUAL; break; } break; @@ -1276,27 +1221,27 @@ public class PHPParser extends PHPKeywords { break; case ':' : - token = TT_DDOT; + token = TokenNameCOLON; if (str.length() > chIndx) { if (str.charAt(chIndx) == ':') { chIndx++; - token = TT_DDOT2; + token = TokenNameCOLON_COLON; } } break; - case '#' : - token = TT_HASH; - - break; +// case '#' : +// token = TokenNameHASH; +// +// break; // case '@' : - // token = TT_AT; + // token = TokenNameAT; // // break; default : throwSyntaxError("unexpected character: '" + ch + "'"); } - if (token == TT_UNDEFINED) { + if (token == TokenNameERROR) { throwSyntaxError("token not found"); } @@ -1310,49 +1255,57 @@ public class PHPParser extends PHPKeywords { chIndx = str.length() + 1; ch = ' '; - token = TT_EOF; + token = TokenNameEOF; phpEnd = true; //PHPString temp; // if (phpList != null) { // if (currentPHPString < phpList.size()) { - // token = TT_UNDEFINED; + // token = TokenNameUNDEFINED; // temp = (PHPString) phpList.get(currentPHPString++); // this.str = temp.getPHPString(); - // this.token = TT_EOF; + // this.token = TokenNameEOF; // this.chIndx = 0; // this.rowCount = temp.getLineNumber(); // this.columnCount = 0; // getNextToken(); // phpEnd = true; // } else { - // token = TT_UNDEFINED; + // token = TokenNameUNDEFINED; // return; // } // } } + /** + * Get an identifier. + */ private void getIdentifier() { - StringBuffer ident = new StringBuffer(); - - ident.append(ch); + // StringBuffer ident = new StringBuffer(); + int startPosition = chIndx - 1; +// ident.append(ch); if (ch == '$') { getChar(); // attention recursive call: getIdentifier(); - token = TT_VARIABLE; + token = TokenNameVariable; return; } else { - token = TT_IDENTIFIER; + token = TokenNameIdentifier; } getChar(); + + //this will read the buffer until the next character is a forbidden character for identifier while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '_')) { - ident.append(ch); + // ident.append(ch); getChar(); } - identifier = ident.toString(); - chIndx--; + int endPosition = chIndx--; + int length = (--endPosition) - startPosition; + identifier = str.substring(startPosition, endPosition); + // System.out.println(identifier); + // determine if this identitfer is a keyword // @todo improve this in future version Integer i = (Integer) keywordMap.get(identifier.toLowerCase()); @@ -1361,6 +1314,13 @@ public class PHPParser extends PHPKeywords { } } + /** + * Get a number. + * if it's a double the number will be stored in doubleNumber and the token will have the + * value {@link PHPParser#TokenNameDOUBLE_NUMBER}
+ * if it's a double the number will be stored in longNumber and the token will have the + * value {@link PHPParser#TokenNameINT_NUMBER} + */ private void getNumber() { StringBuffer inum = new StringBuffer(); char dFlag = ' '; @@ -1433,11 +1393,11 @@ public class PHPParser extends PHPKeywords { try { if (dFlag != ' ') { doubleNumber = new Double(inum.toString()); - token = TT_DOUBLE_NUMBER; + token = TokenNameDoubleLiteral; return; } else { longNumber = Long.valueOf(inum.toString(), numFormat); - token = TT_INT_NUMBER; + token = TokenNameIntegerLiteral; return; } @@ -1446,6 +1406,45 @@ public class PHPParser extends PHPKeywords { } } + /** + * Get a String. + * @param openChar the opening char ('\'', '"', '`') + * @param typeString the type of string {@link #TokenNameSTRING_CONSTANT},{@link #TokenNameINTERPOLATED_STRING} + * @param errorMsg the error message in case of parse error in the string + */ + private void getString(final char openChar, final int typeString, final String errorMsg) { + StringBuffer sBuffer = new StringBuffer(); + boolean openString = true; + int startRow = rowCount; + while (str.length() > chIndx) { + ch = str.charAt(chIndx++); + if (ch == '\\') { + sBuffer.append(ch); + if (str.length() > chIndx) { + ch = str.charAt(chIndx++); + sBuffer.append(ch); + } + } else if (ch == openChar) { + openString = false; + break; + } else if (ch == '\n') { + rowCount++; + columnCount = chIndx; + } else { + sBuffer.append(ch); + } + } + if (openString) { + if (typeString == TokenNameStringConstant) { + throwSyntaxError(errorMsg, startRow); + } else { + throwSyntaxError(errorMsg); + } + } + token = typeString; + stringValue = sBuffer.toString(); + } + public void htmlParserTester(String input) { int lineNumber = 1; int startLineNumber = 1; @@ -1641,7 +1640,7 @@ public class PHPParser extends PHPKeywords { this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString(); } } - this.token = TT_EOF; + this.token = TokenNameEOF; this.chIndx = 0; this.rowCount = rowCount; this.columnCount = 0; @@ -1650,27 +1649,27 @@ public class PHPParser extends PHPKeywords { getNextToken(); do { try { - if (token != TT_EOF && token != TT_UNDEFINED) { + if (token != TokenNameEOF && token != TokenNameERROR) { statementList(); } - if (token != TT_EOF && token != TT_UNDEFINED) { - if (token == TT_ARGCLOSE) { + if (token != TokenNameEOF && token != TokenNameERROR) { + if (token == TokenNameRPAREN) { throwSyntaxError("Too many closing ')'; end-of-file not reached."); } - if (token == TT_LISTCLOSE) { + if (token == TokenNameRBRACE) { throwSyntaxError("Too many closing '}'; end-of-file not reached."); } - if (token == TT_PARTCLOSE) { + if (token == TokenNameRBRACKET) { throwSyntaxError("Too many closing ']'; end-of-file not reached."); } - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { throwSyntaxError("Read character '('; end-of-file not reached."); } - if (token == TT_LISTOPEN) { + if (token == TokenNameLBRACE) { throwSyntaxError("Read character '{'; end-of-file not reached."); } - if (token == TT_PARTOPEN) { + if (token == TokenNameLBRACKET) { throwSyntaxError("Read character '['; end-of-file not reached."); } @@ -1686,13 +1685,13 @@ public class PHPParser extends PHPKeywords { // if an error occured, // try to find keywords 'class' or 'function' // to parse the rest of the string - while (token != TT_EOF && token != TT_UNDEFINED) { - if (token == TT_class || token == TT_function) { + while (token != TokenNameEOF && token != TokenNameERROR) { + if (token == TokenNameclass || token == TokenNamefunction) { break; } getNextToken(); } - if (token == TT_EOF || token == TT_UNDEFINED) { + if (token == TokenNameEOF || token == TokenNameERROR) { return; } } @@ -1706,7 +1705,7 @@ public class PHPParser extends PHPKeywords { */ public void parse(String s) throws CoreException { this.str = s; - this.token = TT_EOF; + this.token = TokenNameEOF; this.chIndx = 0; this.rowCount = 1; this.columnCount = 0; @@ -1715,27 +1714,27 @@ public class PHPParser extends PHPKeywords { getNextToken(); do { try { - if (token != TT_EOF && token != TT_UNDEFINED) { + if (token != TokenNameEOF && token != TokenNameERROR) { statementList(); } - if (token != TT_EOF && token != TT_UNDEFINED) { - if (token == TT_ARGCLOSE) { + if (token != TokenNameEOF && token != TokenNameERROR) { + if (token == TokenNameRPAREN) { throwSyntaxError("Too many closing ')'; end-of-file not reached."); } - if (token == TT_LISTCLOSE) { + if (token == TokenNameRBRACE) { throwSyntaxError("Too many closing '}'; end-of-file not reached."); } - if (token == TT_PARTCLOSE) { + if (token == TokenNameRBRACKET) { throwSyntaxError("Too many closing ']'; end-of-file not reached."); } - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { throwSyntaxError("Read character '('; end-of-file not reached."); } - if (token == TT_LISTOPEN) { + if (token == TokenNameLBRACE) { throwSyntaxError("Read character '{'; end-of-file not reached."); } - if (token == TT_PARTOPEN) { + if (token == TokenNameLBRACKET) { throwSyntaxError("Read character '['; end-of-file not reached."); } @@ -1748,13 +1747,13 @@ public class PHPParser extends PHPKeywords { // if an error occured, // try to find keywords 'class' or 'function' // to parse the rest of the string - while (token != TT_EOF && token != TT_UNDEFINED) { - if (token == TT_class || token == TT_function) { + while (token != TokenNameEOF && token != TokenNameERROR) { + if (token == TokenNameclass || token == TokenNamefunction) { break; } getNextToken(); } - if (token == TT_EOF || token == TT_UNDEFINED) { + if (token == TokenNameEOF || token == TokenNameERROR) { return; } } catch (SyntaxError sytaxErr2) { @@ -1772,7 +1771,7 @@ public class PHPParser extends PHPKeywords { // stack.push(outlineInfo.getDeclarations()); this.str = s; - this.token = TT_EOF; + this.token = TokenNameEOF; this.chIndx = 0; this.rowCount = 1; this.columnCount = 0; @@ -1787,78 +1786,114 @@ public class PHPParser extends PHPKeywords { return outlineInfo; } - private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPClassDeclaration current, boolean goBack) { + private void parseDeclarations(PHPOutlineInfo outlineInfo, PHPSegmentWithChildren current, boolean goBack) { // PHPClassDeclaration current = (PHPClassDeclaration) stack.peek(); - PHPClassDeclaration temp; + PHPSegmentWithChildren temp; int counter = 0; + String oldIdentifier; IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); try { - while (token != TT_EOF && token != TT_UNDEFINED) { - if (token == TT_VARIABLE) { + while (token != TokenNameEOF && token != TokenNameERROR) { + if (token == TokenNameVariable) { outlineInfo.addVariable(identifier); getNextToken(); - } else if (token == TT_var) { + } else if (token == TokenNamevar) { getNextToken(); - if (token == TT_VARIABLE && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) { - outlineInfo.addVariable(identifier); - current.add(new PHPVarDeclaration(current, identifier, chIndx - identifier.length())); + if (token == TokenNameVariable && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) { getNextToken(); + outlineInfo.addVariable(identifier); + if (token != TokenNameSEMICOLON) { + oldIdentifier = identifier; + getNextToken(); + switch (token) { + case TokenNameVariable : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),identifier)); + break; + case TokenNameIdentifier : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),identifier)); + break; + case TokenNameDoubleLiteral : current.add(new PHPVarDeclaration(current, oldIdentifier + doubleNumber, chIndx - identifier.length(),doubleNumber.toString())); + break; + case TokenNameIntegerLiteral : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),longNumber.toString())); + break; + case TokenNameStringInterpolated : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),stringValue)); + break; + case TokenNameStringConstant : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),stringValue)); + break; + default : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length())); + break; + } + } else { + current.add(new PHPVarDeclaration(current, identifier, chIndx - identifier.length())); + } } - } else if (token == TT_function) { + } else if (token == TokenNamefunction) { getNextToken(); - if (token == TT_AMPERSAND) { + if (token == TokenNameAND) { getNextToken(); } - if (token == TT_IDENTIFIER && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) { + if (token == TokenNameIdentifier && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_FUNC)) { outlineInfo.addVariable(identifier); - current.add(new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length())); + temp = new PHPFunctionDeclaration(current, identifier, chIndx - identifier.length()); + current.add(temp); getNextToken(); + parseDeclarations(outlineInfo, temp, true); } - } else if (token == TT_class) { + } else if (token == TokenNameclass) { getNextToken(); - if (token == TT_IDENTIFIER && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) { + if (token == TokenNameIdentifier && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_CLASS)) { outlineInfo.addVariable(identifier); temp = new PHPClassDeclaration(current, identifier, chIndx - identifier.length()); current.add(temp); // stack.push(temp); getNextToken(); - while (token != TT_LISTOPEN && token != TT_EOF && token != TT_UNDEFINED) { + + //skip tokens for classname, extends and others until we have the opening '{' + while (token != TokenNameLBRACE && token != TokenNameEOF && token != TokenNameERROR) { getNextToken(); } parseDeclarations(outlineInfo, temp, true); // stack.pop(); } - } else if (token == TT_LISTOPEN) { + } else if (token == TokenNameLBRACE) { getNextToken(); counter++; - } else if (token == TT_LISTCLOSE) { + } else if (token == TokenNameRBRACE) { getNextToken(); --counter; if (counter == 0 && goBack) { return; } + } else if (token == TokenNamerequire || token == TokenNamerequire_once || token == TokenNameinclude || token == TokenNameinclude_once) { + expression(); + outlineInfo.addVariable(identifier); + current.add(new PHPReqIncDeclaration(current, identifier, chIndx - identifier.length(),expression.toString())); + getNextToken(); } else { getNextToken(); } } } catch (CoreException e) { + } catch (SyntaxError sytaxErr) { + try { + setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR); + } catch (CoreException e) { + } } } private void statementList() throws CoreException { do { statement(); - if ((token == TT_LISTCLOSE) - || (token == TT_case) - || (token == TT_default) - || (token == TT_elseif) - || (token == TT_endif) - || (token == TT_endfor) - || (token == TT_endforeach) - || (token == TT_endwhile) - || (token == TT_endswitch) - || (token == TT_EOF) - || (token == TT_UNDEFINED)) { + if ((token == TokenNameRBRACE) + || (token == TokenNamecase) + || (token == TokenNamedefault) + || (token == TokenNameelseif) + || (token == TokenNameendif) + || (token == TokenNameendfor) + || (token == TokenNameendforeach) + || (token == TokenNameendwhile) + || (token == TokenNameendswitch) + || (token == TokenNameEOF) + || (token == TokenNameERROR)) { return; } } while (true); @@ -1866,15 +1901,15 @@ public class PHPParser extends PHPKeywords { private void compoundStatement() throws CoreException { // '{' [statement-list] '}' - if (token == TT_LISTOPEN) { + if (token == TokenNameLBRACE) { getNextToken(); } else { throwSyntaxError("'{' expected in compound-statement."); } - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { statementList(); } - if (token == TT_LISTCLOSE) { + if (token == TokenNameRBRACE) { getNextToken(); } else { throwSyntaxError("'}' expected in compound-statement."); @@ -1882,12 +1917,12 @@ public class PHPParser extends PHPKeywords { } private void statement() throws CoreException { - // if (token > TT_KEYWORD && token != TT_list && token != TT_new) { + // if (token > TokenNameKEYWORD && token != TokenNamelist && token != TokenNamenew) { String keyword = identifier; - if (token == TT_include || token == TT_include_once) { + if (token == TokenNameinclude || token == TokenNameinclude_once) { getNextToken(); expression(); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -1896,11 +1931,11 @@ public class PHPParser extends PHPKeywords { getNextToken(); } return; - } else if (token == TT_require || token == TT_require_once) { + } else if (token == TokenNamerequire || token == TokenNamerequire_once) { getNextToken(); //constant(); expression(); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -1909,15 +1944,15 @@ public class PHPParser extends PHPKeywords { getNextToken(); } return; - } else if (token == TT_if) { + } else if (token == TokenNameif) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'if' keyword."); } expression(); - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'if' condition."); @@ -1925,53 +1960,53 @@ public class PHPParser extends PHPKeywords { ifStatement(); return; - } else if (token == TT_switch) { + } else if (token == TokenNameswitch) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'switch' keyword."); } expression(); - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'switch' condition."); } switchStatement(); return; - } else if (token == TT_for) { + } else if (token == TokenNamefor) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'for' keyword."); } - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { expressionList(); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { throwSyntaxError("';' expected after 'for'."); } } - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { expressionList(); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { throwSyntaxError("';' expected after 'for'."); } } - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { expressionList(); - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'for'."); @@ -1979,45 +2014,45 @@ public class PHPParser extends PHPKeywords { } forStatement(); return; - } else if (token == TT_while) { + } else if (token == TokenNamewhile) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'while' keyword."); } expression(); - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'while' condition."); } whileStatement(); return; - } else if (token == TT_do) { + } else if (token == TokenNamedo) { getNextToken(); - if (token == TT_LISTOPEN) { + if (token == TokenNameLBRACE) { getNextToken(); } else { throwSyntaxError("'{' expected after 'do' keyword."); } - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { statementList(); } - if (token == TT_LISTCLOSE) { + if (token == TokenNameRBRACE) { getNextToken(); } else { throwSyntaxError("'}' expected after 'do' keyword."); } - if (token == TT_while) { + if (token == TokenNamewhile) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'while' keyword."); } expression(); - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'while' condition."); @@ -2025,7 +2060,7 @@ public class PHPParser extends PHPKeywords { } else { throwSyntaxError("'while' expected after 'do' keyword."); } - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -2034,25 +2069,25 @@ public class PHPParser extends PHPKeywords { getNextToken(); } return; - } else if (token == TT_foreach) { + } else if (token == TokenNameforeach) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'foreach' keyword."); } expression(); - if (token == TT_as) { + if (token == TokenNameas) { getNextToken(); } else { throwSyntaxError("'as' expected after 'foreach' exxpression."); } variable(); - if (token == TT_FOREACH) { + if (token == TokenNameFOREACH) { getNextToken(); variable(); } - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'foreach' expression."); @@ -2060,12 +2095,12 @@ public class PHPParser extends PHPKeywords { foreachStatement(); return; - } else if (token == TT_continue || token == TT_break || token == TT_return) { + } else if (token == TokenNamecontinue || token == TokenNamebreak || token == TokenNamereturn) { getNextToken(); - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { expression(); } - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -2075,10 +2110,10 @@ public class PHPParser extends PHPKeywords { } return; - } else if (token == TT_echo) { + } else if (token == TokenNameecho) { getNextToken(); expressionList(); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -2087,10 +2122,10 @@ public class PHPParser extends PHPKeywords { getNextToken(); } return; - // } else if (token == TT_print) { + // } else if (token == TokenNameprint) { // getNextToken(); // expression(); - // if (token == TT_SEMICOLON) { + // if (token == TokenNameSEMICOLON) { // getNextToken(); // } else { // if (!phpEnd) { @@ -2100,10 +2135,10 @@ public class PHPParser extends PHPKeywords { // } // return; - } else if (token == TT_global || token == TT_static) { + } else if (token == TokenNameglobal || token == TokenNamestatic) { getNextToken(); variableList(); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -2113,20 +2148,20 @@ public class PHPParser extends PHPKeywords { } return; - // } else if (token == TT_unset) { + // } else if (token == TokenNameunset) { // getNextToken(); - // if (token == TT_ARGOPEN) { + // if (token == TokenNameARGOPEN) { // getNextToken(); // } else { // throwSyntaxError("'(' expected after 'unset' keyword."); // } // variableList(); - // if (token == TT_ARGCLOSE) { + // if (token == TokenNameARGCLOSE) { // getNextToken(); // } else { // throwSyntaxError("')' expected after 'unset' statement."); // } - // if (token == TT_SEMICOLON) { + // if (token == TokenNameSEMICOLON) { // getNextToken(); // } else { // if (!phpEnd) { @@ -2136,12 +2171,12 @@ public class PHPParser extends PHPKeywords { // } // return; - // } else if (token == TT_exit || token == TT_die) { + // } else if (token == TokenNameexit || token == TokenNamedie) { // getNextToken(); - // if (token != TT_SEMICOLON) { + // if (token != TokenNameSEMICOLON) { // exitStatus(); // } - // if (token == TT_SEMICOLON) { + // if (token == TokenNameSEMICOLON) { // getNextToken(); // } else { // if (!phpEnd) { @@ -2151,30 +2186,30 @@ public class PHPParser extends PHPKeywords { // } // return; - } else if (token == TT_define) { + } else if (token == TokenNamedefine) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'define' keyword."); } expression(); - if (token == TT_COMMA) { + if (token == TokenNameCOMMA) { getNextToken(); } else { throwSyntaxError("',' expected after first 'define' constant."); } expression(); - if (token == TT_COMMA) { + if (token == TokenNameCOMMA) { getNextToken(); expression(); } - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'define' statement."); } - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { if (!phpEnd) { @@ -2183,34 +2218,34 @@ public class PHPParser extends PHPKeywords { getNextToken(); } return; - } else if (token == TT_function) { + } else if (token == TokenNamefunction) { getNextToken(); functionDefinition(); return; - } else if (token == TT_class) { + } else if (token == TokenNameclass) { getNextToken(); classDeclarator(); classBody(); return; // } else { // throwSyntaxError("Unexpected keyword '" + keyword + "'"); - } else if (token == TT_LISTOPEN) { + } else if (token == TokenNameLBRACE) { // compoundStatement getNextToken(); - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { statementList(); } - if (token == TT_LISTCLOSE) { + if (token == TokenNameRBRACE) { getNextToken(); return; } else { throwSyntaxError("'}' expected."); } } else { - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { expression(); } - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); return; } else { @@ -2225,11 +2260,11 @@ public class PHPParser extends PHPKeywords { private void classDeclarator() throws CoreException { //identifier //identifier 'extends' identifier - if (token == TT_IDENTIFIER) { + if (token == TokenNameIdentifier) { getNextToken(); - if (token == TT_extends) { + if (token == TokenNameextends) { getNextToken(); - if (token == TT_IDENTIFIER) { + if (token == TokenNameIdentifier) { getNextToken(); } else { throwSyntaxError("Class name expected after keyword 'extends'."); @@ -2242,12 +2277,12 @@ public class PHPParser extends PHPKeywords { private void classBody() throws CoreException { //'{' [class-element-list] '}' - if (token == TT_LISTOPEN) { + if (token == TokenNameLBRACE) { getNextToken(); - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { classElementList(); } - if (token == TT_LISTCLOSE) { + if (token == TokenNameRBRACE) { getNextToken(); } else { throwSyntaxError("'}' expected at end of class body."); @@ -2260,16 +2295,16 @@ public class PHPParser extends PHPKeywords { private void classElementList() throws CoreException { do { classElement(); - } while (token == TT_function || token == TT_var); + } while (token == TokenNamefunction || token == TokenNamevar); } private void classElement() throws CoreException { //class-property //function-definition - if (token == TT_function) { + if (token == TokenNamefunction) { getNextToken(); functionDefinition(); - } else if (token == TT_var) { + } else if (token == TokenNamevar) { getNextToken(); classProperty(); } else { @@ -2281,21 +2316,21 @@ public class PHPParser extends PHPKeywords { //'var' variable ';' //'var' variable '=' constant ';' do { - if (token == TT_VARIABLE) { + if (token == TokenNameVariable) { getNextToken(); - if (token == TT_ASSIGN) { + if (token == TokenNameEQUAL) { getNextToken(); constant(); } } else { throwSyntaxError("Variable expected after keyword 'var'."); } - if (token != TT_COMMA) { + if (token != TokenNameCOMMA) { break; } getNextToken(); } while (true); - if (token == TT_SEMICOLON) { + if (token == TokenNameSEMICOLON) { getNextToken(); } else { throwSyntaxError("';' expected after variable declaration."); @@ -2309,20 +2344,20 @@ public class PHPParser extends PHPKeywords { private void functionDeclarator() throws CoreException { //identifier '(' [parameter-list] ')' - if (token == TT_AMPERSAND) { + if (token == TokenNameAND) { getNextToken(); } - if (token == TT_IDENTIFIER) { + if (token == TokenNameIdentifier) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected in function declaration."); } - if (token != TT_ARGCLOSE) { + if (token != TokenNameRPAREN) { parameterList(); } - if (token != TT_ARGCLOSE) { + if (token != TokenNameRPAREN) { throwSyntaxError("')' expected in function declaration."); } else { getNextToken(); @@ -2335,7 +2370,7 @@ public class PHPParser extends PHPKeywords { //parameter-list ',' parameter-declaration do { parameterDeclaration(); - if (token != TT_COMMA) { + if (token != TokenNameCOMMA) { break; } getNextToken(); @@ -2345,18 +2380,18 @@ public class PHPParser extends PHPKeywords { private void parameterDeclaration() throws CoreException { //variable //variable-reference - if (token == TT_AMPERSAND) { + if (token == TokenNameAND) { getNextToken(); - if (token == TT_VARIABLE) { + if (token == TokenNameVariable) { getNextToken(); } else { throwSyntaxError("Variable expected after reference operator '&'."); } } //variable '=' constant - if (token == TT_VARIABLE) { + if (token == TokenNameVariable) { getNextToken(); - if (token == TT_ASSIGN) { + if (token == TokenNameEQUAL) { getNextToken(); constant(); } @@ -2365,55 +2400,55 @@ public class PHPParser extends PHPKeywords { } private void labeledStatementList() throws CoreException { - if (token != TT_case && token != TT_default) { + if (token != TokenNamecase && token != TokenNamedefault) { throwSyntaxError("'case' or 'default' expected."); } do { - if (token == TT_case) { + if (token == TokenNamecase) { getNextToken(); constant(); - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); - if (token == TT_case || token == TT_default) { // empty case statement ? + if (token == TokenNamecase || token == TokenNamedefault) { // empty case statement ? continue; } statementList(); - } else if (token == TT_SEMICOLON) { + } else if (token == TokenNameSEMICOLON) { setMarker("':' expected after 'case' keyword found ';'.", rowCount, PHPParser.INFO); getNextToken(); - if (token == TT_case) { // empty case statement ? + if (token == TokenNamecase) { // empty case statement ? continue; } statementList(); } else { throwSyntaxError("':' character after 'case' constant expected."); } - } else { // TT_default + } else { // TokenNamedefault getNextToken(); - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); } else { throwSyntaxError("':' character after 'default' expected."); } } - } while (token == TT_case || token == TT_default); + } while (token == TokenNamecase || token == TokenNamedefault); } // public void labeledStatement() { - // if (token == TT_case) { + // if (token == TokenNamecase) { // getNextToken(); // constant(); - // if (token == TT_DDOT) { + // if (token == TokenNameDDOT) { // getNextToken(); // statement(); // } else { // throwSyntaxError("':' character after 'case' constant expected."); // } // return; - // } else if (token == TT_default) { + // } else if (token == TokenNamedefault) { // getNextToken(); - // if (token == TT_DDOT) { + // if (token == TokenNameDDOT) { // getNextToken(); // statement(); // } else { @@ -2455,17 +2490,17 @@ public class PHPParser extends PHPKeywords { private void ifStatement() throws CoreException { // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';' - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); switch (token) { - case TT_else : + case TokenNameelse : getNextToken(); - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); } else { - if (token == TT_if) { //'else if' + if (token == TokenNameif) { //'else if' getNextToken(); elseifStatementList(); } else { @@ -2473,38 +2508,38 @@ public class PHPParser extends PHPKeywords { } } break; - case TT_elseif : + case TokenNameelseif : getNextToken(); elseifStatementList(); break; } - if (token != TT_endif) { + if (token != TokenNameendif) { throwSyntaxError("'endif' expected."); } getNextToken(); - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { throwSyntaxError("';' expected after if-statement."); } getNextToken(); } else { // statement [else-statement] statement(); - if (token == TT_elseif) { + if (token == TokenNameelseif) { getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected after 'elseif' keyword."); } expression(); - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'elseif' condition."); } ifStatement(); - } else if (token == TT_else) { + } else if (token == TokenNameelse) { getNextToken(); statement(); } @@ -2515,21 +2550,21 @@ public class PHPParser extends PHPKeywords { do { elseifStatement(); switch (token) { - case TT_else : + case TokenNameelse : getNextToken(); - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); return; } else { - if (token == TT_if) { //'else if' + if (token == TokenNameif) { //'else if' getNextToken(); } else { throwSyntaxError("':' expected after 'else'."); } } break; - case TT_elseif : + case TokenNameelseif : getNextToken(); break; default : @@ -2539,14 +2574,14 @@ public class PHPParser extends PHPKeywords { } private void elseifStatement() throws CoreException { - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); expression(); - if (token != TT_ARGOPEN) { + if (token != TokenNameLPAREN) { throwSyntaxError("')' expected in else-if-statement."); } getNextToken(); - if (token != TT_DDOT) { + if (token != TokenNameCOLON) { throwSyntaxError("':' expected in else-if-statement."); } getNextToken(); @@ -2555,28 +2590,28 @@ public class PHPParser extends PHPKeywords { } private void switchStatement() throws CoreException { - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { // ':' [labeled-statement-list] 'endswitch' ';' getNextToken(); labeledStatementList(); - if (token != TT_endswitch) { + if (token != TokenNameendswitch) { throwSyntaxError("'endswitch' expected."); } getNextToken(); - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { throwSyntaxError("';' expected after switch-statement."); } getNextToken(); } else { // '{' [labeled-statement-list] '}' - if (token != TT_LISTOPEN) { + if (token != TokenNameLBRACE) { throwSyntaxError("'{' expected in switch statement."); } getNextToken(); - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { labeledStatementList(); } - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { throwSyntaxError("'}' expected in switch statement."); } getNextToken(); @@ -2585,14 +2620,14 @@ public class PHPParser extends PHPKeywords { } private void forStatement() throws CoreException { - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); - if (token != TT_endfor) { + if (token != TokenNameendfor) { throwSyntaxError("'endfor' expected."); } getNextToken(); - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { throwSyntaxError("';' expected after for-statement."); } getNextToken(); @@ -2603,14 +2638,14 @@ public class PHPParser extends PHPKeywords { private void whileStatement() throws CoreException { // ':' statement-list 'endwhile' ';' - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); - if (token != TT_endwhile) { + if (token != TokenNameendwhile) { throwSyntaxError("'endwhile' expected."); } getNextToken(); - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { throwSyntaxError("';' expected after while-statement."); } getNextToken(); @@ -2620,14 +2655,14 @@ public class PHPParser extends PHPKeywords { } private void foreachStatement() throws CoreException { - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); statementList(); - if (token != TT_endforeach) { + if (token != TokenNameendforeach) { throwSyntaxError("'endforeach' expected."); } getNextToken(); - if (token != TT_SEMICOLON) { + if (token != TokenNameSEMICOLON) { throwSyntaxError("';' expected after foreach-statement."); } getNextToken(); @@ -2637,15 +2672,15 @@ public class PHPParser extends PHPKeywords { } private void exitStatus() throws CoreException { - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); } else { throwSyntaxError("'(' expected in 'exit-status'."); } - if (token != TT_ARGCLOSE) { + if (token != TokenNameRPAREN) { expression(); } - if (token == TT_ARGCLOSE) { + if (token == TokenNameRPAREN) { getNextToken(); } else { throwSyntaxError("')' expected after 'exit-status'."); @@ -2655,7 +2690,7 @@ public class PHPParser extends PHPKeywords { private void expressionList() throws CoreException { do { expression(); - if (token == TT_COMMA) { + if (token == TokenNameCOMMA) { getNextToken(); } else { break; @@ -2664,11 +2699,19 @@ public class PHPParser extends PHPKeywords { } private void expression() throws CoreException { - // if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) { + //todo: find a better way to get the expression + expression = new StringBuffer(); + for (int i = chIndx;i + case TokenNameCOLON_COLON : // :: + case TokenNameMINUS_GREATER : // -> getNextToken(); - if (token > TT_KEYWORD) { + if (token > TokenNameKEYWORD) { ident = identifier; setMarker("Avoid using keyword '" + ident + "' as variable name.", rowCount, PHPParser.INFO); } switch (token) { - case TT_VARIABLE : + case TokenNameVariable : ident = identifier; getNextToken(); - // if (token == TT_ARGOPEN) { + // if (token == TokenNameARGOPEN) { // getNextToken(); // expressionList(); - // if (token != TT_ARGCLOSE) { + // if (token != TokenNameARGCLOSE) { // throwSyntaxError(") expected after variable '" + ident + "'."); // } // getNextToken(); // } break; - case TT_IDENTIFIER : + case TokenNameIdentifier : ident = identifier; getNextToken(); break; - case TT_LISTOPEN : + case TokenNameLBRACE : getNextToken(); expression(); - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { throwSyntaxError("} expected in postfix-expression."); } getNextToken(); break; default : throwSyntaxError("Syntax error after '->' token."); - } while (token == TT_PARTOPEN || token == TT_ARGOPEN || token == TT_LISTOPEN) { - if (token == TT_PARTOPEN) { + } while (token == TokenNameLBRACKET || token == TokenNameLPAREN || token == TokenNameLBRACE) { + if (token == TokenNameLBRACKET) { getNextToken(); expressionList(); - if (token != TT_PARTCLOSE) { + if (token != TokenNameRBRACKET) { throwSyntaxError("] expected after '->'."); } getNextToken(); } - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); expressionList(); - if (token != TT_ARGCLOSE) { + if (token != TokenNameRPAREN) { throwSyntaxError(") expected after '->'."); } getNextToken(); } - if (token == TT_LISTOPEN) { + if (token == TokenNameLBRACE) { getNextToken(); expression(); - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { throwSyntaxError("} expected after '->'."); } getNextToken(); } } break; - case TT_INCREMENT : + case TokenNamePLUS_PLUS : getNextToken(); break; - case TT_DECREMENT : + case TokenNameMINUS_MINUS : getNextToken(); break; default : @@ -2945,40 +2988,40 @@ public class PHPParser extends PHPKeywords { private void unaryExpression() throws CoreException { switch (token) { - case TT_INCREMENT : + case TokenNamePLUS_PLUS : getNextToken(); unaryExpression(); break; - case TT_DECREMENT : + case TokenNameMINUS_MINUS : getNextToken(); unaryExpression(); break; // '@' '&' '*' '+' '-' '~' '!' - case TT_AT : + case TokenNameAT : getNextToken(); castExpression(); break; - case TT_AMPERSAND : + case TokenNameAND : getNextToken(); castExpression(); break; - case TT_MULTIPLY : + case TokenNameMULTIPLY : getNextToken(); castExpression(); break; - case TT_ADD : + case TokenNamePLUS : getNextToken(); castExpression(); break; - case TT_SUBTRACT : + case TokenNameMINUS : getNextToken(); castExpression(); break; - case TT_TILDE : + case TokenNameTWIDDLE : getNextToken(); castExpression(); break; - case TT_NOT : + case TokenNameNOT : getNextToken(); castExpression(); break; @@ -2988,10 +3031,10 @@ public class PHPParser extends PHPKeywords { } private void castExpression() throws CoreException { - // if (token == TT_ARGOPEN) { + // if (token == TokenNameARGOPEN) { // getNextToken(); // typeName(); - // if (token != TT_ARGCLOSE) { + // if (token != TokenNameARGCLOSE) { // throwSyntaxError(") expected after cast-expression."); // } // getNextToken(); @@ -3005,7 +3048,7 @@ public class PHPParser extends PHPKeywords { //'real' 'double' 'float' //'int' 'integer' String ident = ""; - if (token == TT_IDENTIFIER) { + if (token == TokenNameIdentifier) { ident = identifier; String str = identifier.toLowerCase(); getNextToken(); @@ -3020,43 +3063,43 @@ public class PHPParser extends PHPKeywords { private void assignExpression() throws CoreException { castExpression(); - if (token == TT_ASSIGN) { // = + if (token == TokenNameEQUAL) { // = getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_DOTASSIGN) { // .= + } else if (token == TokenNameDOT_EQUAL) { // .= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_FOREACH) { // => + } else if (token == TokenNameFOREACH) { // => getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_ADDTO) { // += + } else if (token == TokenNamePLUS_EQUAL) { // += getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_SUBTRACTFROM) { // -= + } else if (token == TokenNameMINUS_EQUAL) { // -= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_TIMESBY) { // *= + } else if (token == TokenNameMULTIPLY_EQUAL) { // *= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_DIVIDEBY) { // *= + } else if (token == TokenNameDIVIDE_EQUAL) { // *= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_MODASSIGN) { // %= + } else if (token == TokenNameREMAINDER_EQUAL) { // %= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_ANDASSIGN) { // &= + } else if (token == TokenNameAND_EQUAL) { // &= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_POWASSIGN) { // ^= + } else if (token == TokenNameXOR_EQUAL) { // ^= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_LSHIFTASSIGN) { // <<= + } else if (token == TokenNameLEFT_SHIFT_EQUAL) { // <<= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_RSHIFTASSIGN) { // >>= + } else if (token == TokenNameRIGHT_SHIFT_EQUAL) { // >>= getNextToken(); logicalinclusiveorExpression(); - } else if (token == TT_TILDEASSIGN) { // ~= + } else if (token == TokenNameTWIDDLE_EQUAL) { // ~= getNextToken(); logicalinclusiveorExpression(); } @@ -3065,7 +3108,7 @@ public class PHPParser extends PHPKeywords { private void multiplicativeExpression() throws CoreException { do { assignExpression(); - if (token != TT_MULTIPLY && token != TT_DIV && token != TT_MOD) { + if (token != TokenNameMULTIPLY && token != TokenNameDIVIDE && token != TokenNameREMAINDER) { return; } getNextToken(); @@ -3075,7 +3118,7 @@ public class PHPParser extends PHPKeywords { private void concatenationExpression() throws CoreException { do { multiplicativeExpression(); - if (token != TT_DOT) { + if (token != TokenNameDOT) { return; } getNextToken(); @@ -3085,7 +3128,7 @@ public class PHPParser extends PHPKeywords { private void additiveExpression() throws CoreException { do { concatenationExpression(); - if (token != TT_ADD && token != TT_SUBTRACT) { + if (token != TokenNamePLUS && token != TokenNameMINUS) { return; } getNextToken(); @@ -3095,7 +3138,7 @@ public class PHPParser extends PHPKeywords { private void shiftExpression() throws CoreException { do { additiveExpression(); - if (token != TT_LSHIFT && token != TT_RSHIFT) { + if (token != TokenNameLEFT_SHIFT && token != TokenNameRIGHT_SHIFT) { return; } getNextToken(); @@ -3105,7 +3148,7 @@ public class PHPParser extends PHPKeywords { private void relationalExpression() throws CoreException { do { shiftExpression(); - if (token != TT_LESS && token != TT_GREATER && token != TT_LESSEQUAL && token != TT_GREATEREQUAL) { + if (token != TokenNameLESS && token != TokenNameGREATER && token != TokenNameLESS_EQUAL && token != TokenNameGREATER_EQUAL) { return; } getNextToken(); @@ -3115,7 +3158,7 @@ public class PHPParser extends PHPKeywords { private void identicalExpression() throws CoreException { do { relationalExpression(); - if (token != TT_EX_EQUAL && token != TT_EX_UNEQUAL) { + if (token != TokenNameEQUAL_EQUAL_EQUAL && token != TokenNameNOT_EQUAL_EQUAL) { return; } getNextToken(); @@ -3125,7 +3168,7 @@ public class PHPParser extends PHPKeywords { private void equalityExpression() throws CoreException { do { identicalExpression(); - if (token != TT_EQUAL && token != TT_UNEQUAL) { + if (token != TokenNameEQUAL_EQUAL && token != TokenNameNOT_EQUAL) { return; } getNextToken(); @@ -3134,10 +3177,10 @@ public class PHPParser extends PHPKeywords { private void ternaryExpression() throws CoreException { equalityExpression(); - if (token == TT_QUESTIONMARK) { + if (token == TokenNameQUESTION) { getNextToken(); expression(); - if (token == TT_DDOT) { + if (token == TokenNameCOLON) { getNextToken(); expression(); } else { @@ -3149,7 +3192,7 @@ public class PHPParser extends PHPKeywords { private void andExpression() throws CoreException { do { ternaryExpression(); - if (token != TT_AMPERSAND) { + if (token != TokenNameAND) { return; } getNextToken(); @@ -3159,7 +3202,7 @@ public class PHPParser extends PHPKeywords { private void exclusiveorExpression() throws CoreException { do { andExpression(); - if (token != TT_POW) { + if (token != TokenNameXOR) { return; } getNextToken(); @@ -3169,7 +3212,7 @@ public class PHPParser extends PHPKeywords { private void inclusiveorExpression() throws CoreException { do { exclusiveorExpression(); - if (token != TT_LINE) { + if (token != TokenNameOR) { return; } getNextToken(); @@ -3179,7 +3222,7 @@ public class PHPParser extends PHPKeywords { private void booleanandExpression() throws CoreException { do { inclusiveorExpression(); - if (token != TT_AND) { + if (token != TokenNameAND_AND) { return; } getNextToken(); @@ -3189,7 +3232,7 @@ public class PHPParser extends PHPKeywords { private void booleanorExpression() throws CoreException { do { booleanandExpression(); - if (token != TT_OR) { + if (token != TokenNameOR_OR) { return; } getNextToken(); @@ -3199,7 +3242,7 @@ public class PHPParser extends PHPKeywords { private void logicalandExpression() throws CoreException { do { booleanorExpression(); - if (token != TT_and) { + if (token != TokenNameAND) { return; } getNextToken(); @@ -3209,7 +3252,7 @@ public class PHPParser extends PHPKeywords { private void logicalexclusiveorExpression() throws CoreException { do { logicalandExpression(); - if (token != TT_xor) { + if (token != TokenNameXOR) { return; } getNextToken(); @@ -3219,7 +3262,7 @@ public class PHPParser extends PHPKeywords { private void logicalinclusiveorExpression() throws CoreException { do { logicalexclusiveorExpression(); - if (token != TT_or) { + if (token != TokenNameOR) { return; } getNextToken(); @@ -3227,9 +3270,9 @@ public class PHPParser extends PHPKeywords { } // public void assignmentExpression() { - // if (token == TT_VARIABLE) { + // if (token == TokenNameVARIABLE) { // getNextToken(); - // if (token == TT_SET) { + // if (token == TokenNameSET) { // getNextToken(); // logicalinclusiveorExpression(); // } @@ -3241,7 +3284,7 @@ public class PHPParser extends PHPKeywords { private void variableList() throws CoreException { do { variable(); - if (token == TT_COMMA) { + if (token == TokenNameCOMMA) { getNextToken(); } else { break; @@ -3250,25 +3293,25 @@ public class PHPParser extends PHPKeywords { } private void variable() throws CoreException { - if (token == TT_DOLLAROPEN) { + if (token == TokenNameDOLLAROPEN) { getNextToken(); expression(); ; - if (token != TT_LISTCLOSE) { + if (token != TokenNameRBRACE) { throwSyntaxError("'}' expected after indirect variable token '${'."); } getNextToken(); } else { - if (token == TT_VARIABLE) { + if (token == TokenNameVariable) { getNextToken(); - if (token == TT_PARTOPEN) { + if (token == TokenNameLBRACKET) { getNextToken(); expression(); - if (token != TT_PARTCLOSE) { + if (token != TokenNameRBRACKET) { throwSyntaxError("']' expected in variable-list."); } getNextToken(); - } else if (token == TT_ASSIGN) { + } else if (token == TokenNameEQUAL) { getNextToken(); constant(); } @@ -3278,68 +3321,72 @@ public class PHPParser extends PHPKeywords { } } + /** + * It will look for a value (after a '=' for example) + * @throws CoreException + */ private void constant() throws CoreException { String ident; switch (token) { - case TT_ADD : + case TokenNamePLUS : getNextToken(); switch (token) { - case TT_DOUBLE_NUMBER : + case TokenNameDoubleLiteral : getNextToken(); break; - case TT_INT_NUMBER : + case TokenNameIntegerLiteral : getNextToken(); break; default : throwSyntaxError("Constant expected after '+' presign."); } break; - case TT_SUBTRACT : + case TokenNameMINUS : getNextToken(); switch (token) { - case TT_DOUBLE_NUMBER : + case TokenNameDoubleLiteral : getNextToken(); break; - case TT_INT_NUMBER : + case TokenNameIntegerLiteral : getNextToken(); break; default : throwSyntaxError("Constant expected after '-' presign."); } break; - case TT_null : + case TokenNamenull : getNextToken(); break; - case TT_false : + case TokenNamefalse : getNextToken(); break; - case TT_true : + case TokenNametrue : getNextToken(); break; - case TT_IDENTIFIER : + case TokenNameIdentifier : ident = identifier; getNextToken(); - if (token == TT_ARGOPEN) { + if (token == TokenNameLPAREN) { getNextToken(); - if (token != TT_ARGCLOSE) { + if (token != TokenNameRPAREN) { expressionList(); - if (token != TT_ARGCLOSE) { + if (token != TokenNameRPAREN) { throwSyntaxError("')' expected after identifier '" + ident + "' in postfix-expression."); } } getNextToken(); } break; - case TT_STRING_CONSTANT : + case TokenNameStringConstant : getNextToken(); break; - case TT_INTERPOLATED_STRING : + case TokenNameStringInterpolated : getNextToken(); break; - case TT_DOUBLE_NUMBER : + case TokenNameDoubleLiteral : getNextToken(); break; - case TT_INT_NUMBER : + case TokenNameIntegerLiteral : getNextToken(); break; default : @@ -3361,9 +3408,9 @@ public class PHPParser extends PHPKeywords { MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF)); String command = form.format(arguments); - String parserResult = PHPStartApacheAction.execute(command, "External parser: "); + String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: "); - try { + try { // parse the buffer to find the errors and warnings createMarkers(parserResult, file); } catch (CoreException e) {