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 bb3d533..e69a928 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -29,22 +29,19 @@ import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.jface.preference.IPreferenceStore; import java.util.Hashtable; +import java.util.ArrayList; +import java.util.Enumeration; import java.io.StringReader; import java.io.*; import java.text.MessageFormat; import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; -import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren; -import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration; -import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration; -import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration; -import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration; +import net.sourceforge.phpdt.internal.compiler.parser.*; /** * A new php parser. - * This php parser is inspired by the Java 1.2 grammar example + * This php parser is inspired by the Java 1.2 grammar example * given with JavaCC. You can get JavaCC at http://www.webgain.com * You can test the parser with the PHPParserTestCase2.java * @author Matthieu Casanova @@ -61,6 +58,8 @@ public final class PHPParser extends PHPParserSuperclass { private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ PHPOutlineInfo outlineInfo; + private static PHPFunctionDeclaration currentFunction; + /** The error level of the current ParseException. */ private static int errorLevel = ERROR; /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */ @@ -101,8 +100,6 @@ public final class PHPParser extends PHPParserSuperclass { phpFile(); } catch (FileNotFoundException e) { e.printStackTrace(); //To change body of catch statement use Options | File Templates. - } catch (ParseException e) { - e.printStackTrace(); //To change body of catch statement use Options | File Templates. } } @@ -295,6 +292,7 @@ PARSER_END(PHPParser) "> : DEFAULT } +/* Skip any character if we are not in php mode */ SKIP : { < ~[] > @@ -302,7 +300,6 @@ PARSER_END(PHPParser) /* WHITE SPACE */ - SKIP : { " " @@ -313,7 +310,6 @@ PARSER_END(PHPParser) } /* COMMENTS */ - SPECIAL_TOKEN : { "//" : IN_SINGLE_LINE_COMMENT @@ -364,6 +360,7 @@ MORE : | | | +| } /* LANGUAGE CONSTRUCT */ @@ -382,10 +379,6 @@ MORE : | "> } - TOKEN : -{ - -} /* RESERVED WORDS AND LITERALS */ TOKEN : @@ -408,6 +401,7 @@ MORE : | | | +| | | | @@ -415,7 +409,6 @@ MORE : } /* TYPES */ - TOKEN : { @@ -436,7 +429,6 @@ MORE : } /* LITERALS */ - TOKEN : { < INTEGER_LITERAL: @@ -464,9 +456,10 @@ MORE : | < STRING_1: "\"" ( - ~["\""] + ~["\""] | ~["{"] | "\\\"" + | "{" ~["\""] "}" )* "\"" > @@ -562,6 +555,7 @@ MORE : | | +| | | | @@ -602,18 +596,26 @@ void phpFile() : (PhpBlock())* } catch (TokenMgrError e) { + PHPeclipsePlugin.log(e); + errorStart = SimpleCharStream.getPosition(); + errorEnd = errorStart + 1; errorMessage = e.getMessage(); errorLevel = ERROR; throw generateParseException(); } } +/** + * A php block is a + * or + * or + */ void PhpBlock() : { final int start = jj_input_stream.getPosition(); } { - Expression() [ ] + phpEchoBlock() | [ | @@ -640,6 +642,12 @@ void PhpBlock() : } } +void phpEchoBlock() : +{} +{ + Expression() [ ] +} + void Php() : {} { @@ -660,8 +668,8 @@ void ClassDeclaration() : } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } [ @@ -715,6 +723,9 @@ void ClassBody() : } } +/** + * A class can contain only methods and fields. + */ void ClassBodyDeclaration() : {} { @@ -723,6 +734,9 @@ void ClassBodyDeclaration() : FieldDeclaration() } +/** + * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;. + */ void FieldDeclaration() : { PHPVarDeclaration variableDeclaration; @@ -745,7 +759,7 @@ void FieldDeclaration() : try { } catch (ParseException e) { - errorMessage = "';' expected after variable declaration"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -755,8 +769,7 @@ void FieldDeclaration() : PHPVarDeclaration VariableDeclarator() : { - final String varName; - final String varValue; + final String varName, varValue; final int pos = jj_input_stream.getPosition(); } { @@ -765,7 +778,7 @@ PHPVarDeclaration VariableDeclarator() : try { varValue = VariableInitializer() - {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);} + {return new PHPVarDeclaration(currentSegment,varName.substring(1),pos,varValue);} } catch (ParseException e) { errorMessage = "Literal expression expected in variable initializer"; errorLevel = ERROR; @@ -808,6 +821,12 @@ String Variable(): token = [ expr = Expression() ] { if (expr == null) { + if (currentFunction != null) { + PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1)); + if (var != null) { + var.getVariable().setUsed(true); + } + } return token.image; } return token + "{" + expr + "}"; @@ -829,16 +848,38 @@ final Token token; token = [ expr = Expression() ] { if (expr == null) { + if (currentFunction != null) { + PHPVarDeclaration var = currentFunction.getParameter(token.image); + if (var != null) { + var.getVariable().setUsed(true); + } + } return token.image; } return token + "{" + expr + "}"; } | expr = VariableName() - {return "$" + expr;} + { + if (currentFunction != null) { + PHPVarDeclaration var = currentFunction.getParameter(expr); + if (var != null) { + var.getVariable().setUsed(true); + } + } + return "$" + expr; + } | token = - {return token.image + expr;} + { + if (currentFunction != null) { + PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1)); + if (var != null) { + var.getVariable().setUsed(true); + } + } + return token.image + expr; + } /*| pas besoin ? token = [expr = VariableName()] { @@ -894,7 +935,9 @@ final StringBuffer buff = new StringBuffer("("); {buff.append(expr);} ( LOOKAHEAD(2) expr = ArrayVariable() {buff.append(",").append(expr);} - )* ] + )* + ] + [ {buff.append(",");}] { buff.append(")"); @@ -902,12 +945,17 @@ final StringBuffer buff = new StringBuffer("("); } } +/** + * A Method Declaration. + * function MetodDeclarator() Block() + */ void MethodDeclaration() : { final PHPFunctionDeclaration functionDeclaration; + Token functionToken; } { - + functionToken = try { functionDeclaration = MethodDeclarator() } catch (ParseException e) { @@ -925,9 +973,27 @@ void MethodDeclaration() : currentSegment.add(functionDeclaration); currentSegment = functionDeclaration; } + currentFunction = functionDeclaration; } Block() { + Hashtable parameters = currentFunction.getParameters(); + Enumeration vars = parameters.elements(); + while (vars.hasMoreElements()) { + PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement(); + if (!o.getVariable().isUsed()) { + try { + setMarker(fileToParse, + "Parameter "+o.getVariable().getName()+" is never used in function", + functionToken.beginLine, + WARNING, + "Line " + token.beginLine); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + } + } + } + currentFunction = null; if (currentSegment != null) { currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); } @@ -935,48 +1001,54 @@ void MethodDeclaration() : } /** - * A MethodDeclarator contains [&] IDENTIFIER(parameters ...). + * A MethodDeclarator. + * [&] IDENTIFIER(parameters ...). * @return a function description for the outline */ PHPFunctionDeclaration MethodDeclarator() : { final Token identifier; final StringBuffer methodDeclaration = new StringBuffer(); - final String formalParameters; + final Hashtable formalParameters; final int pos = jj_input_stream.getPosition(); } { [ {methodDeclaration.append("&");} ] identifier = - {methodDeclaration.append(identifier);} - formalParameters = FormalParameters() + formalParameters = FormalParameters() { - methodDeclaration.append(formalParameters); - return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos); + methodDeclaration.append(identifier); + return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos,formalParameters); } } -String FormalParameters() : +/** + * FormalParameters follows method identifier. + * (FormalParameter()) + */ +Hashtable FormalParameters() : { String expr; final StringBuffer buff = new StringBuffer("("); + PHPVarDeclaration var; + final Hashtable parameters = new Hashtable(); } { try { } catch (ParseException e) { - errorMessage = "Formal parameter expected after function identifier"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; throw e; } - [ expr = FormalParameter() - {buff.append(expr);} - ( - expr = FormalParameter() - {buff.append(",").append(expr);} - )* + [ var = FormalParameter() + {parameters.put(var.getVariable().getName(),var);} + ( + var = FormalParameter() + {parameters.put(var.getVariable().getName(),var);} + )* ] try { @@ -987,22 +1059,25 @@ String FormalParameters() : errorEnd = jj_input_stream.getPosition() + 1; throw e; } - { - buff.append(")"); - return buff.toString(); - } + {return parameters;} } -String FormalParameter() : +/** + * A formal parameter. + * $varname[=value] (,$varname[=value]) + */ +PHPVarDeclaration FormalParameter() : { final PHPVarDeclaration variableDeclaration; - final StringBuffer buff = new StringBuffer(); + Token token = null; } { - [ {buff.append("&");}] variableDeclaration = VariableDeclarator() + [token = ] variableDeclaration = VariableDeclarator() { - buff.append(variableDeclaration.toString()); - return buff.toString(); + if (token != null) { + variableDeclaration.getVariable().setPrefix("@"); + } + return variableDeclaration; } } @@ -1057,6 +1132,9 @@ String Expression() : expr2 = Expression() {return expr + assignOperator + expr2;} } catch (ParseException e) { + if (errorMessage != null) { + throw e; + } errorMessage = "expression expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; @@ -1330,11 +1408,11 @@ String MultiplicativeExpression() : } {buff.append(expr);} ( - ( operator = | operator = | operator = ) expr = UnaryExpression() - { - buff.append(operator.image); - buff.append(expr); - } + ( operator = | operator = | operator = ) expr = UnaryExpression() + { + buff.append(operator.image); + buff.append(expr); + } )* {return buff.toString();} } @@ -1372,10 +1450,7 @@ String UnaryExpressionNoPrefix() : return token.image + expr; } | - expr = PreIncrementExpression() - {return expr;} -| - expr = PreDecrementExpression() + expr = PreIncDecExpression() {return expr;} | expr = UnaryExpressionNotPlusMinus() @@ -1383,22 +1458,14 @@ String UnaryExpressionNoPrefix() : } -String PreIncrementExpression() : -{ -final String expr; -} -{ - expr = PrimaryExpression() - {return "++"+expr;} -} - -String PreDecrementExpression() : +String PreIncDecExpression() : { final String expr; +final Token token; } { - expr = PrimaryExpression() - {return "--"+expr;} + (token = | token = ) expr = PrimaryExpression() + {return token.image + expr;} } String UnaryExpressionNotPlusMinus() : @@ -1409,7 +1476,7 @@ String UnaryExpressionNotPlusMinus() : expr = UnaryExpression() {return "!" + expr;} | - LOOKAHEAD( Type() ) + LOOKAHEAD( (Type() | ) ) expr = CastExpression() {return expr;} | @@ -1437,7 +1504,7 @@ String CastExpression() : final String type, expr; } { - type = Type() expr = UnaryExpression() + (type = Type() | {type = "array";}) expr = UnaryExpression() {return "(" + type + ")" + expr;} } @@ -1563,8 +1630,8 @@ String VariableSuffix() : throw e; } {return "->" + expr;} -| - [ expr = Expression() ] +| + [ expr = Expression() | expr = Type() ] //Not good try { } catch (ParseException e) { @@ -1600,8 +1667,8 @@ String Literal() : expr = BooleanLiteral() {return expr;} | - expr = NullLiteral() - {return expr;} + + {return "null";} } String BooleanLiteral() : @@ -1614,13 +1681,6 @@ String BooleanLiteral() : {return "false";} } -String NullLiteral() : -{} -{ - - {return "null";} -} - String Arguments() : { String expr = null; @@ -1678,13 +1738,15 @@ void StatementNoBreak() : LOOKAHEAD(2) Expression() try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; - throw e; + if (e.currentToken.next.kind != 4) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; + errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; + throw e; + } } | LOOKAHEAD(2) @@ -1698,7 +1760,7 @@ void StatementNoBreak() : try { } catch (ParseException e) { - errorMessage = "';' expected after expression"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -1741,74 +1803,36 @@ void Statement() : BreakStatement() } +void htmlBlock() : +{} +{ + (phpEchoBlock())* ( | ) +} + +/** + * An include statement. It's "include" an expression; + */ void IncludeStatement() : { final String expr; + final Token token; final int pos = jj_input_stream.getPosition(); } { - - expr = Expression() - { - if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr)); - } - } - try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) - } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; - throw e; - } -| - + ( token = + | token = + | token = + | token = ) expr = Expression() { if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr)); + currentSegment.add(new PHPReqIncDeclaration(currentSegment, token.image,pos,expr)); } } try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) - } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; - throw e; - } -| - - expr = Expression() - { - if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr)); - } - } - try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) - } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; - throw e; - } -| - - expr = Expression() - { - if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr)); - } - } - try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -1849,7 +1873,7 @@ String ListExpression() : expr = VariableDeclaratorId() {buff.append(expr);} ] - [ + ( try { } catch (ParseException e) { @@ -1861,7 +1885,7 @@ String ListExpression() : } expr = VariableDeclaratorId() {buff.append(",").append(expr);} - ] + )* {buff.append(")");} try { @@ -1876,29 +1900,47 @@ String ListExpression() : {return buff.toString();} } +/** + * An echo statement is like this : echo anyexpression (, otherexpression)* + */ void EchoStatement() : {} { Expression() ( Expression())* try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected after 'echo' statement"; - errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; - throw e; + if (e.currentToken.next.kind != 4) { + errorMessage = "';' expected after 'echo' statement"; + errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; + throw e; + } } } void GlobalStatement() : -{} { - VariableDeclaratorId() ( VariableDeclaratorId())* + final int pos = jj_input_stream.getPosition(); + String expr; +} +{ + + expr = VariableDeclaratorId() + {if (currentSegment != null) { + currentSegment.add(new PHPGlobalDeclaration(currentSegment, "global",pos,expr)); + }} + ( + expr = VariableDeclaratorId() + {if (currentSegment != null) { + currentSegment.add(new PHPGlobalDeclaration(currentSegment, "global",pos,expr)); + }} + )* try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -1911,9 +1953,9 @@ void StaticStatement() : { VariableDeclarator() ( VariableDeclarator())* try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -1939,7 +1981,7 @@ void Block() : errorEnd = jj_input_stream.getPosition() + 1; throw e; } - ( BlockStatement() )* + ( BlockStatement() | htmlBlock())* try { } catch (ParseException e) { @@ -1995,9 +2037,7 @@ void EmptyStatement() : void StatementExpression() : {} { - PreIncrementExpression() -| - PreDecrementExpression() + PreIncDecExpression() | PrimaryExpression() [ @@ -2011,8 +2051,7 @@ void StatementExpression() : void SwitchStatement() : { - Token breakToken = null; - int line; + final int pos = jj_input_stream.getPosition(); } { @@ -2035,37 +2074,57 @@ void SwitchStatement() : errorEnd = jj_input_stream.getPosition() + 1; throw e; } - try { + (switchStatementBrace() | switchStatementColon(pos, pos + 6)) +} + +void switchStatementBrace() : +{} +{ + ( switchLabel0() )* + try { + } catch (ParseException e) { - errorMessage = "'{' expected"; + errorMessage = "'}' expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; throw e; } - ( - line = SwitchLabel() - ( BlockStatementNoBreak() )* - [ breakToken = BreakStatement() ] - { - 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); - } - } - )* +} +/** + * A Switch statement with : ... endswitch; + * @param start the begin offset of the switch + * @param end the end offset of the switch + */ +void switchStatementColon(final int start, final int end) : +{} +{ + + {try { + setMarker(fileToParse, + "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;", + start, + end, + INFO, + "Line " + token.beginLine); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + }} + (switchLabel0())* try { - + } catch (ParseException e) { - errorMessage = "'}' expected"; + errorMessage = "'endswitch' expected"; + errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; + throw e; + } + try { + + } catch (ParseException e) { + errorMessage = "';' expected after 'endswitch' keyword"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -2073,6 +2132,30 @@ void SwitchStatement() : } } +void switchLabel0() : +{ + Token breakToken = null; + final int line; +} +{ + line = SwitchLabel() + ( BlockStatementNoBreak() | htmlBlock() )* + [ breakToken = BreakStatement() ] + { + 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); + } + } +} + Token BreakStatement() : { final Token token; @@ -2167,7 +2250,7 @@ void Condition(final String keyword) : void IfStatement0(final int start,final int end) : {} { - (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] + (Statement() | htmlBlock())* (ElseIfStatementColon())* [ElseStatementColon()] {try { setMarker(fileToParse, @@ -2198,19 +2281,35 @@ void IfStatement0(final int start,final int end) : throw e; } | - Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) Statement() ] + (Statement() | htmlBlock()) + ( LOOKAHEAD(1) ElseIfStatement() )* + [ LOOKAHEAD(1) + + try { + Statement() + } catch (ParseException e) { + if (errorMessage != null) { + throw e; + } + errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected"; + errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; + throw e; + } + ] } void ElseIfStatementColon() : {} { - Condition("elseif") (Statement())* + Condition("elseif") (Statement() | htmlBlock())* } void ElseStatementColon() : {} { - (Statement())* + (Statement() | htmlBlock())* } void ElseIfStatement() : @@ -2252,7 +2351,7 @@ void WhileStatement0(final int start, final int end) : throw e; } try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { errorMessage = "';' expected after 'endwhile' keyword"; errorLevel = ERROR; @@ -2269,9 +2368,9 @@ void DoStatement() : { Statement() Condition("while") try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected"; errorLevel = ERROR; errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = jj_input_stream.getPosition() + 1; @@ -2301,7 +2400,7 @@ void ForeachStatement() : errorEnd = jj_input_stream.getPosition() + 1; throw e; } - [ VariableSuffix() ] + ( VariableSuffix() )* try { } catch (ParseException e) { @@ -2414,7 +2513,7 @@ void StatementExpressionList() : void ContinueStatement() : {} { - [ ] + [ Expression() ] try { } catch (ParseException e) {