X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index b49b15a..35b3173 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -29,21 +29,19 @@ import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.jface.preference.IPreferenceStore; import java.util.Hashtable; +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.*; +import net.sourceforge.phpdt.internal.compiler.ast.*; /** * 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 @@ -53,12 +51,15 @@ public final class PHPParser extends PHPParserSuperclass { /** The file that is parsed. */ private static IFile fileToParse; - /** The current segment */ + /** The current segment. */ private static PHPSegmentWithChildren currentSegment; private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$ private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ - PHPOutlineInfo outlineInfo; + static PHPOutlineInfo outlineInfo; + + private static PHPFunctionDeclaration currentFunction; + private static boolean assigning; /** The error level of the current ParseException. */ private static int errorLevel = ERROR; @@ -68,13 +69,20 @@ public final class PHPParser extends PHPParserSuperclass { private static int errorStart = -1; private static int errorEnd = -1; - public PHPParser() { - } + //ast stack + private final static int AstStackIncrement = 100; + /** The stack of node. */ + private static AstNode[] astStack; + /** The cursor in expression stack. */ + private static int expressionPtr; public final void setFileToParse(final IFile fileToParse) { this.fileToParse = fileToParse; } + public PHPParser() { + } + public PHPParser(final IFile fileToParse) { this(new StringReader("")); this.fileToParse = fileToParse; @@ -87,15 +95,31 @@ public final class PHPParser extends PHPParserSuperclass { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(new StringReader(strEval)); + astStack = new AstNode[AstStackIncrement]; phpTest(); } + public static final void htmlParserTester(final File fileName) throws CoreException, ParseException { + try { + final Reader stream = new FileReader(fileName); + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } + ReInit(stream); + astStack = new AstNode[AstStackIncrement]; + phpFile(); + } catch (FileNotFoundException e) { + e.printStackTrace(); //To change body of catch statement use Options | File Templates. + } + } + public static final void htmlParserTester(final String strEval) throws CoreException, ParseException { final StringReader stream = new StringReader(strEval); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(stream); + astStack = new AstNode[AstStackIncrement]; phpFile(); } @@ -107,6 +131,7 @@ public final class PHPParser extends PHPParserSuperclass { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(stream); + astStack = new AstNode[AstStackIncrement]; try { parse(); } catch (ParseException e) { @@ -124,6 +149,8 @@ public final class PHPParser extends PHPParserSuperclass { if (errorMessage == null) { PHPeclipsePlugin.log(e); errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it"; + errorStart = jj_input_stream.getPosition(); + errorEnd = errorStart + 1; } setMarker(e); errorMessage = null; @@ -229,6 +256,7 @@ public final class PHPParser extends PHPParserSuperclass { jj_input_stream = new SimpleCharStream(stream, 1, 1); } ReInit(stream); + astStack = new AstNode[AstStackIncrement]; try { parse(); } catch (ParseException e) { @@ -258,7 +286,7 @@ public final class PHPParser extends PHPParserSuperclass { } } - public static final void parse() throws ParseException { + private static final void parse() throws ParseException { phpFile(); } } @@ -277,6 +305,7 @@ PARSER_END(PHPParser) "> : DEFAULT } +/* Skip any character if we are not in php mode */ SKIP : { < ~[] > @@ -284,7 +313,6 @@ PARSER_END(PHPParser) /* WHITE SPACE */ - SKIP : { " " @@ -295,7 +323,6 @@ PARSER_END(PHPParser) } /* COMMENTS */ - SPECIAL_TOKEN : { "//" : IN_SINGLE_LINE_COMMENT @@ -346,6 +373,7 @@ MORE : | | | +| } /* LANGUAGE CONSTRUCT */ @@ -364,10 +392,6 @@ MORE : | "> } - TOKEN : -{ - -} /* RESERVED WORDS AND LITERALS */ TOKEN : @@ -390,6 +414,7 @@ MORE : | | | +| | | | @@ -397,7 +422,6 @@ MORE : } /* TYPES */ - TOKEN : { @@ -418,7 +442,6 @@ MORE : } /* LITERALS */ - TOKEN : { < INTEGER_LITERAL: @@ -446,18 +469,18 @@ MORE : | < STRING_1: "\"" ( - ~["\""] - | - "\\\"" + ~["\"","{","}"] + | "\\\"" + | "\\" + | "{" ~["\""] "}" )* "\"" > | < STRING_2: "'" ( - ~["'"] - | - "\\'" + ~["'"] + | "\\'" )* "'" @@ -466,8 +489,7 @@ MORE : "`" ( ~["`"] - | - "\\`" + | "\\`" )* "`" > @@ -544,6 +566,7 @@ MORE : | | +| | | | @@ -584,18 +607,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.bufpos; + final int start = jj_input_stream.getPosition(); } { - Expression() [ ] + phpEchoBlock() | [ | @@ -603,7 +634,7 @@ void PhpBlock() : setMarker(fileToParse, "You should use '' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } +void phpEchoBlock() : +{} +{ + Expression() [ ] +} + void Php() : {} { @@ -635,11 +674,13 @@ void ClassDeclaration() : { try { - {pos = jj_input_stream.bufpos;} + {pos = jj_input_stream.getPosition();} className = } 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; throw e; } [ @@ -649,6 +690,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; throw e; } ] @@ -673,28 +716,37 @@ void ClassBody() : try { } catch (ParseException e) { - errorMessage = "'{' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } ( ClassBodyDeclaration() )* try { } catch (ParseException e) { - errorMessage = "'var', 'function' or '}' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } +/** + * A class can contain only methods and fields. + */ void ClassBodyDeclaration() : {} { MethodDeclaration() -| - FieldDeclaration() +| FieldDeclaration() } +/** + * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;. + */ void FieldDeclaration() : { PHPVarDeclaration variableDeclaration; @@ -702,6 +754,7 @@ void FieldDeclaration() : { variableDeclaration = VariableDeclarator() { + outlineInfo.addVariable(variableDeclaration.getVariable().getName()); if (currentSegment != null) { currentSegment.add(variableDeclaration); } @@ -717,17 +770,18 @@ 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; throw e; } } PHPVarDeclaration VariableDeclarator() : { - final String varName; - String varValue; - final int pos = jj_input_stream.bufpos; + final String varName, varValue; + final int pos = jj_input_stream.getPosition(); } { varName = VariableDeclaratorId() @@ -739,6 +793,8 @@ PHPVarDeclaration VariableDeclarator() : } catch (ParseException e) { errorMessage = "Literal expression expected in variable initializer"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } ] @@ -752,15 +808,16 @@ String VariableDeclaratorId() : } { try { - expr = Variable() - {buff.append(expr);} - ( LOOKAHEAD(2) expr = VariableSuffix() - {buff.append(expr);} + expr = Variable() {buff.append(expr);} + ( LOOKAHEAD(2) + expr = VariableSuffix() {buff.append(expr);} )* {return buff.toString();} } catch (ParseException e) { errorMessage = "'$' expected for variable identifier"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } @@ -773,14 +830,20 @@ String Variable(): { token = [ expr = Expression() ] { - if (expr == null) { - return token.image; + if (expr == null && !assigning) { + if (currentFunction != null) { + PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1)); + if (var != null) { + var.getVariable().setUsed(true); + } + } + return token.image.substring(1); } return token + "{" + expr + "}"; } | expr = VariableName() - {return "$" + expr;} + {return expr;} } String VariableName(): @@ -795,21 +858,46 @@ 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 = + { + 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()] { if (expr == null) { return token.image; } return token.image + expr; - } + }*/ } String VariableInitializer() : @@ -857,7 +945,9 @@ final StringBuffer buff = new StringBuffer("("); {buff.append(expr);} ( LOOKAHEAD(2) expr = ArrayVariable() {buff.append(",").append(expr);} - )* ] + )* + ] + [ {buff.append(",");}] { buff.append(")"); @@ -865,20 +955,28 @@ final StringBuffer buff = new StringBuffer("("); } } +/** + * A Method Declaration. + * function MetodDeclarator() Block() + */ void MethodDeclaration() : { final PHPFunctionDeclaration functionDeclaration; + Token functionToken; } { - + functionToken = try { functionDeclaration = MethodDeclarator() + {outlineInfo.addVariable(functionDeclaration.getName());} } catch (ParseException e) { if (errorMessage != null) { throw e; } errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } { @@ -886,108 +984,126 @@ 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(); } } } +/** + * 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 int pos = jj_input_stream.bufpos; + 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; - jj_consume_token(token.kind); + 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 { } 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; } - { - 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().setReference(true); + } + return variableDeclaration; } } String Type() : {} { - - {return "string";} -| - - {return "bool";} -| - - {return "boolean";} -| - - {return "real";} -| - - {return "double";} -| - - {return "float";} -| - - {return "int";} -| - - {return "integer";} -| - - {return "object";} + {return "string";} +| {return "bool";} +| {return "boolean";} +| {return "real";} +| {return "double";} +| {return "float";} +| {return "int";} +| {return "integer";} +| {return "object";} } String Expression() : @@ -997,56 +1113,57 @@ String Expression() : final String expr2; } { - expr = PrintExpression() - {return expr;} -| - expr = ListExpression() - {return expr;} -| - expr = ConditionalExpression() - [ - assignOperator = AssignmentOperator() + expr = PrintExpression() {return expr;} +| expr = ListExpression() {return expr;} +| LOOKAHEAD(varAssignation()) + expr = varAssignation() {return expr;} +| expr = ConditionalExpression() {return expr;} +} + +/** + * A Variable assignation. + * varName (an assign operator) any expression + */ +String varAssignation() : +{ + String varName,assignOperator,expr2; + PHPVarDeclaration variable; + final int pos = SimpleCharStream.getPosition(); +} +{ + varName = VariableDeclaratorId() + assignOperator = AssignmentOperator() try { 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; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } - ] - {return expr;} + {return varName + assignOperator + expr2;} } String AssignmentOperator() : {} { - -{return "=";} -| -{return "*=";} -| -{return "/=";} -| -{return "%=";} -| -{return "+=";} -| -{return "-=";} -| -{return "<<=";} -| -{return ">>=";} -| -{return "&=";} -| -{return "|=";} -| -{return "|=";} -| -{return ".=";} -| -{return "~=";} + {return "=";} +| {return "*=";} +| {return "/=";} +| {return "%=";} +| {return "+=";} +| {return "-=";} +| {return "<<=";} +| {return ">>=";} +| {return "&=";} +| {return "|=";} +| {return "|=";} +| {return ".=";} +| {return "~=";} } String ConditionalExpression() : @@ -1198,6 +1315,8 @@ String EqualityExpression() : } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected after '"+operator.image+"'"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } { @@ -1268,14 +1387,22 @@ String MultiplicativeExpression() : Token operator; final StringBuffer buff = new StringBuffer();} { - expr = UnaryExpression() + try { + expr = UnaryExpression() + } catch (ParseException e) { + errorMessage = "unexpected token '"+e.currentToken.next.image+"'"; + errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; + throw e; + } {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();} } @@ -1297,8 +1424,8 @@ String UnaryExpression() : } return token.image + expr; } -| - ( {buff.append("@");})* expr = UnaryExpressionNoPrefix() +| ( {buff.append("@");})* + expr = UnaryExpressionNoPrefix() {return buff.append(expr).toString();} } @@ -1313,10 +1440,7 @@ String UnaryExpressionNoPrefix() : return token.image + expr; } | - expr = PreIncrementExpression() - {return expr;} -| - expr = PreDecrementExpression() + expr = PreIncDecExpression() {return expr;} | expr = UnaryExpressionNotPlusMinus() @@ -1324,22 +1448,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() : @@ -1347,25 +1463,19 @@ String UnaryExpressionNotPlusMinus() : final String expr; } { - expr = UnaryExpression() - {return "!" + expr;} -| - LOOKAHEAD( Type() ) - expr = CastExpression() - {return expr;} -| - expr = PostfixExpression() - {return expr;} -| - expr = Literal() - {return expr;} -| - expr = Expression() + expr = UnaryExpression() {return "!" + expr;} +| LOOKAHEAD( (Type() | ) ) + expr = CastExpression() {return expr;} +| expr = PostfixExpression() {return expr;} +| expr = Literal() {return expr;} +| expr = Expression() try { } 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; } {return "("+expr+")";} @@ -1376,7 +1486,7 @@ String CastExpression() : final String type, expr; } { - type = Type() expr = UnaryExpression() + (type = Type() | {type = "array";}) expr = UnaryExpression() {return "(" + type + ")" + expr;} } @@ -1434,16 +1544,24 @@ String PrimaryPrefix() : final Token token; } { - token = - {return token.image;} -| + token = {return token.image;} +| expr = ClassIdentifier() {return "new " + expr;} +| expr = VariableDeclaratorId() {return expr;} +} + +String classInstantiation() : +{ + String expr; + final StringBuffer buff = new StringBuffer("new "); +} +{ expr = ClassIdentifier() - { - return "new " + expr; - } -| - expr = VariableDeclaratorId() - {return expr;} + {buff.append(expr);} + [ + expr = PrimaryExpression() + {buff.append(expr);} + ] + {return buff.toString();} } String ClassIdentifier(): @@ -1452,11 +1570,8 @@ String ClassIdentifier(): final Token token; } { - token = - {return token.image;} -| - expr = VariableDeclaratorId() - {return expr;} + token = {return token.image;} +| expr = VariableDeclaratorId() {return expr;} } String PrimarySuffix() : @@ -1464,11 +1579,8 @@ String PrimarySuffix() : final String expr; } { - expr = Arguments() - {return expr;} -| - expr = VariableSuffix() - {return expr;} + expr = Arguments() {return expr;} +| expr = VariableSuffix() {return expr;} } String VariableSuffix() : @@ -1482,16 +1594,20 @@ String VariableSuffix() : } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } {return "->" + expr;} -| - [ expr = Expression() ] +| + [ expr = Expression() | expr = Type() ] //Not good try { } 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; } { @@ -1508,37 +1624,18 @@ String Literal() : final Token token; } { - token = - {return token.image;} -| - token = - {return token.image;} -| - token = - {return token.image;} -| - expr = BooleanLiteral() - {return expr;} -| - expr = NullLiteral() - {return expr;} + token = {return token.image;} +| token = {return token.image;} +| token = {return token.image;} +| expr = BooleanLiteral() {return expr;} +| {return "null";} } String BooleanLiteral() : {} { - - {return "true";} -| - - {return "false";} -} - -String NullLiteral() : -{} -{ - - {return "null";} + {return "true";} +| {return "false";} } String Arguments() : @@ -1552,6 +1649,8 @@ String expr = null; } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } { @@ -1574,19 +1673,19 @@ final StringBuffer buff = new StringBuffer(); try { expr = Expression() } catch (ParseException e) { - errorMessage = "expression expected after a comma in argument list"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } - { - buff.append(",").append(expr); - } + {buff.append(",").append(expr);} )* {return buff.toString();} } /** - * A Statement without break + * A Statement without break. */ void StatementNoBreak() : {} @@ -1594,143 +1693,120 @@ void StatementNoBreak() : LOOKAHEAD(2) Expression() try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - 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) +| LOOKAHEAD(2) LabeledStatement() -| - Block() -| - EmptyStatement() -| - StatementExpression() +| Block() +| EmptyStatement() +| StatementExpression() 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; throw e; } -| - SwitchStatement() -| - IfStatement() -| - WhileStatement() -| - DoStatement() -| - ForStatement() -| - ForeachStatement() -| - ContinueStatement() -| - ReturnStatement() -| - EchoStatement() -| - [] IncludeStatement() -| - StaticStatement() -| - GlobalStatement() +| SwitchStatement() +| IfStatement() +| WhileStatement() +| DoStatement() +| ForStatement() +| ForeachStatement() +| ContinueStatement() +| ReturnStatement() +| EchoStatement() +| [] IncludeStatement() +| StaticStatement() +| GlobalStatement() } /** - * A Normal statement + * A Normal statement. */ void Statement() : {} { StatementNoBreak() -| - BreakStatement() +| BreakStatement() } -void IncludeStatement() : -{ - final String expr; - final int pos = jj_input_stream.bufpos; -} +/** + * An html block inside a php syntax. + */ +void htmlBlock() : +{} { - - 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; - throw e; - } -| - - expr = Expression() - { - if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr)); - } - } + (phpEchoBlock())* try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + ( | ) } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "End of file unexpected, ' - expr = Expression() - { - if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr)); +} + +/** + * An include statement. It's "include" an expression; + */ +void IncludeStatement() : +{ + final String expr; + final Token token; + final int pos = jj_input_stream.getPosition(); +} +{ + ( token = + | token = + | token = + | token = ) + try { + expr = Expression() + } catch (ParseException e) { + if (errorMessage != null) { + throw e; + } + errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected"; + errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; + throw e; } - } - try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) - } catch (ParseException e) { - errorMessage = "';' expected"; - errorLevel = ERROR; - throw e; - } -| - - expr = Expression() { if (currentSegment != null) { - currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr)); + currentSegment.add(new PHPReqIncDeclaration(currentSegment, token.image,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; throw e; } } String PrintExpression() : { - final StringBuffer buff = new StringBuffer("print "); final String expr; } { - expr = Expression() - { - buff.append(expr); - return buff.toString(); - } + expr = Expression() {return "print " + expr;} } String ListExpression() : @@ -1745,57 +1821,86 @@ String ListExpression() : } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } [ expr = VariableDeclaratorId() {buff.append(expr);} ] - [ + ( try { } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } expr = VariableDeclaratorId() {buff.append(",").append(expr);} - ] + )* {buff.append(")");} try { } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } [ expr = Expression() {buff.append("(").append(expr);}] {return buff.toString();} } +/** + * An echo statement. + * echo anyexpression (, otherexpression)* + */ void EchoStatement() : {} { Expression() ( Expression())* try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { - errorMessage = "';' expected after 'echo' statement"; - errorLevel = ERROR; - 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; throw e; } } @@ -1805,10 +1910,12 @@ 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; throw e; } } @@ -1827,14 +1934,18 @@ void Block() : } 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; } - ( BlockStatement() )* + ( BlockStatement() | htmlBlock())* try { } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } @@ -1843,10 +1954,8 @@ void BlockStatement() : {} { Statement() -| - ClassDeclaration() -| - MethodDeclaration() +| ClassDeclaration() +| MethodDeclaration() } /** @@ -1856,10 +1965,8 @@ void BlockStatementNoBreak() : {} { StatementNoBreak() -| - ClassDeclaration() -| - MethodDeclaration() +| ClassDeclaration() +| MethodDeclaration() } void LocalVariableDeclaration() : @@ -1883,24 +1990,17 @@ void EmptyStatement() : void StatementExpression() : {} { - PreIncrementExpression() -| - PreDecrementExpression() + PreIncDecExpression() | PrimaryExpression() - [ - - | - - | - AssignmentOperator() Expression() - ] + [ + | + | AssignmentOperator() Expression() ] } void SwitchStatement() : { - Token breakToken = null; - int line; + final int pos = jj_input_stream.getPosition(); } { @@ -1909,50 +2009,113 @@ void SwitchStatement() : } catch (ParseException e) { errorMessage = "'(' expected after 'switch'"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } - Expression() try { - + Expression() } catch (ParseException e) { - errorMessage = "')' expected"; + if (errorMessage != null) { + throw e; + } + errorMessage = "expression 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"; + 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); - } - } - )* + (switchStatementBrace() | switchStatementColon(pos, pos + 6)) +} + +void switchStatementBrace() : +{} +{ + + ( switchLabel0() )* try { } 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; + } +} +/** + * 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 = "'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; throw e; } } +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; @@ -1964,6 +2127,8 @@ Token BreakStatement() : } catch (ParseException e) { errorMessage = "';' expected after 'break' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } {return token;} @@ -1981,6 +2146,8 @@ int SwitchLabel() : if (errorMessage != null) throw e; errorMessage = "expression expected after 'case' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { @@ -1988,6 +2155,8 @@ int SwitchLabel() : } catch (ParseException e) { errorMessage = "':' expected after case expression"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } {return token.beginLine;} @@ -1998,6 +2167,8 @@ int SwitchLabel() : } catch (ParseException e) { errorMessage = "':' expected after 'default' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } {return token.beginLine;} @@ -2006,7 +2177,7 @@ int SwitchLabel() : void IfStatement() : { final Token token; - final int pos = jj_input_stream.bufpos; + final int pos = jj_input_stream.getPosition(); } { token = Condition("if") IfStatement0(pos,pos+token.image.length()) @@ -2020,7 +2191,9 @@ void Condition(final String keyword) : } catch (ParseException e) { errorMessage = "'(' expected after " + keyword + " keyword"; errorLevel = ERROR; - throw e; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length(); + errorEnd = errorStart +1; + processParseException(e); } Expression() try { @@ -2028,6 +2201,8 @@ void Condition(final String keyword) : } catch (ParseException e) { errorMessage = "')' expected after " + keyword + " keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } @@ -2035,7 +2210,7 @@ void Condition(final String keyword) : void IfStatement0(final int start,final int end) : {} { - (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] + (Statement() | htmlBlock())* (ElseIfStatementColon())* [ElseStatementColon()] {try { setMarker(fileToParse, @@ -2052,6 +2227,8 @@ void IfStatement0(final int start,final int end) : } catch (ParseException e) { errorMessage = "'endif' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { @@ -2059,22 +2236,40 @@ void IfStatement0(final int start,final int end) : } catch (ParseException e) { errorMessage = "';' expected after 'endif' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; 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() : @@ -2086,7 +2281,7 @@ void ElseIfStatement() : void WhileStatement() : { final Token token; - final int pos = jj_input_stream.bufpos; + final int pos = jj_input_stream.getPosition(); } { token = Condition("while") WhileStatement0(pos,pos + token.image.length()) @@ -2111,13 +2306,17 @@ void WhileStatement0(final int start, final int end) : } catch (ParseException e) { errorMessage = "'endwhile' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { - ( | {PHPParserTokenManager.SwitchTo(PHPParserTokenManager.DEFAULT);}) + } catch (ParseException e) { errorMessage = "';' expected after 'endwhile' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } | @@ -2129,10 +2328,12 @@ 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; throw e; } } @@ -2146,6 +2347,8 @@ void ForeachStatement() : } catch (ParseException e) { errorMessage = "'(' expected after 'foreach' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { @@ -2153,14 +2356,18 @@ void ForeachStatement() : } catch (ParseException e) { errorMessage = "variable expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } - [ VariableSuffix() ] + ( VariableSuffix() )* try { } catch (ParseException e) { errorMessage = "'as' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { @@ -2168,6 +2375,8 @@ void ForeachStatement() : } catch (ParseException e) { errorMessage = "variable expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } [ Expression() ] @@ -2176,6 +2385,8 @@ void ForeachStatement() : } catch (ParseException e) { errorMessage = "')' expected after 'foreach' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { @@ -2184,6 +2395,8 @@ void ForeachStatement() : if (errorMessage != null) throw e; errorMessage = "statement expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } @@ -2191,7 +2404,7 @@ void ForeachStatement() : void ForStatement() : { final Token token; -final int pos = jj_input_stream.bufpos; +final int pos = jj_input_stream.getPosition(); } { token = @@ -2200,6 +2413,8 @@ final int pos = jj_input_stream.bufpos; } catch (ParseException e) { errorMessage = "'(' expected after 'for' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } [ ForInit() ] [ Expression() ] [ StatementExpressionList() ] @@ -2224,6 +2439,8 @@ final int pos = jj_input_stream.bufpos; } catch (ParseException e) { errorMessage = "'endfor' expected"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } try { @@ -2231,6 +2448,8 @@ final int pos = jj_input_stream.bufpos; } catch (ParseException e) { errorMessage = "';' expected after 'endfor' keyword"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } ) @@ -2254,12 +2473,14 @@ void StatementExpressionList() : void ContinueStatement() : {} { - [ ] + [ Expression() ] try { } catch (ParseException e) { errorMessage = "';' expected after 'continue' statement"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } @@ -2273,6 +2494,8 @@ void ReturnStatement() : } catch (ParseException e) { errorMessage = "';' expected after 'return' statement"; errorLevel = ERROR; + errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = jj_input_stream.getPosition() + 1; throw e; } } \ No newline at end of file