X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index 861d2c6..2a86a45 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -127,7 +127,12 @@ public class PHPParser extends PHPParserSuperclass { */ private static void setMarker(ParseException e) { try { - setMarker(fileToParse, errorMessage, jj_input_stream.tokenBegin,jj_input_stream.tokenBegin+e.currentToken.image.length(), errorLevel); + setMarker(fileToParse, + errorMessage, + jj_input_stream.tokenBegin, + jj_input_stream.tokenBegin + e.currentToken.image.length(), + errorLevel, + "Line " + e.currentToken.beginLine); } catch (CoreException e2) { PHPeclipsePlugin.log(e2); } @@ -197,7 +202,11 @@ public class PHPParser extends PHPParserSuperclass { } public void parse(String s) throws CoreException { - ReInit(new StringReader(s)); + StringReader stream = new StringReader(s); + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } + ReInit(stream); try { parse(); } catch (ParseException e) { @@ -272,10 +281,14 @@ PARSER_END(PHPParser) "/*" : IN_MULTI_LINE_COMMENT } - -SPECIAL_TOKEN : + SPECIAL_TOKEN : { - " > : PHPPARSING + : PHPPARSING +} + + TOKEN : +{ + " > : DEFAULT } @@ -347,6 +360,10 @@ MORE : | < TRUE: "true" > | < WHILE: "while" > | < ENDWHILE : "endwhile" > +| +| +| +| } /* TYPES */ @@ -441,7 +458,7 @@ MORE : > | < #SPECIAL: - "_" + "_" | ["\u007f"-"\u00ff"] > } @@ -476,6 +493,7 @@ MORE : | =" > | " > | | | @@ -502,7 +520,9 @@ MORE : | >=" > -| >>=" > +| +| +| (token = | token = ) + {return "+" + token.image;} +| expr = ArrayDeclarator() {return expr;} +| + token = + {return token.image;} } String ArrayVariable() : @@ -748,12 +796,16 @@ void MethodDeclaration() : { functionDeclaration = MethodDeclarator() { - currentSegment.add(functionDeclaration); - currentSegment = functionDeclaration; + if (currentSegment != null) { + currentSegment.add(functionDeclaration); + currentSegment = functionDeclaration; + } } Block() { - currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + if (currentSegment != null) { + currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + } } } @@ -847,6 +899,9 @@ String Type() : | {return "integer";} +| + + {return "object";} } String Expression() : @@ -867,7 +922,7 @@ String Expression() : } catch (ParseException e) { errorMessage = "expression expected"; errorLevel = ERROR; - throw generateParseException(); + throw e; } ] { @@ -898,8 +953,6 @@ String AssignmentOperator() : {return "<<=";} | {return ">>=";} -| -{return ">>>=";} | {return "&=";} | @@ -908,6 +961,8 @@ String AssignmentOperator() : {return "|=";} | {return ".=";} +| +{return "~=";} } String ConditionalExpression() : @@ -1078,7 +1133,13 @@ String EqualityExpression() : expr = RelationalExpression() {buff.append(expr);} ( - ( operator = | operator = ) expr2 = RelationalExpression() + ( operator = + | operator = + | operator = + | operator = + | operator = + ) + expr2 = RelationalExpression() { buff.append(operator.image); buff.append(expr2); @@ -1165,15 +1226,34 @@ String MultiplicativeExpression() : {return buff.toString();} } +/** + * An unary expression starting with @, & or nothing + */ String UnaryExpression() : { String expr; Token token; + final StringBuffer buff = new StringBuffer(); } { - expr = UnaryExpression() - {return "@" + expr;} + token = expr = UnaryExpressionNoPrefix() + { + if (token == null) { + return expr; + } + return token.image + expr; + } | + ( {buff.append("@");})* expr = UnaryExpressionNoPrefix() + {return buff.append(expr).toString();} +} + +String UnaryExpressionNoPrefix() : +{ + String expr; + Token token; +} +{ ( token = | token = ) expr = UnaryExpression() { return token.image + expr; @@ -1189,6 +1269,7 @@ String UnaryExpression() : {return expr;} } + String PreIncrementExpression() : { String expr; @@ -1296,12 +1377,9 @@ String PrimaryPrefix() : token = {return token.image;} | - [token = ] expr = ClassIdentifier() + expr = ClassIdentifier() { - if (token == null) { - return "new " + expr; - } - return "new &" + expr; + return "new " + expr; } | expr = VariableDeclaratorId() @@ -1347,7 +1425,7 @@ String VariableSuffix() : } catch (ParseException e) { errorMessage = "']' expected"; errorLevel = ERROR; - throw generateParseException(); + throw e; } { if(expr == null) { @@ -1369,14 +1447,8 @@ String Literal() : token = {return token.image;} | - try { - token = + token = {return token.image;} - } catch (TokenMgrError e) { - errorMessage = "unterminated string"; - errorLevel = ERROR; - throw generateParseException(); - } | expr = BooleanLiteral() {return expr;} @@ -1489,6 +1561,8 @@ void Statement() : | ForStatement() | + ForeachStatement() +| BreakStatement() | ContinueStatement() @@ -1512,7 +1586,11 @@ void IncludeStatement() : { expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1523,7 +1601,11 @@ void IncludeStatement() : | expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1534,7 +1616,11 @@ void IncludeStatement() : | expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1545,7 +1631,11 @@ void IncludeStatement() : | expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1690,7 +1780,7 @@ void IfStatement() : */ {} { - Condition("if") Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) Statement() ] + Condition("if") IfStatement0() } void Condition(String keyword) : @@ -1713,6 +1803,39 @@ void Condition(String keyword) : } } +void IfStatement0() : +{} +{ + (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] + try { + + } catch (ParseException e) { + errorMessage = "';' expected 'endif' keyword"; + errorLevel = ERROR; + throw e; + } +| + Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) Statement() ] +} + +void ElseIfStatementColon() : +{} +{ + Condition("elseif") (Statement())* +} + +void ElseStatement() : +{} +{ + Statement() +} + +void ElseStatementColon() : +{} +{ + (Statement())* +} + void ElseIfStatement() : {} { @@ -1732,7 +1855,7 @@ void WhileStatement0() : try { ( | "?>") } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "';' expected after 'endwhile' keyword"; errorLevel = ERROR; throw e; } @@ -1753,10 +1876,28 @@ void DoStatement() : } } +void ForeachStatement() : +{} +{ + Variable() Variable() [ Expression() ] Statement() +} + void ForStatement() : {} { - [ ForInit() ] [ Expression() ] [ ForUpdate() ] Statement() + [ ForInit() ] [ Expression() ] [ ForUpdate() ] + ( + Statement() + | + (Statement())* + try { + + } catch (ParseException e) { + errorMessage = "';' expected 'endfor' keyword"; + errorLevel = ERROR; + throw e; + } + ) } void ForInit() :