X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java index 5848e7d..98ce451 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java @@ -1,8 +1,14 @@ package net.sourceforge.phpeclipse.phpeditor; +import java.util.ArrayList; import java.util.HashMap; +import java.util.Hashtable; 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.ui.texteditor.MarkerUtilities; /********************************************************************** Copyright (c) 2000, 2002 IBM Corp. and others. @@ -18,6 +24,15 @@ Contributors: 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; + + private int currentPHPString; + private boolean phpEnd; + private static HashMap keywordMap = null; private String str; @@ -62,12 +77,19 @@ public class PHPParser extends PHPKeywords { final static int TT_DDOT = 47; final static int TT_DOTASSIGN = 48; - final static int TT_SET = 49; + 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_ARGOPEN = 128; final static int TT_ARGCLOSE = 129; @@ -108,20 +130,50 @@ public class PHPParser extends PHPKeywords { *@param sess Description of Parameter *@see */ - public PHPParser() { + public PHPParser(IFile fileToParse) { if (keywordMap == null) { keywordMap = new HashMap(); for (int i = 0; i < PHP_KEYWORS.length; i++) { keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i])); } } + this.currentPHPString = 0; + this.fileToParse = fileToParse; + this.phpList = null; this.str = ""; this.token = TT_EOF; this.chIndx = 0; this.rowCount = 1; this.columnCount = 0; + this.phpEnd = false; + + // getNextToken(); + } + + /** + * Create marker for the parse error + */ + protected void setMarker(String message, int lineNumber, int errorLevel) throws CoreException { + setMarker(fileToParse, message, lineNumber, errorLevel); + } - getNextToken(); + public static void setMarker(IFile file, String message, int lineNumber, int errorLevel) throws CoreException { + + Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + switch (errorLevel) { + case ERROR : + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + break; + case WARNING : + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + break; + case INFO : + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + break; + } + MarkerUtilities.setLineNumber(attributes, lineNumber); + MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM); } private void throwSyntaxError(String error) { @@ -155,13 +207,16 @@ public class PHPParser extends PHPKeywords { chIndx = str.length() + 1; ch = ' '; - token = TT_EOF; + // token = TT_EOF; + phpEnd = true; } /** * gets the next token from input */ void getNextToken() { + phpEnd = false; + while (str.length() > chIndx) { ch = str.charAt(chIndx++); token = TT_UNDEFINED; @@ -170,7 +225,9 @@ public class PHPParser extends PHPKeywords { columnCount = chIndx; continue; // while loop } - + if (str.length() == chIndx) { + phpEnd = true; + } if (!Character.isWhitespace(ch)) { if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$') || (ch == '@')) { getIdentifier(); @@ -197,7 +254,11 @@ public class PHPParser extends PHPKeywords { chIndx += 2; break; } - chIndx++; + ch = str.charAt(chIndx++); + if (ch == '\n') { + rowCount++; + columnCount = chIndx; + } } continue; } @@ -220,11 +281,9 @@ public class PHPParser extends PHPKeywords { } else if (ch == '"') { openString = false; break; - } else { - if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } + } else if (ch == '\n') { + rowCount++; + columnCount = chIndx; } } if (openString) { @@ -244,11 +303,9 @@ public class PHPParser extends PHPKeywords { } else if (ch == '\'') { openString = false; break; - } else { - if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } + } else if (ch == '\n') { + rowCount++; + columnCount = chIndx; } } if (openString) { @@ -288,9 +345,19 @@ public class PHPParser extends PHPKeywords { token = TT_COMMA; break; + case '?' : + token = TT_QUESTIONMARK; + break; case '~' : token = TT_TILDE; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_TILDEASSIGN; + break; + } + } break; case '.' : token = TT_DOT; @@ -310,7 +377,14 @@ public class PHPParser extends PHPKeywords { break; case '%' : token = TT_MOD; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_MODASSIGN; + break; + } + } break; case ';' : token = TT_SEMICOLON; @@ -318,7 +392,14 @@ public class PHPParser extends PHPKeywords { break; case '^' : token = TT_POW; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_POWASSIGN; + break; + } + } break; case '/' : token = TT_DIV; @@ -393,7 +474,7 @@ public class PHPParser extends PHPKeywords { break; case '=' : - token = TT_SET; + token = TT_ASSIGN; if (str.length() > chIndx) { ch = str.charAt(chIndx); @@ -447,13 +528,18 @@ public class PHPParser extends PHPKeywords { 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; } } @@ -472,7 +558,13 @@ public class PHPParser extends PHPKeywords { if (str.charAt(chIndx) == '<') { chIndx++; token = TT_LSHIFT; - + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_LSHIFTASSIGN; + break; + } + } break; } } @@ -493,17 +585,19 @@ public class PHPParser extends PHPKeywords { break; case '&' : + token = TT_AMPERSAND; if (str.length() > chIndx) { if (str.charAt(chIndx) == '&') { chIndx++; token = TT_AND; - break; - } else { - token = TT_AMPERSAND; - + } + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_ANDASSIGN; break; } + break; } break; @@ -534,6 +628,24 @@ public class PHPParser extends PHPKeywords { 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; + } + } } void getIdentifier() { @@ -644,43 +756,208 @@ public class PHPParser extends PHPKeywords { } } - public void start(String s, int rowCount) throws SyntaxError { - // start up - this.str = s; - this.token = TT_EOF; - this.chIndx = 0; - this.rowCount = rowCount; - this.columnCount = 0; - getNextToken(); + public void htmlParse(String input) { + boolean lineCommentMode = false; + boolean multiLineCommentMode = false; + boolean stringMode = false; - statementList(); - if (token != TT_EOF) { - if (token == TT_ARGCLOSE) { - throwSyntaxError("too many closing ')'; end-of-file not reached"); - } - if (token == TT_LISTCLOSE) { - throwSyntaxError("too many closing '}'; end-of-file not reached"); + StringBuffer buf = new StringBuffer(); + int lineNumber = 1; + int startLineNumber = 1; + int startIndex = 0; + char ch; + char ch2; + boolean phpMode = false; + boolean phpFound = false; + + phpList = new ArrayList(); + currentPHPString = 0; + + try { + int i = 0; + while (i < input.length()) { + ch = input.charAt(i++); + if (ch == '\n') { + lineNumber++; + } + if ((!phpMode) && ch == '<') { + ch2 = input.charAt(i++); + if (ch2 == '?') { + ch2 = input.charAt(i++); + if (Character.isWhitespace(ch2)) { + // php start + phpMode = true; + phpFound = true; + startIndex = i; + startLineNumber = lineNumber; + continue; + } else if (ch2 == 'p') { + ch2 = input.charAt(i++); + if (ch2 == 'h') { + ch2 = input.charAt(i++); + if (ch2 == 'p') { + phpMode = true; + phpFound = true; + startIndex = i; + startLineNumber = lineNumber; + continue; + } + i--; + } + i--; + } else if (ch2 == 'P') { + ch2 = input.charAt(i++); + if (ch2 == 'H') { + ch2 = input.charAt(i++); + if (ch2 == 'P') { + phpMode = true; + phpFound = true; + startIndex = i; + startLineNumber = lineNumber; + continue; + } + i--; + } + i--; + } + i--; + } + i--; + } + + if (phpMode) { + buf.append(ch); + if (lineCommentMode && (ch == '\n')) { + lineCommentMode = false; + // read until end of line + } else if ((!stringMode) && (ch == '#')) { + // read until end of line + lineCommentMode = true; + continue; + } else if ((!stringMode) && (!multiLineCommentMode) && (ch == '/')) { + ch2 = input.charAt(i++); + if (ch2 == '/') { + lineCommentMode = true; + continue; + } else if (ch2 == '*') { + multiLineCommentMode = true; + continue; + } else { + i--; + } + } else if (ch == '*' && multiLineCommentMode) { + ch2 = input.charAt(i++); + if (ch2 == '/') { + multiLineCommentMode = false; + continue; + } else { + i--; + } + } else if (ch == '\\' && stringMode) { + ch2 = input.charAt(i++); + if (ch2 == '"') { + continue; + } else { + i--; + } + } else if ((!lineCommentMode) && (!multiLineCommentMode) && (ch == '"')) { + if (stringMode) { + stringMode = false; + } else { + stringMode = true; + } + continue; + } + if (lineCommentMode || multiLineCommentMode || stringMode) { + continue; + } + + if (ch == '?') { + ch2 = input.charAt(i++); + if (ch2 == '>') { + // php end + phpMode = false; + phpList.add(new PHPString(input.substring(startIndex, i - 2), startLineNumber)); + continue; + } + i--; + } + } else { + } } - if (token == TT_PARTCLOSE) { - throwSyntaxError("too many closing ']'; end-of-file not reached"); + if (!phpFound) { + setMarker("No PHP source code found.", lineNumber, PHPParser.INFO); + } else { + // for (int j=0;j"); + // } + phpParse(null, 1); + // PHPString temp; + // for(int j=0;j TT_KEYWORD && token != TT_list) { String keyword = identifier; if (token == TT_include || token == TT_include_once) { @@ -724,7 +1002,9 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' character after 'include' or 'include_once' expected."); + if (!phpEnd) { + throwSyntaxError("';' character after 'include' or 'include_once' expected."); + } } return; } else if (token == TT_require || token == TT_require_once) { @@ -734,7 +1014,9 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' character after 'require' or 'require_once' expected."); + if (!phpEnd) { + throwSyntaxError("';' character after 'require' or 'require_once' expected."); + } } return; } else if (token == TT_if) { @@ -822,6 +1104,45 @@ public class PHPParser extends PHPKeywords { } whileStatement(); return; + } else if (token == TT_do) { + getNextToken(); + if (token == TT_LISTOPEN) { + getNextToken(); + } else { + throwSyntaxError("'{' expected after 'do' keyword."); + } + if (token != TT_LISTCLOSE) { + statementList(); + } + if (token == TT_LISTCLOSE) { + getNextToken(); + } else { + throwSyntaxError("'}' expected after 'do' keyword."); + } + if (token == TT_while) { + getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected after 'while' keyword."); + } + expression(); + if (token == TT_ARGCLOSE) { + getNextToken(); + } else { + throwSyntaxError("')' expected after 'while' condition."); + } + } else { + throwSyntaxError("'while' expected after 'do' keyword."); + } + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + if (!phpEnd) { + throwSyntaxError("';' expected after do-while statement."); + } + } + return; } else if (token == TT_foreach) { getNextToken(); if (token == TT_ARGOPEN) { @@ -856,7 +1177,9 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after 'continue', 'break' or 'return'."); + if (!phpEnd) { + throwSyntaxError("';' expected after 'continue', 'break' or 'return'."); + } } return; @@ -866,17 +1189,20 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after 'echo' statement."); + if (!phpEnd) { + throwSyntaxError("';' expected after 'echo' statement."); + } } return; - } else if (token == TT_print) { getNextToken(); expression(); if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after 'print' statement."); + if (!phpEnd) { + throwSyntaxError("';' expected after 'print' statement."); + } } return; @@ -886,7 +1212,9 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after 'global' or 'static' statement."); + if (!phpEnd) { + throwSyntaxError("';' expected after 'global' or 'static' statement."); + } } return; @@ -906,21 +1234,25 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after 'unset' statement."); + if (!phpEnd) { + throwSyntaxError("';' expected after 'unset' statement."); + } } return; - } else if (token == TT_exit || token == TT_die) { - getNextToken(); - if (token != TT_SEMICOLON) { - exitStatus(); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'exit' or 'die' statement."); - } - return; + // } else if (token == TT_exit || token == TT_die) { + // getNextToken(); + // if (token != TT_SEMICOLON) { + // exitStatus(); + // } + // if (token == TT_SEMICOLON) { + // getNextToken(); + // } else { + // if (!phpEnd) { + // throwSyntaxError("';' expected after 'exit' or 'die' statement."); + // } + // } + // return; } else if (token == TT_define) { getNextToken(); @@ -944,19 +1276,26 @@ public class PHPParser extends PHPKeywords { if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after 'define' statement."); + if (!phpEnd) { + throwSyntaxError("';' expected after 'define' statement."); + } } return; } else if (token == TT_function) { getNextToken(); functionDefinition(); return; + } else if (token == TT_class) { + getNextToken(); + classDeclarator(); + classBody(); + return; } else { throwSyntaxError("Unexpected keyword '" + keyword + "'"); } } else if (token == TT_LISTOPEN) { - // compundStatement + // compoundStatement getNextToken(); if (token != TT_LISTCLOSE) { statementList(); @@ -975,13 +1314,93 @@ public class PHPParser extends PHPKeywords { getNextToken(); return; } else { - throwSyntaxError("';' expected after expression."); + if (!phpEnd) { + throwSyntaxError("';' expected after expression."); + } } } } - public void functionDefinition() { + public void classDeclarator() { + //identifier + //identifier 'extends' identifier + if (token == TT_IDENTIFIER) { + getNextToken(); + if (token == TT_extends) { + getNextToken(); + if (token == TT_IDENTIFIER) { + getNextToken(); + } else { + throwSyntaxError("Class name expected after keyword 'extends'."); + } + } + } else { + throwSyntaxError("Class name expected after keyword 'class'."); + } + } + + public void classBody() throws CoreException { + //'{' [class-element-list] '}' + if (token == TT_LISTOPEN) { + getNextToken(); + if (token != TT_LISTCLOSE) { + classElementList(); + } + if (token == TT_LISTCLOSE) { + getNextToken(); + } else { + throwSyntaxError("'}' expected at end of class body."); + } + } else { + throwSyntaxError("'{' expected at start of class body."); + } + } + + public void classElementList() throws CoreException { + do { + classElement(); + } while (token == TT_function || token == TT_var); + } + + public void classElement() throws CoreException { + //class-property + //function-definition + if (token == TT_function) { + getNextToken(); + functionDefinition(); + } else if (token == TT_var) { + getNextToken(); + classProperty(); + } else { + throwSyntaxError("'function' or 'var' expected."); + } + } + + public void classProperty() { + //'var' variable ';' + //'var' variable '=' constant ';' + if (token == TT_VARIABLE) { + getNextToken(); + if (token == TT_ASSIGN) { + getNextToken(); + constant(); + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after variable declaration."); + } + } else if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' or '=' expected after variable declaration."); + } + } else { + throwSyntaxError("Variable expected after keyword 'var'."); + } + } + + public void functionDefinition() throws CoreException { functionDeclarator(); compoundStatement(); } @@ -1024,7 +1443,7 @@ public class PHPParser extends PHPKeywords { //variable '=' constant if (token == TT_VARIABLE) { getNextToken(); - if (token == TT_SET) { + if (token == TT_ASSIGN) { getNextToken(); constant(); } @@ -1032,7 +1451,7 @@ public class PHPParser extends PHPKeywords { } } - public void labeledStatementList() { + public void labeledStatementList() throws CoreException { if (token != TT_case && token != TT_default) { throwSyntaxError("'case' or 'default' expected."); } @@ -1043,6 +1462,10 @@ public class PHPParser extends PHPKeywords { if (token == TT_DDOT) { getNextToken(); statementList(); + } else if (token == TT_SEMICOLON) { + setMarker("':' expected after 'case' keyword found ';'.", rowCount, PHPParser.INFO); + getNextToken(); + statementList(); } else { throwSyntaxError("':' character after 'case' constant expected."); } @@ -1111,7 +1534,7 @@ public class PHPParser extends PHPKeywords { // public void definitionStatement() { // } - public void ifStatement() { + public void ifStatement() throws CoreException { // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';' if (token == TT_DDOT) { getNextToken(); @@ -1168,7 +1591,7 @@ public class PHPParser extends PHPKeywords { } } } - public void elseifStatementList() { + public void elseifStatementList() throws CoreException { do { elseifStatement(); switch (token) { @@ -1195,7 +1618,7 @@ public class PHPParser extends PHPKeywords { } while (true); } - public void elseifStatement() { + public void elseifStatement() throws CoreException { if (token == TT_ARGOPEN) { getNextToken(); expression(); @@ -1211,7 +1634,7 @@ public class PHPParser extends PHPKeywords { } } - public void switchStatement() { + public void switchStatement() throws CoreException { if (token == TT_DDOT) { // ':' [labeled-statement-list] 'endswitch' ';' getNextToken(); @@ -1241,7 +1664,7 @@ public class PHPParser extends PHPKeywords { } } - public void forStatement() { + public void forStatement() throws CoreException { if (token == TT_DDOT) { getNextToken(); statementList(); @@ -1258,7 +1681,7 @@ public class PHPParser extends PHPKeywords { } } - public void whileStatement() { + public void whileStatement() throws CoreException { // ':' statement-list 'endwhile' ';' if (token == TT_DDOT) { getNextToken(); @@ -1276,7 +1699,7 @@ public class PHPParser extends PHPKeywords { } } - public void foreachStatement() { + public void foreachStatement() throws CoreException { if (token == TT_DDOT) { getNextToken(); statementList(); @@ -1335,6 +1758,19 @@ public class PHPParser extends PHPKeywords { String ident; boolean castFlag = false; switch (token) { + case TT_new : + getNextToken(); + expression(); + break; + case TT_null : + getNextToken(); + break; + case TT_false : + getNextToken(); + break; + case TT_true : + getNextToken(); + break; case TT_STRING_CONSTANT : getNextToken(); break; @@ -1423,6 +1859,33 @@ public class PHPParser extends PHPKeywords { throwSyntaxError("'(' expected after 'list' keyword."); } break; + // case TT_exit : + // getNextToken(); + // if (token != TT_SEMICOLON) { + // exitStatus(); + // } + // if (token == TT_SEMICOLON) { + // getNextToken(); + // } else { + // if (!phpEnd) { + // throwSyntaxError("';' expected after 'exit' expression."); + // } + // } + // break; + // case TT_die : + // getNextToken(); + // if (token != TT_SEMICOLON) { + // exitStatus(); + // } + // if (token == TT_SEMICOLON) { + // getNextToken(); + // } else { + // if (!phpEnd) { + // throwSyntaxError("';' expected after 'die' expression."); + // } + // } + // break; + // case TT_array : // getNextToken(); // if (token == TT_ARGOPEN) { @@ -1456,12 +1919,31 @@ public class PHPParser extends PHPKeywords { getNextToken(); break; case TT_REF : // -> + getNextToken(); switch (token) { case TT_VARIABLE : + ident = identifier; getNextToken(); + // if (token == TT_ARGOPEN) { + // getNextToken(); + // expressionList(); + // if (token != TT_ARGCLOSE) { + // throwSyntaxError(") expected after variable '" + ident + "'."); + // } + // getNextToken(); + // } break; case TT_IDENTIFIER : + ident = identifier; getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + expressionList(); + if (token != TT_ARGCLOSE) { + throwSyntaxError(") expected after identifier '" + ident + "'."); + } + getNextToken(); + } break; case TT_LISTOPEN : getNextToken(); @@ -1474,6 +1956,7 @@ public class PHPParser extends PHPKeywords { default : throwSyntaxError("Syntax error after '->' token."); } + break; case TT_INCREMENT : getNextToken(); break; @@ -1559,7 +2042,7 @@ public class PHPParser extends PHPKeywords { public void assignExpression() { castExpression(); - if (token == TT_SET) { // = + if (token == TT_ASSIGN) { // = getNextToken(); logicalinclusiveorExpression(); } else if (token == TT_DOTASSIGN) { // .= @@ -1568,6 +2051,36 @@ public class PHPParser extends PHPKeywords { } else if (token == TT_FOREACH) { // => getNextToken(); logicalinclusiveorExpression(); + } else if (token == TT_ADDTO) { // += + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_SUBTRACTFROM) { // -= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_TIMESBY) { // *= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_DIVIDEBY) { // *= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_MODASSIGN) { // %= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_ANDASSIGN) { // &= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_POWASSIGN) { // ^= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_LSHIFTASSIGN) { // <<= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_RSHIFTASSIGN) { // >>= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_TILDEASSIGN) { // ~= + getNextToken(); + logicalinclusiveorExpression(); } } @@ -1641,9 +2154,23 @@ public class PHPParser extends PHPKeywords { } while (true); } + public void ternaryExpression() { + equalityExpression(); + if (token == TT_QUESTIONMARK) { + getNextToken(); + expression(); + if (token == TT_DDOT) { + getNextToken(); + expression(); + } else { + throwSyntaxError("':' expected in ternary operator '? :'."); + } + } + } + public void andExpression() { do { - equalityExpression(); + ternaryExpression(); if (token != TT_AMPERSAND) { return; } @@ -1754,6 +2281,41 @@ public class PHPParser extends PHPKeywords { public void constant() { switch (token) { + case TT_ADD : + getNextToken(); + switch (token) { + case TT_DOUBLE_NUMBER : + getNextToken(); + break; + case TT_INT_NUMBER : + getNextToken(); + break; + default : + throwSyntaxError("Constant expected after '+' presign."); + } + break; + case TT_SUBTRACT : + getNextToken(); + switch (token) { + case TT_DOUBLE_NUMBER : + getNextToken(); + break; + case TT_INT_NUMBER : + getNextToken(); + break; + default : + throwSyntaxError("Constant expected after '-' presign."); + } + break; + case TT_null : + getNextToken(); + break; + case TT_false : + getNextToken(); + break; + case TT_true : + getNextToken(); + break; case TT_STRING_CONSTANT : getNextToken(); break;