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 34ee7b7..9327af8 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -344,6 +344,10 @@ MORE : | "> } + TOKEN : +{ + +} /* RESERVED WORDS AND LITERALS */ TOKEN : @@ -574,18 +578,19 @@ void PhpBlock() : Expression() [ ] | [ - | - {try { - setMarker(fileToParse, - "You should use ' + {try { + setMarker(fileToParse, + "You should use ' } catch (ParseException e) { @@ -683,7 +688,7 @@ void FieldDeclaration() : PHPVarDeclaration VariableDeclarator() : { final String varName; - String varValue = null; + String varValue; final int pos = jj_input_stream.bufpos; } { @@ -947,6 +952,9 @@ String Expression() : expr = PrintExpression() {return expr;} | + expr = ListExpression() + {return expr;} +| expr = ConditionalExpression() [ assignOperator = AssignmentOperator() @@ -1298,7 +1306,14 @@ String UnaryExpressionNotPlusMinus() : expr = Literal() {return expr;} | - expr = Expression() + expr = Expression() + try { + + } catch (ParseException e) { + errorMessage = "')' expected"; + errorLevel = ERROR; + throw e; + } {return "("+expr+")";} } @@ -1407,7 +1422,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() ] @@ -1474,7 +1496,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; } @@ -1509,11 +1531,10 @@ final StringBuffer buff = new StringBuffer(); {return buff.toString();} } -/* - * Statement syntax follows. +/** + * A Statement without break */ - -void Statement() : +void StatementNoBreak() : {} { LOOKAHEAD(2) @@ -1554,8 +1575,6 @@ void Statement() : | ForeachStatement() | - BreakStatement() -| ContinueStatement() | ReturnStatement() @@ -1569,6 +1588,17 @@ void Statement() : GlobalStatement() } +/** + * A Normal statement + */ +void Statement() : +{} +{ + StatementNoBreak() +| + BreakStatement() +} + void IncludeStatement() : { final String expr; @@ -1649,6 +1679,47 @@ String PrintExpression() : } } +String ListExpression() : +{ + final StringBuffer buff = new StringBuffer("list("); + String expr; +} +{ + + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected"; + errorLevel = ERROR; + throw e; + } + [ + expr = VariableDeclaratorId() + {buff.append(expr);} + ] + [ + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected"; + errorLevel = ERROR; + throw e; + } + expr = VariableDeclaratorId() + {buff.append(",").append(expr);} + ] + {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() : {} { @@ -1705,7 +1776,13 @@ void Block() : throw e; } ( BlockStatement() )* - + try { + + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected"; + errorLevel = ERROR; + throw e; + } } void BlockStatement() : @@ -1718,6 +1795,19 @@ void BlockStatement() : MethodDeclaration() } +/** + * A Block statement that will not contain any 'break' + */ +void BlockStatementNoBreak() : +{} +{ + StatementNoBreak() +| + ClassDeclaration() +| + MethodDeclaration() +} + void LocalVariableDeclaration() : {} { @@ -1754,19 +1844,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() : +{ + final Token token; +} { - Expression() + 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() : @@ -1799,8 +1971,7 @@ void Condition(final String keyword) : } void IfStatement0(final int start,final int end) : -{ -} +{} { (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] @@ -1824,7 +1995,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; } @@ -1969,7 +2140,7 @@ final int pos = jj_input_stream.bufpos; errorLevel = ERROR; throw e; } - [ ForInit() ] [ Expression() ] [ ForUpdate() ] + [ ForInit() ] [ Expression() ] [ StatementExpressionList() ] ( Statement() | @@ -1996,7 +2167,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; } @@ -2018,26 +2189,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