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 d3b3e59..baab0b4 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -60,7 +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. */ @@ -83,12 +82,6 @@ public final class PHPParser extends PHPParserSuperclass { private static AstNode[] nodes; /** The cursor in expression stack. */ private static int nodePtr; - private static VariableDeclaration[] variableDeclarationStack; - private static int variableDeclarationPtr; - private static Statement[] statementStack; - private static int statementPtr; - private static ElseIf[] elseIfStack; - private static int elseIfPtr; public final void setFileToParse(final IFile fileToParse) { this.fileToParse = fileToParse; @@ -107,11 +100,7 @@ public final class PHPParser extends PHPParserSuperclass { */ private static final void init() { nodes = new AstNode[AstStackIncrement]; - statementStack = new Statement[AstStackIncrement]; - elseIfStack = new ElseIf[AstStackIncrement]; nodePtr = -1; - statementPtr = -1; - elseIfPtr = -1; htmlStart = 0; } @@ -132,83 +121,9 @@ public final class PHPParser extends PHPParserSuperclass { } } - private static final void pushOnVariableDeclarationStack(VariableDeclaration var) { - try { - variableDeclarationStack[++variableDeclarationPtr] = var; - } catch (IndexOutOfBoundsException e) { - int oldStackLength = variableDeclarationStack.length; - VariableDeclaration[] oldStack = variableDeclarationStack; - variableDeclarationStack = new VariableDeclaration[oldStackLength + AstStackIncrement]; - System.arraycopy(oldStack, 0, variableDeclarationStack, 0, oldStackLength); - variableDeclarationPtr = oldStackLength; - variableDeclarationStack[variableDeclarationPtr] = var; - } - } - - private static final void pushOnStatementStack(Statement statement) { - try { - statementStack[++statementPtr] = statement; - } catch (IndexOutOfBoundsException e) { - int oldStackLength = statementStack.length; - Statement[] oldStack = statementStack; - statementStack = new Statement[oldStackLength + AstStackIncrement]; - System.arraycopy(oldStack, 0, statementStack, 0, oldStackLength); - statementPtr = oldStackLength; - statementStack[statementPtr] = statement; - } - } - - private static final void pushOnElseIfStack(ElseIf elseIf) { - try { - elseIfStack[++elseIfPtr] = elseIf; - } catch (IndexOutOfBoundsException e) { - int oldStackLength = elseIfStack.length; - ElseIf[] oldStack = elseIfStack; - elseIfStack = new ElseIf[oldStackLength + AstStackIncrement]; - System.arraycopy(oldStack, 0, elseIfStack, 0, oldStackLength); - elseIfPtr = oldStackLength; - elseIfStack[elseIfPtr] = elseIf; - } - } - - 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); + outlineInfo = new PHPOutlineInfo(parent, currentSegment); final StringReader stream = new StringReader(s); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); @@ -218,8 +133,8 @@ public final class PHPParser extends PHPParserSuperclass { try { parse(); phpDocument = new PHPDocument(null); - phpDocument.nodes = nodes; - PHPeclipsePlugin.log(1,phpDocument.toString()); + phpDocument.nodes = new AstNode[nodes.length]; + System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length); } catch (ParseException e) { processParseException(e); } @@ -235,7 +150,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); @@ -251,8 +166,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 { @@ -380,7 +295,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)); } @@ -569,39 +484,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() : {} { @@ -723,7 +629,7 @@ void phpFile() : */ void PhpBlock() : { - final int start = jj_input_stream.getPosition(); + final int start = SimpleCharStream.getPosition(); } { phpEchoBlock() @@ -734,7 +640,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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -783,13 +689,13 @@ ClassDeclaration ClassDeclaration() : { try { - {pos = jj_input_stream.getPosition();} + {pos = SimpleCharStream.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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } [ @@ -799,8 +705,8 @@ ClassDeclaration ClassDeclaration() : } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } ] @@ -835,8 +741,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) )* @@ -845,8 +751,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; } } @@ -860,7 +766,8 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : FieldDeclaration field; } { - method = MethodDeclaration() {classDeclaration.addMethod(method);} + method = MethodDeclaration() {method.setParent(classDeclaration); + classDeclaration.addMethod(method);} | field = FieldDeclaration() {classDeclaration.addVariable(field);} } @@ -870,21 +777,17 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : FieldDeclaration FieldDeclaration() : { VariableDeclaration variableDeclaration; - variableDeclarationPtr = 0; - variableDeclarationStack = new VariableDeclaration[AstStackIncrement]; VariableDeclaration[] list; + final ArrayList arrayList = new ArrayList(); final int pos = SimpleCharStream.getPosition(); } { variableDeclaration = VariableDeclarator() - { - pushOnVariableDeclarationStack(variableDeclaration); - outlineInfo.addVariable(new String(variableDeclaration.name)); - currentSegment.add(variableDeclaration); - } - ( - variableDeclaration = VariableDeclarator() - {pushOnVariableDeclarationStack(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);} )* @@ -893,23 +796,24 @@ FieldDeclaration FieldDeclaration() : } 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } - {list = new VariableDeclaration[variableDeclarationPtr]; - System.arraycopy(variableDeclarationStack,0,list,0,variableDeclarationPtr); + {list = new VariableDeclaration[arrayList.size()]; + arrayList.toArray(list); return new FieldDeclaration(list, pos, - SimpleCharStream.getPosition());} + 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() @@ -920,8 +824,8 @@ 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; } ] @@ -930,7 +834,7 @@ VariableDeclaration VariableDeclarator() : return new VariableDeclaration(currentSegment, varName.toCharArray(), pos, - jj_input_stream.getPosition()); + SimpleCharStream.getPosition()); } return new VariableDeclaration(currentSegment, varName.toCharArray(), @@ -965,8 +869,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; } } @@ -992,7 +896,7 @@ String Variable(): } | expr = VariableName() - {return expr;} + {return "$" + expr;} } String VariableName(): @@ -1004,9 +908,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() ] @@ -1064,12 +968,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() : @@ -1099,22 +1005,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; } { @@ -1122,12 +1025,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(); } @@ -1148,8 +1049,7 @@ MethodDeclaration MethodDeclarator() : final int pos = SimpleCharStream.getPosition(); } { - [ reference = ] - identifier = + [reference = ] identifier = formalParameters = FormalParameters() {return new MethodDeclaration(currentSegment, identifier.image.toCharArray(), @@ -1165,8 +1065,6 @@ MethodDeclaration MethodDeclarator() : */ Hashtable FormalParameters() : { - String expr; - final StringBuffer buff = new StringBuffer("("); VariableDeclaration var; final Hashtable parameters = new Hashtable(); } @@ -1176,8 +1074,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() @@ -1192,8 +1090,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;} @@ -1222,31 +1120,31 @@ ConstantIdentifier Type() : { {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.STRING, - pos,pos-6);} + pos,pos-6);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.BOOL, - pos,pos-4);} + pos,pos-4);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.BOOLEAN, - pos,pos-7);} + pos,pos-7);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.REAL, - pos,pos-4);} + pos,pos-4);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.DOUBLE, - pos,pos-5);} + pos,pos-5);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.FLOAT, - pos,pos-5);} + pos,pos-5);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.INT, - pos,pos-3);} + pos,pos-3);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.INTEGER, - pos,pos-7);} + pos,pos-7);} | {pos = SimpleCharStream.getPosition(); return new ConstantIdentifier(Types.OBJECT, - pos,pos-6);} + pos,pos-6);} } Expression Expression() : @@ -1283,8 +1181,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(), @@ -1435,8 +1333,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; } { @@ -1506,13 +1404,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; } ( @@ -1537,8 +1433,7 @@ Expression UnaryExpression() : expr = UnaryExpressionNoPrefix() {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);} | - expr = AtUnaryExpression() - {return expr;} + expr = AtUnaryExpression() {return expr;} } Expression AtUnaryExpression() : @@ -1606,8 +1501,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;} @@ -1649,7 +1544,6 @@ Expression PrimaryExpression() : { final Token identifier; Expression expr; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); } { @@ -1758,8 +1652,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, @@ -1772,8 +1666,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());} @@ -1790,7 +1684,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(); @@ -1801,7 +1695,7 @@ Literal Literal() : FunctionCall Arguments(Expression func) : { -ArgumentDeclaration[] args = null; +Expression[] args = null; } { [ args = ArgumentList() ] @@ -1810,74 +1704,44 @@ 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() : { -ArgumentDeclaration arg; +Expression arg; final ArrayList list = new ArrayList(); -ArgumentDeclaration argument; } { - arg = argumentDeclaration() + arg = Expression() {list.add(arg);} ( try { - arg = argumentDeclaration() + 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; } )* { - ArgumentDeclaration[] args = new ArgumentDeclaration[list.size()]; - list.toArray(args); - return args;} + Expression[] arguments = new Expression[list.size()]; + list.toArray(arguments); + return arguments;} } -ArgumentDeclaration argumentDeclaration() : -{ - boolean reference = false; - String varName; - Expression initializer = null; - final int pos = SimpleCharStream.getPosition(); -} -{ - [ {reference = true;}] - varName = VariableDeclaratorId() - [ - - try { - initializer = VariableInitializer() - } 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; - } - ] - { - if (initializer == null) { - return new ArgumentDeclaration(varName.toCharArray(), - reference, - pos); - } - return new ArgumentDeclaration(varName.toCharArray(), - reference, - initializer, - pos); - } -} /** * A Statement without break. */ @@ -1895,8 +1759,8 @@ Statement StatementNoBreak() : 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -1911,8 +1775,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;} @@ -1962,12 +1826,12 @@ HTMLBlock htmlBlock() : } catch (ParseException e) { errorMessage = "End of file unexpected, ' expression = Expression() @@ -2115,8 +1978,8 @@ EchoStatement EchoStatement() : 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; } } @@ -2124,7 +1987,7 @@ EchoStatement EchoStatement() : GlobalStatement GlobalStatement() : { - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); String expr; ArrayList vars = new ArrayList(); GlobalStatement global; @@ -2151,8 +2014,8 @@ GlobalStatement GlobalStatement() : } 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; } } @@ -2177,8 +2040,8 @@ StaticStatement StaticStatement() : } 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; } } @@ -2204,10 +2067,8 @@ LabeledStatement LabeledStatement() : Block Block() : { final int pos = SimpleCharStream.getPosition(); - Statement[] statements; + final ArrayList list = new ArrayList(); Statement statement; - final int startingPtr = statementPtr; - final int length; } { try { @@ -2215,26 +2076,24 @@ 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; } - ( statement = BlockStatement() {pushOnStatementStack(statement);} - | statement = htmlBlock() {pushOnStatementStack(statement);})* + ( 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; } { - length = statementPtr-startingPtr+1; - statements = new Statement[length]; - System.arraycopy(variableDeclarationStack,startingPtr+1,statements,0,length); - statementPtr = startingPtr; + Statement[] statements = new Statement[list.size()]; + list.toArray(statements); return new Block(statements,pos,SimpleCharStream.getPosition());} } @@ -2289,7 +2148,7 @@ VariableDeclaration LocalVariableDeclarator() : return new VariableDeclaration(currentSegment, varName.toCharArray(), pos, - jj_input_stream.getPosition()); + SimpleCharStream.getPosition()); } return new VariableDeclaration(currentSegment, varName.toCharArray(), @@ -2310,19 +2169,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() : @@ -2338,8 +2201,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 { @@ -2350,8 +2213,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 { @@ -2359,8 +2222,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)) @@ -2384,8 +2247,8 @@ AbstractCase[] switchStatementBrace() : } 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; } } @@ -2417,8 +2280,8 @@ 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 { @@ -2430,8 +2293,8 @@ AbstractCase[] switchStatementColon(final int start, final int end) : } 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; } } @@ -2465,7 +2328,6 @@ AbstractCase switchLabel0() : */ Expression SwitchLabel() : { - final Token token; final Expression expr; } { @@ -2476,8 +2338,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 { @@ -2486,8 +2348,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; } | @@ -2498,8 +2360,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; } } @@ -2516,8 +2378,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());} @@ -2525,7 +2387,7 @@ Break BreakStatement() : IfStatement IfStatement() : { - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); Expression condition; IfStatement ifStatement; } @@ -2545,7 +2407,7 @@ 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); } @@ -2556,8 +2418,8 @@ 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() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } } @@ -2599,8 +2461,8 @@ 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 { @@ -2608,8 +2470,8 @@ IfStatement IfStatement0(Expression condition, 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; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } { @@ -2649,8 +2511,8 @@ 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; } ] @@ -2748,8 +2610,8 @@ 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 { @@ -2761,8 +2623,8 @@ Statement WhileStatement0(final int start, final int end) : } 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; } | @@ -2784,8 +2646,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; } } @@ -2794,7 +2656,6 @@ ForeachStatement ForeachStatement() : { Statement statement; Expression expression; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); ArrayVariableDeclaration variable; } @@ -2805,8 +2666,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 { @@ -2814,8 +2675,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 { @@ -2823,8 +2684,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 { @@ -2832,8 +2693,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 { @@ -2841,8 +2702,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 { @@ -2851,8 +2712,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, @@ -2881,8 +2742,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() ] @@ -2913,8 +2774,8 @@ 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 { @@ -2926,8 +2787,8 @@ final int startBlock, endBlock; } 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; } ) @@ -2973,8 +2834,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; } } @@ -2992,8 +2853,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