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 b0bb021..21cdb6f 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -280,7 +280,7 @@ PARSER_END(PHPParser) SPECIAL_TOKEN : { - "//" : IN_SINGLE_LINE_COMMENT + "//" | "#" : IN_SINGLE_LINE_COMMENT | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT | @@ -578,18 +578,19 @@ void PhpBlock() : Expression() [ ] | [ - | - {try { - setMarker(fileToParse, - "You should use ' + {try { + setMarker(fileToParse, + "You should use ' } catch (ParseException e) { @@ -687,7 +688,7 @@ void FieldDeclaration() : PHPVarDeclaration VariableDeclarator() : { final String varName; - String varValue = null; + String varValue; final int pos = jj_input_stream.bufpos; } { @@ -831,7 +832,17 @@ void MethodDeclaration() : final PHPFunctionDeclaration functionDeclaration; } { - functionDeclaration = MethodDeclarator() + + try { + functionDeclaration = MethodDeclarator() + } catch (ParseException e) { + if (errorMessage != null) { + throw e; + } + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected"; + errorLevel = ERROR; + throw e; + } { if (currentSegment != null) { currentSegment.add(functionDeclaration); @@ -1305,7 +1316,14 @@ String UnaryExpressionNotPlusMinus() : expr = Literal() {return expr;} | - expr = Expression() + expr = Expression() + try { + + } catch (ParseException e) { + errorMessage = "')' expected"; + errorLevel = ERROR; + throw e; + } {return "("+expr+")";} } @@ -1414,7 +1432,14 @@ String VariableSuffix() : String expr = null; } { - expr = VariableName() + + try { + expr = VariableName() + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected"; + errorLevel = ERROR; + throw e; + } {return "->" + expr;} | [ expr = Expression() ] @@ -1481,7 +1506,7 @@ String expr = null; try { } catch (ParseException e) { - errorMessage = "')' expected to close the argument list"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list"; errorLevel = ERROR; throw e; } @@ -1516,11 +1541,10 @@ final StringBuffer buff = new StringBuffer(); {return buff.toString();} } -/* - * Statement syntax follows. +/** + * A Statement without break */ - -void Statement() : +void StatementNoBreak() : {} { LOOKAHEAD(2) @@ -1561,8 +1585,6 @@ void Statement() : | ForeachStatement() | - BreakStatement() -| ContinueStatement() | ReturnStatement() @@ -1576,6 +1598,17 @@ void Statement() : GlobalStatement() } +/** + * A Normal statement + */ +void Statement() : +{} +{ + StatementNoBreak() +| + BreakStatement() +} + void IncludeStatement() : { final String expr; @@ -1662,22 +1695,39 @@ String ListExpression() : String expr; } { - + + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected"; + errorLevel = ERROR; + throw e; + } [ expr = VariableDeclaratorId() {buff.append(expr);} ] - - {buff.append(",");} [ + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected"; + errorLevel = ERROR; + throw e; + } expr = VariableDeclaratorId() - {buff.append(expr);} + {buff.append(",").append(expr);} ] - - { - buff.append(")"); - return buff.toString(); + {buff.append(")");} + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected"; + errorLevel = ERROR; + throw e; } + [ expr = Expression() {buff.append("(").append(expr);}] + {return buff.toString();} } void EchoStatement() : @@ -1736,7 +1786,13 @@ void Block() : throw e; } ( BlockStatement() )* - + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected"; + errorLevel = ERROR; + throw e; + } } void BlockStatement() : @@ -1749,6 +1805,19 @@ void BlockStatement() : MethodDeclaration() } +/** + * A Block statement that will not contain any 'break' + */ +void BlockStatementNoBreak() : +{} +{ + StatementNoBreak() +| + ClassDeclaration() +| + MethodDeclaration() +} + void LocalVariableDeclaration() : {} { @@ -1785,19 +1854,101 @@ void StatementExpression() : } void SwitchStatement() : -{} { - Expression() - ( SwitchLabel() ( BlockStatement() )* )* - + Token breakToken = null; + int line; +} +{ + + try { + + } catch (ParseException e) { + errorMessage = "'(' expected after 'switch'"; + errorLevel = ERROR; + throw e; + } + Expression() + try { + + } catch (ParseException e) { + errorMessage = "')' expected"; + errorLevel = ERROR; + throw e; + } + try { + + } catch (ParseException e) { + errorMessage = "'{' expected"; + errorLevel = ERROR; + throw e; + } + ( + line = SwitchLabel() + ( BlockStatementNoBreak() )* + [ breakToken = + try { + + } catch (ParseException e) { + errorMessage = "';' expected after 'break' keyword"; + errorLevel = ERROR; + throw e; + } + ] + { + try { + if (breakToken == null) { + setMarker(fileToParse, + "You should use put a 'break' at the end of your statement", + line, + INFO, + "Line " + line); + } + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + } + } + )* + try { + + } catch (ParseException e) { + errorMessage = "'}' expected"; + errorLevel = ERROR; + throw e; + } } -void SwitchLabel() : -{} +int SwitchLabel() : { - Expression() + final Token token; +} +{ + token = + try { + Expression() + } catch (ParseException e) { + if (errorMessage != null) throw e; + errorMessage = "expression expected after 'case' keyword"; + errorLevel = ERROR; + throw e; + } + try { + + } catch (ParseException e) { + errorMessage = "':' expected after case expression"; + errorLevel = ERROR; + throw e; + } + {return token.beginLine;} | - <_DEFAULT> + token = <_DEFAULT> + try { + + } catch (ParseException e) { + errorMessage = "':' expected after 'default' keyword"; + errorLevel = ERROR; + throw e; + } + {return token.beginLine;} } void IfStatement() : @@ -1830,8 +1981,7 @@ void Condition(final String keyword) : } void IfStatement0(final int start,final int end) : -{ -} +{} { (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] @@ -1855,7 +2005,7 @@ void IfStatement0(final int start,final int end) : try { } catch (ParseException e) { - errorMessage = "';' expected 'endif' keyword"; + errorMessage = "';' expected after 'endif' keyword"; errorLevel = ERROR; throw e; } @@ -2000,7 +2150,7 @@ final int pos = jj_input_stream.bufpos; errorLevel = ERROR; throw e; } - [ ForInit() ] [ Expression() ] [ ForUpdate() ] + [ ForInit() ] [ Expression() ] [ StatementExpressionList() ] ( Statement() | @@ -2027,7 +2177,7 @@ final int pos = jj_input_stream.bufpos; try { } catch (ParseException e) { - errorMessage = "';' expected 'endfor' keyword"; + errorMessage = "';' expected after 'endfor' keyword"; errorLevel = ERROR; throw e; } @@ -2049,26 +2199,41 @@ void StatementExpressionList() : StatementExpression() ( StatementExpression() )* } -void ForUpdate() : -{} -{ - StatementExpressionList() -} - void BreakStatement() : {} { - [ ] + [ ] + try { + + } catch (ParseException e) { + errorMessage = "';' expected after 'break' statement"; + errorLevel = ERROR; + throw e; + } } void ContinueStatement() : {} { - [ ] + [ ] + try { + + } catch (ParseException e) { + errorMessage = "';' expected after 'continue' statement"; + errorLevel = ERROR; + throw e; + } } void ReturnStatement() : {} { - [ Expression() ] + [ Expression() ] + try { + + } catch (ParseException e) { + errorMessage = "';' expected after 'return' statement"; + errorLevel = ERROR; + throw e; + } } \ No newline at end of file