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 823b11e..2b4a1e9 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -60,9 +60,6 @@ public final class PHPParser extends PHPParserSuperclass { private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$ static PHPOutlineInfo outlineInfo; - public static MethodDeclaration currentFunction; - private static boolean assigning; - /** 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 */ @@ -71,6 +68,8 @@ public final class PHPParser extends PHPParserSuperclass { private static int errorStart = -1; private static int errorEnd = -1; private static PHPDocument phpDocument; + + private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'}; /** * The point where html starts. * It will be used by the token manager to create HTMLCode objects @@ -122,44 +121,10 @@ public final class PHPParser extends PHPParserSuperclass { } } - public static final void phpParserTester(final String strEval) throws CoreException, ParseException { - PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING); - final StringReader stream = new StringReader(strEval); - if (jj_input_stream == null) { - jj_input_stream = new SimpleCharStream(stream, 1, 1); - } - ReInit(new StringReader(strEval)); - init(); - 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); - init(); - 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); - init(); - phpFile(); - } - public final PHPOutlineInfo parseInfo(final Object parent, final String s) { - currentSegment = new PHPDocument(parent); - outlineInfo = new PHPOutlineInfo(parent); + phpDocument = new PHPDocument(parent,"_root".toCharArray()); + currentSegment = phpDocument; + outlineInfo = new PHPOutlineInfo(parent, currentSegment); final StringReader stream = new StringReader(s); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); @@ -168,7 +133,11 @@ public final class PHPParser extends PHPParserSuperclass { init(); try { parse(); - //PHPeclipsePlugin.log(1,phpDocument.toString()); + phpDocument.nodes = new AstNode[nodes.length]; + System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length); + if (PHPeclipsePlugin.DEBUG) { + PHPeclipsePlugin.log(1,phpDocument.toString()); + } } catch (ParseException e) { processParseException(e); } @@ -184,7 +153,7 @@ 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(); + errorStart = SimpleCharStream.getPosition(); errorEnd = errorStart + 1; } setMarker(e); @@ -200,8 +169,8 @@ public final class PHPParser extends PHPParserSuperclass { if (errorStart == -1) { setMarker(fileToParse, errorMessage, - jj_input_stream.tokenBegin, - jj_input_stream.tokenBegin + e.currentToken.image.length(), + SimpleCharStream.tokenBegin, + SimpleCharStream.tokenBegin + e.currentToken.image.length(), errorLevel, "Line " + e.currentToken.beginLine); } else { @@ -329,7 +298,7 @@ public final class PHPParser extends PHPParserSuperclass { if (currentPosition == htmlStart) { return; } - final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray(); + final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray(); pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition)); } @@ -518,39 +487,38 @@ MORE : /* LITERALS */ TOKEN : { - < INTEGER_LITERAL: + (["l","L"])? | (["l","L"])? | (["l","L"])? > | - < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > + <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > | - < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > + <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > | - < #OCTAL_LITERAL: "0" (["0"-"7"])* > + <#OCTAL_LITERAL: "0" (["0"-"7"])* > | - < FLOATING_POINT_LITERAL: + )? (["f","F","d","D"])? | "." (["0"-"9"])+ ()? (["f","F","d","D"])? | (["0"-"9"])+ (["f","F","d","D"])? | (["0"-"9"])+ ()? ["f","F","d","D"] > | - < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > + <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | - < STRING_LITERAL: ( | | )> -| < STRING_1: + | | )> +| -| < STRING_2: +| -| < STRING_3: +| > } -void phpTest() : -{} -{ - Php() - - {PHPParser.createNewHTMLCode();} -} - void phpFile() : {} { @@ -672,18 +632,20 @@ void phpFile() : */ void PhpBlock() : { - final int start = jj_input_stream.getPosition(); + final int start = SimpleCharStream.getPosition(); + final PHPEchoBlock phpEchoBlock; } { - phpEchoBlock() + phpEchoBlock = phpEchoBlock() + {pushOnAstNodes(phpEchoBlock);} | - [ + [ | {try { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } } @@ -728,41 +690,46 @@ ClassDeclaration ClassDeclaration() : final Token className; Token superclassName = null; final int pos; + char[] classNameImage = SYNTAX_ERROR_CHAR; + char[] superclassNameImage = null; } { + {pos = SimpleCharStream.getPosition();} try { - {pos = jj_input_stream.getPosition();} className = + {classNameImage = className.image.toCharArray();} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } [ try { superclassName = + {superclassNameImage = superclassName.image.toCharArray();} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); + superclassNameImage = SYNTAX_ERROR_CHAR; } ] { - if (superclassName == null) { + if (superclassNameImage == null) { classDeclaration = new ClassDeclaration(currentSegment, - className.image.toCharArray(), - superclassName.image.toCharArray(), + classNameImage, pos, 0); } else { classDeclaration = new ClassDeclaration(currentSegment, - className.image.toCharArray(), + classNameImage, + superclassNameImage, pos, 0); } @@ -784,8 +751,8 @@ void ClassBody(ClassDeclaration classDeclaration) : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } ( ClassBodyDeclaration(classDeclaration) )* @@ -794,8 +761,8 @@ void ClassBody(ClassDeclaration classDeclaration) : } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -809,8 +776,8 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : FieldDeclaration field; } { - method = MethodDeclaration() {classDeclaration.addMethod(method);} -| field = FieldDeclaration() {classDeclaration.addVariable(field);} + method = MethodDeclaration() {method.setParent(classDeclaration);} +| field = FieldDeclaration() } /** @@ -819,39 +786,43 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : FieldDeclaration FieldDeclaration() : { VariableDeclaration variableDeclaration; + VariableDeclaration[] list; + final ArrayList arrayList = new ArrayList(); + final int pos = SimpleCharStream.getPosition(); } { variableDeclaration = VariableDeclarator() - { - outlineInfo.addVariable(new String(variableDeclaration.name)); - if (currentSegment != null) { - currentSegment.add(variableDeclaration); - } - } - ( - variableDeclaration = VariableDeclarator() - { - if (currentSegment != null) { - currentSegment.add(variableDeclaration); - } - } + {arrayList.add(variableDeclaration); + outlineInfo.addVariable(new String(variableDeclaration.name)); + currentSegment.add(variableDeclaration);} + ( variableDeclaration = VariableDeclarator() + {arrayList.add(variableDeclaration); + outlineInfo.addVariable(new String(variableDeclaration.name)); + currentSegment.add(variableDeclaration);} )* try { } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } + + {list = new VariableDeclaration[arrayList.size()]; + arrayList.toArray(list); + return new FieldDeclaration(list, + pos, + SimpleCharStream.getPosition(), + currentSegment);} } VariableDeclaration VariableDeclarator() : { - final String varName, varValue; + final String varName; Expression initializer = null; - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); } { varName = VariableDeclaratorId() @@ -862,15 +833,23 @@ VariableDeclaration 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } ] - {return new VariableDeclaration(currentSegment, + { + if (initializer == null) { + return new VariableDeclaration(currentSegment, varName.toCharArray(), - initializer, - pos);} + pos, + SimpleCharStream.getPosition()); + } + return new VariableDeclaration(currentSegment, + varName.toCharArray(), + initializer, + pos); + } } /** @@ -899,8 +878,8 @@ String VariableDeclaratorId() : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -915,20 +894,24 @@ String Variable(): { token = [ expression = Expression() ] { - if (expression == null && !assigning) { + if (expression == null) { return token.image.substring(1); } buff = new StringBuffer(token.image); - buff.append('{'); + buff.append("{"); buff.append(expression.toStringExpression()); - buff.append('}'); + buff.append("}"); return buff.toString(); } | expr = VariableName() - {return expr;} + {return "$" + expr;} } +/** + * A Variable name (without the $) + * @return a variable name String + */ String VariableName(): { final StringBuffer buff; @@ -938,9 +921,9 @@ String VariableName(): } { expression = Expression() - {buff = new StringBuffer('{'); + {buff = new StringBuffer("{"); buff.append(expression.toStringExpression()); - buff.append('}'); + buff.append("}"); return buff.toString();} | token = [ expression = Expression() ] @@ -949,15 +932,15 @@ String VariableName(): return token.image; } buff = new StringBuffer(token.image); - buff.append('{'); + buff.append("{"); buff.append(expression.toStringExpression()); - buff.append('}'); + buff.append("}"); return buff.toString(); } | expr = VariableName() { - buff = new StringBuffer('$'); + buff = new StringBuffer("$"); buff.append(expr); return buff.toString(); } @@ -998,12 +981,14 @@ Expression VariableInitializer() : ArrayVariableDeclaration ArrayVariable() : { -Expression expr; -Expression expr2 = null; +Expression expr,expr2; } { - expr = Expression() [ expr2 = Expression()] + expr = Expression() + [ expr2 = Expression() {return new ArrayVariableDeclaration(expr,expr2);} + ] + {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());} } ArrayVariableDeclaration[] ArrayInitializer() : @@ -1020,7 +1005,10 @@ ArrayVariableDeclaration[] ArrayInitializer() : ] [ {list.add(null);}] - {return (ArrayVariableDeclaration[]) list.toArray();} + { + ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()]; + list.toArray(vars); + return vars;} } /** @@ -1030,22 +1018,19 @@ ArrayVariableDeclaration[] ArrayInitializer() : MethodDeclaration MethodDeclaration() : { final MethodDeclaration functionDeclaration; - Token functionToken; final Block block; } { - functionToken = + try { functionDeclaration = MethodDeclarator() {outlineInfo.addVariable(new String(functionDeclaration.name));} } catch (ParseException e) { - if (errorMessage != null) { - throw 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } { @@ -1053,12 +1038,10 @@ MethodDeclaration MethodDeclaration() : currentSegment.add(functionDeclaration); currentSegment = functionDeclaration; } - currentFunction = functionDeclaration; } block = Block() { functionDeclaration.statements = block.statements; - currentFunction = null; if (currentSegment != null) { currentSegment = (OutlineableWithChildren) currentSegment.getParent(); } @@ -1077,13 +1060,23 @@ MethodDeclaration MethodDeclarator() : Token reference = null; final Hashtable formalParameters; final int pos = SimpleCharStream.getPosition(); + char[] identifierChar = SYNTAX_ERROR_CHAR; } { - [ reference = ] - identifier = + [reference = ] + try { + identifier = + {identifierChar = identifier.image.toCharArray();} + } catch (ParseException e) { + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); + } formalParameters = FormalParameters() {return new MethodDeclaration(currentSegment, - identifier.image.toCharArray(), + identifierChar, formalParameters, reference != null, pos, @@ -1096,8 +1089,6 @@ MethodDeclaration MethodDeclarator() : */ Hashtable FormalParameters() : { - String expr; - final StringBuffer buff = new StringBuffer("("); VariableDeclaration var; final Hashtable parameters = new Hashtable(); } @@ -1107,8 +1098,8 @@ Hashtable FormalParameters() : } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } [ var = FormalParameter() @@ -1123,8 +1114,8 @@ Hashtable FormalParameters() : } catch (ParseException e) { errorMessage = "')' expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return parameters;} @@ -1152,32 +1143,23 @@ ConstantIdentifier Type() : {final int pos;} { {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.STRING, - pos,pos-6);} + return new ConstantIdentifier(Types.STRING,pos,pos-6);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.BOOL, - pos,pos-4);} + return new ConstantIdentifier(Types.BOOL,pos,pos-4);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.BOOLEAN, - pos,pos-7);} + return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.REAL, - pos,pos-4);} + return new ConstantIdentifier(Types.REAL,pos,pos-4);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.DOUBLE, - pos,pos-5);} + return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.FLOAT, - pos,pos-5);} + return new ConstantIdentifier(Types.FLOAT,pos,pos-5);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.INT, - pos,pos-3);} + return new ConstantIdentifier(Types.INT,pos,pos-3);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.INTEGER, - pos,pos-7);} + return new ConstantIdentifier(Types.INTEGER,pos,pos-7);} | {pos = SimpleCharStream.getPosition(); - return new ConstantIdentifier(Types.OBJECT, - pos,pos-6);} + return new ConstantIdentifier(Types.OBJECT,pos,pos-6);} } Expression Expression() : @@ -1214,8 +1196,8 @@ VarAssignation varAssignation() : } errorMessage = "expression expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new VarAssignation(varName.toCharArray(), @@ -1366,8 +1348,8 @@ Expression EqualityExpression() : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } { @@ -1437,13 +1419,11 @@ Expression MultiplicativeExpression() : try { expr = UnaryExpression() } catch (ParseException e) { - if (errorMessage != null) { - throw e; - } + if (errorMessage != null) throw 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } ( @@ -1468,8 +1448,7 @@ Expression UnaryExpression() : expr = UnaryExpressionNoPrefix() {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);} | - expr = AtUnaryExpression() - {return expr;} + expr = AtUnaryExpression() {return expr;} } Expression AtUnaryExpression() : @@ -1537,8 +1516,8 @@ Expression UnaryExpressionNotPlusMinus() : } catch (ParseException e) { errorMessage = "')' expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return expr;} @@ -1580,7 +1559,6 @@ Expression PrimaryExpression() : { final Token identifier; Expression expr; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); } { @@ -1689,8 +1667,8 @@ AbstractSuffixExpression VariableSuffix(Expression prefix) : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new ClassAccess(prefix, @@ -1703,8 +1681,8 @@ AbstractSuffixExpression VariableSuffix(Expression prefix) : } catch (ParseException e) { errorMessage = "']' expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());} @@ -1721,7 +1699,7 @@ Literal Literal() : | token = {pos = SimpleCharStream.getPosition(); return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);} | token = {pos = SimpleCharStream.getPosition(); - return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);} + return new StringLiteral(token.image.toCharArray(),pos-token.image.length());} | {pos = SimpleCharStream.getPosition(); return new TrueLiteral(pos-4,pos);} | {pos = SimpleCharStream.getPosition(); @@ -1732,7 +1710,7 @@ Literal Literal() : FunctionCall Arguments(Expression func) : { -ArgumentDeclaration[] args = null; +Expression[] args = null; } { [ args = ArgumentList() ] @@ -1741,34 +1719,42 @@ ArgumentDeclaration[] args = 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new FunctionCall(func,args,SimpleCharStream.getPosition());} } -ArgumentDeclaration[] ArgumentList() : +/** + * An argument list is a list of arguments separated by comma : + * argumentDeclaration() (, argumentDeclaration)* + * @return an array of arguments + */ +Expression[] ArgumentList() : { -Expression expr; +Expression arg; final ArrayList list = new ArrayList(); } { - expr = Expression() - {list.add(expr);} + arg = Expression() + {list.add(arg);} ( try { - expr = Expression() - {list.add(expr);} + arg = Expression() + {list.add(arg);} } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } )* - {return (ArgumentDeclaration[]) list.toArray();} + { + Expression[] arguments = new Expression[list.size()]; + list.toArray(arguments); + return arguments;} } /** @@ -1785,11 +1771,11 @@ Statement StatementNoBreak() : try { } catch (ParseException e) { - if (e.currentToken.next.kind != 4) { + if (e.currentToken.next.kind != PHPParserConstants.PHPEND) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -1804,8 +1790,8 @@ Statement StatementNoBreak() : } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return statement;} @@ -1855,15 +1841,16 @@ HTMLBlock htmlBlock() : } catch (ParseException e) { errorMessage = "End of file unexpected, ' expression = Expression() - {return new ListExpression((String[]) list.toArray(),expression,pos,SimpleCharStream.getPosition());}] - {return new ListExpression((String[]) list.toArray(),null,pos,SimpleCharStream.getPosition());} + { + String[] strings = new String[list.size()]; + list.toArray(strings); + return new ListExpression(strings, + expression, + pos, + SimpleCharStream.getPosition());} + ] + { + String[] strings = new String[list.size()]; + list.toArray(strings); + return new ListExpression(strings,pos,SimpleCharStream.getPosition());} } /** @@ -1990,21 +1986,23 @@ EchoStatement EchoStatement() : )* try { - {return new EchoStatement((Expression[]) expressions.toArray(),pos);} } catch (ParseException 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } + {Expression[] exprs = new Expression[expressions.size()]; + expressions.toArray(exprs); + return new EchoStatement(exprs,pos);} } GlobalStatement GlobalStatement() : { - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); String expr; ArrayList vars = new ArrayList(); GlobalStatement global; @@ -2019,17 +2017,20 @@ GlobalStatement GlobalStatement() : )* try { - {global = new GlobalStatement(currentSegment, - (String[]) vars.toArray(), - pos, - SimpleCharStream.getPosition()); + { + String[] strings = new String[vars.size()]; + vars.toArray(strings); + global = new GlobalStatement(currentSegment, + strings, + pos, + SimpleCharStream.getPosition()); currentSegment.add(global); return global;} } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2045,14 +2046,17 @@ StaticStatement StaticStatement() : ( expr = VariableDeclarator() {vars.add(new String(expr.name));})* try { - {return new StaticStatement((String[])vars.toArray(), + { + String[] strings = new String[vars.size()]; + vars.toArray(strings); + return new StaticStatement(strings, pos, SimpleCharStream.getPosition());} } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2078,6 +2082,8 @@ LabeledStatement LabeledStatement() : Block Block() : { final int pos = SimpleCharStream.getPosition(); + final ArrayList list = new ArrayList(); + Statement statement; } { try { @@ -2085,20 +2091,25 @@ Block 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } - ( BlockStatement() | htmlBlock())* + ( statement = BlockStatement() {list.add(statement);} + | statement = htmlBlock() {list.add(statement);})* 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } + { + Statement[] statements = new Statement[list.size()]; + list.toArray(statements); + return new Block(statements,pos,SimpleCharStream.getPosition());} } Statement BlockStatement() : @@ -2106,9 +2117,19 @@ Statement BlockStatement() : final Statement statement; } { - statement = Statement() {return statement;} + try { + statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement); + return statement;} + } catch (ParseException e) { + errorMessage = "statement expected"; + errorLevel = ERROR; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + throw e; + } | statement = ClassDeclaration() {return statement;} -| statement = MethodDeclaration() {return statement;} +| statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement); + return statement;} } /** @@ -2133,18 +2154,32 @@ VariableDeclaration[] LocalVariableDeclaration() : var = LocalVariableDeclarator() {list.add(var);} ( var = LocalVariableDeclarator() {list.add(var);})* - {return (VariableDeclaration[]) list.toArray();} + { + VariableDeclaration[] vars = new VariableDeclaration[list.size()]; + list.toArray(vars); + return vars;} } VariableDeclaration LocalVariableDeclarator() : { final String varName; - Expression init = null; + Expression initializer = null; final int pos = SimpleCharStream.getPosition(); } { - varName = VariableDeclaratorId() [ init = Expression() ] - {return new VariableDeclaration(varName.toCharArray(),init,pos);} + varName = VariableDeclaratorId() [ initializer = Expression() ] + { + if (initializer == null) { + return new VariableDeclaration(currentSegment, + varName.toCharArray(), + pos, + SimpleCharStream.getPosition()); + } + return new VariableDeclaration(currentSegment, + varName.toCharArray(), + initializer, + pos); + } } EmptyStatement EmptyStatement() : @@ -2159,19 +2194,23 @@ EmptyStatement EmptyStatement() : Statement StatementExpression() : { - Expression expr; + Expression expr,expr2; + int operator; } { expr = PreIncDecExpression() {return expr;} | expr = PrimaryExpression() - [ {expr = new PostfixedUnaryExpression(expr, + [ {return new PostfixedUnaryExpression(expr, OperatorIds.PLUS_PLUS, SimpleCharStream.getPosition());} - | {expr = new PostfixedUnaryExpression(expr, + | {return new PostfixedUnaryExpression(expr, OperatorIds.MINUS_MINUS, SimpleCharStream.getPosition());} - | AssignmentOperator() Expression() ] + | operator = AssignmentOperator() expr2 = Expression() + {return new BinaryExpression(expr,expr2,operator);} + ] + {return expr;} } SwitchStatement SwitchStatement() : @@ -2187,8 +2226,8 @@ SwitchStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2199,8 +2238,8 @@ SwitchStatement SwitchStatement() : } errorMessage = "expression expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2208,8 +2247,8 @@ SwitchStatement SwitchStatement() : } catch (ParseException e) { errorMessage = "')' expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6)) @@ -2226,12 +2265,15 @@ AbstractCase[] switchStatementBrace() : ( cas = switchLabel0() {cases.add(cas);})* try { - {return (AbstractCase[]) cases.toArray();} + { + AbstractCase[] abcase = new AbstractCase[cases.size()]; + cases.toArray(abcase); + return abcase;} } catch (ParseException e) { errorMessage = "'}' expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2263,18 +2305,21 @@ AbstractCase[] switchStatementColon(final int start, final int end) : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { - {return (AbstractCase[]) cases.toArray();} + { + AbstractCase[] abcase = new AbstractCase[cases.size()]; + cases.toArray(abcase); + return abcase;} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2291,10 +2336,13 @@ AbstractCase switchLabel0() : ( statement = BlockStatementNoBreak() {stmts.add(statement);} | statement = htmlBlock() {stmts.add(statement);})* [ statement = BreakStatement() {stmts.add(statement);}] - {if (expr == null) {//it's a default - return new DefaultCase((Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition()); + { + Statement[] stmtsArray = new Statement[stmts.size()]; + stmts.toArray(stmtsArray); + if (expr == null) {//it's a default + return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition()); } - return new Case(expr,(Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());} + return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());} } /** @@ -2305,7 +2353,6 @@ AbstractCase switchLabel0() : */ Expression SwitchLabel() : { - final Token token; final Expression expr; } { @@ -2316,8 +2363,8 @@ Expression 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2326,8 +2373,8 @@ Expression 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } | @@ -2338,8 +2385,8 @@ Expression 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2356,8 +2403,8 @@ Break 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new Break(expression, start, SimpleCharStream.getPosition());} @@ -2365,7 +2412,7 @@ Break BreakStatement() : IfStatement IfStatement() : { - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); Expression condition; IfStatement ifStatement; } @@ -2385,37 +2432,43 @@ Expression Condition(final String keyword) : } catch (ParseException e) { errorMessage = "'(' expected after " + keyword + " keyword"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length(); + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length(); errorEnd = errorStart +1; processParseException(e); } condition = Expression() try { - {return condition;} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } + {return condition;} } IfStatement IfStatement0(Expression condition, final int start,final int end) : { Statement statement; + Statement stmt; + final Statement[] statementsArray; ElseIf elseifStatement; Else elseStatement = null; - ArrayList stmts = new ArrayList(); - ArrayList elseifs = new ArrayList(); + ArrayList stmts; + final ArrayList elseIfList = new ArrayList(); + ElseIf[] elseIfs; int pos = SimpleCharStream.getPosition(); + int endStatements; } { + {stmts = new ArrayList();} ( statement = Statement() {stmts.add(statement);} | statement = htmlBlock() {stmts.add(statement);})* - (elseifStatement = ElseIfStatementColon() {elseifs.add(elseifStatement);})* + {endStatements = SimpleCharStream.getPosition();} + (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})* [elseStatement = ElseStatementColon()] {try { @@ -2433,28 +2486,44 @@ IfStatement IfStatement0(Expression condition, 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { - {return new IfStatement(condition, - (ElseIf[]) elseifs.toArray(), - elseStatement, - pos, - SimpleCharStream.getPosition());} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } + { + elseIfs = new ElseIf[elseIfList.size()]; + elseIfList.toArray(elseIfs); + if (stmts.size() == 1) { + return new IfStatement(condition, + (Statement) stmts.get(0), + elseIfs, + elseStatement, + pos, + SimpleCharStream.getPosition()); + } else { + statementsArray = new Statement[stmts.size()]; + stmts.toArray(statementsArray); + return new IfStatement(condition, + new Block(statementsArray,pos,endStatements), + elseIfs, + elseStatement, + pos, + SimpleCharStream.getPosition()); + } + } + | - (statement = Statement() | statement = htmlBlock()) - {stmts.add(statement);} - ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseifs.add(elseifStatement);})* + (stmt = Statement() | stmt = htmlBlock()) + ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})* [ LOOKAHEAD(1) try { @@ -2467,16 +2536,20 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } ] - {return new IfStatement(condition, - (ElseIf[]) elseifs.toArray(), - elseStatement, - pos, - SimpleCharStream.getPosition());} + { + elseIfs = new ElseIf[elseIfList.size()]; + elseIfList.toArray(elseIfs); + return new IfStatement(condition, + stmt, + elseIfs, + elseStatement, + pos, + SimpleCharStream.getPosition());} } ElseIf ElseIfStatementColon() : @@ -2490,7 +2563,10 @@ ElseIf ElseIfStatementColon() : condition = Condition("elseif") ( statement = Statement() {list.add(statement);} | statement = htmlBlock() {list.add(statement);})* - {return new ElseIf(condition,(Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());} + { + Statement[] stmtsArray = new Statement[list.size()]; + list.toArray(stmtsArray); + return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());} } Else ElseStatementColon() : @@ -2502,7 +2578,10 @@ Else ElseStatementColon() : { ( statement = Statement() {list.add(statement);} | statement = htmlBlock() {list.add(statement);})* - {return new Else((Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());} + { + Statement[] stmtsArray = new Statement[list.size()]; + list.toArray(stmtsArray); + return new Else(stmtsArray,pos,SimpleCharStream.getPosition());} } ElseIf ElseIfStatement() : @@ -2514,7 +2593,10 @@ ElseIf ElseIfStatement() : } { condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/} - {return new ElseIf(condition,(Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());} + { + Statement[] stmtsArray = new Statement[list.size()]; + list.toArray(stmtsArray); + return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());} } WhileStatement WhileStatement() : @@ -2553,18 +2635,21 @@ Statement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { - {return new Block((Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());} + { + Statement[] stmtsArray = new Statement[stmts.size()]; + stmts.toArray(stmtsArray); + return new Block(stmtsArray,pos,SimpleCharStream.getPosition());} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } | @@ -2586,8 +2671,8 @@ DoStatement DoStatement() : } catch (ParseException e) { 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2596,7 +2681,6 @@ ForeachStatement ForeachStatement() : { Statement statement; Expression expression; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); ArrayVariableDeclaration variable; } @@ -2607,8 +2691,8 @@ ForeachStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2616,8 +2700,8 @@ ForeachStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2625,8 +2709,8 @@ ForeachStatement ForeachStatement() : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2634,8 +2718,8 @@ ForeachStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2643,8 +2727,8 @@ ForeachStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { @@ -2653,8 +2737,8 @@ ForeachStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new ForeachStatement(expression, @@ -2683,8 +2767,8 @@ final int startBlock, endBlock; } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } [ initializations = ForInit() ] @@ -2715,18 +2799,21 @@ final int startBlock, endBlock; } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } try { - {return new ForStatement(initializations,condition,increments,new Block((Statement[])list.toArray(),startBlock,endBlock),pos,SimpleCharStream.getPosition());} + { + Statement[] stmtsArray = new Statement[list.size()]; + list.toArray(stmtsArray); + return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());} } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } ) @@ -2753,7 +2840,10 @@ Statement[] StatementExpressionList() : { expr = StatementExpression() {list.add(expr);} ( StatementExpression() {list.add(expr);})* - {return (Statement[]) list.toArray();} + { + Statement[] stmtsArray = new Statement[list.size()]; + list.toArray(stmtsArray); + return stmtsArray;} } Continue ContinueStatement() : @@ -2769,8 +2859,8 @@ Continue ContinueStatement() : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2788,8 +2878,8 @@ ReturnStatement 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } \ No newline at end of file