X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index 628b52a..00cc6c9 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -29,7 +29,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities; import org.eclipse.jface.preference.IPreferenceStore; import java.util.Hashtable; -import java.util.Enumeration; import java.util.ArrayList; import java.io.StringReader; import java.io.*; @@ -60,9 +59,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 +67,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 @@ -83,12 +81,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 +99,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 +120,10 @@ 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); + 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); @@ -217,9 +132,11 @@ public final class PHPParser extends PHPParserSuperclass { init(); 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); + if (PHPeclipsePlugin.DEBUG) { + PHPeclipsePlugin.log(1,phpDocument.toString()); + } } catch (ParseException e) { processParseException(e); } @@ -235,7 +152,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 +168,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 { @@ -270,31 +187,6 @@ public final class PHPParser extends PHPParserSuperclass { } } - /** - * Create markers according to the external parser output - */ - private static void createMarkers(final String output, final IFile file) throws CoreException { - // delete all markers - file.deleteMarkers(IMarker.PROBLEM, false, 0); - - int indx = 0; - int brIndx; - boolean flag = true; - while ((brIndx = output.indexOf("
", indx)) != -1) { - // newer php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 6; - flag = false; - } - if (flag) { - while ((brIndx = output.indexOf("
", indx)) != -1) { - // older php error output (tested with 4.2.3) - scanLine(output, file, indx, brIndx); - indx = brIndx + 4; - } - } - } - private static void scanLine(final String output, final IFile file, final int indx, @@ -380,10 +272,29 @@ 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)); } + /** + * Create a new task. + */ + public static final void createNewTask() { + final int currentPosition = SimpleCharStream.getPosition(); + final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1, + SimpleCharStream.currentBuffer.indexOf("\n", + currentPosition)-1); + try { + setMarker(fileToParse, + "todo : " + todo, + SimpleCharStream.getBeginLine(), + TASK, + "Line "+SimpleCharStream.getBeginLine()); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + } + } + private static final void parse() throws ParseException { phpFile(); } @@ -424,34 +335,30 @@ PARSER_END(PHPParser) SPECIAL_TOKEN : { "//" : IN_SINGLE_LINE_COMMENT -| - "#" : IN_SINGLE_LINE_COMMENT -| - <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT -| - "/*" : IN_MULTI_LINE_COMMENT +| "#" : IN_SINGLE_LINE_COMMENT +| <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT +| "/*" : IN_MULTI_LINE_COMMENT } SPECIAL_TOKEN : { : PHPPARSING +| "?>" : DEFAULT } - SPECIAL_TOKEN : + SPECIAL_TOKEN : { - " > : DEFAULT + "todo" {PHPParser.createNewTask();} } - -SPECIAL_TOKEN : + SPECIAL_TOKEN : { - : PHPPARSING + "*/" : PHPPARSING } - -SPECIAL_TOKEN : + SPECIAL_TOKEN : { - : PHPPARSING + "*/" : PHPPARSING } @@ -549,8 +456,8 @@ MORE : { | -| -| +| +| | | | @@ -594,10 +501,9 @@ MORE : | @@ -689,15 +595,7 @@ MORE : TOKEN : { - < DOLLAR_ID: > -} - -void phpTest() : -{} -{ - Php() - - {PHPParser.createNewHTMLCode();} + > } void phpFile() : @@ -705,7 +603,7 @@ void phpFile() : { try { (PhpBlock())* - + {PHPParser.createNewHTMLCode();} } catch (TokenMgrError e) { PHPeclipsePlugin.log(e); errorStart = SimpleCharStream.getPosition(); @@ -723,18 +621,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); } } @@ -779,41 +679,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(), + classNameImage, pos, 0); } else { classDeclaration = new ClassDeclaration(currentSegment, - className.image.toCharArray(), - superclassName.image.toCharArray(), + classNameImage, + superclassNameImage, pos, 0); } @@ -835,8 +740,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 +750,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; } } @@ -861,7 +766,7 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : } { method = MethodDeclaration() {classDeclaration.addMethod(method);} -| field = FieldDeclaration() {classDeclaration.addVariable(field);} +| field = FieldDeclaration() {classDeclaration.addField(field);} } /** @@ -877,35 +782,34 @@ FieldDeclaration FieldDeclaration() : { variableDeclaration = VariableDeclarator() {arrayList.add(variableDeclaration); - outlineInfo.addVariable(new String(variableDeclaration.name)); - currentSegment.add(variableDeclaration);} + outlineInfo.addVariable(new String(variableDeclaration.name));} ( variableDeclaration = VariableDeclarator() {arrayList.add(variableDeclaration); - outlineInfo.addVariable(new String(variableDeclaration.name)); - currentSegment.add(variableDeclaration);} + outlineInfo.addVariable(new String(variableDeclaration.name));} )* 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());} + 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() @@ -916,8 +820,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; } ] @@ -926,7 +830,7 @@ VariableDeclaration VariableDeclarator() : return new VariableDeclaration(currentSegment, varName.toCharArray(), pos, - jj_input_stream.getPosition()); + SimpleCharStream.getPosition()); } return new VariableDeclaration(currentSegment, varName.toCharArray(), @@ -942,31 +846,39 @@ VariableDeclaration VariableDeclarator() : String VariableDeclaratorId() : { String expr; - Expression expression; + Expression expression = null; final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); ConstantIdentifier ex; } { try { - expr = Variable() {buff.append(expr);} + expr = Variable() ( LOOKAHEAD(2) {ex = new ConstantIdentifier(expr.toCharArray(), pos, SimpleCharStream.getPosition());} expression = VariableSuffix(ex) - {buff.append(expression.toStringExpression());} )* - {return buff.toString();} + { + if (expression == null) { + return expr; + } + return expression.toStringExpression(); + } } 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; } } +/** + * Return a variablename without the $. + * @return a variable name + */ String Variable(): { final StringBuffer buff; @@ -977,13 +889,13 @@ 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(); } | @@ -991,6 +903,10 @@ String Variable(): {return expr;} } +/** + * A Variable name (without the $) + * @return a variable name String + */ String VariableName(): { final StringBuffer buff; @@ -1000,9 +916,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() ] @@ -1011,15 +927,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(); } @@ -1097,11 +1013,11 @@ ArrayVariableDeclaration[] ArrayInitializer() : MethodDeclaration MethodDeclaration() : { final MethodDeclaration functionDeclaration; - Token functionToken; final Block block; + final OutlineableWithChildren seg = currentSegment; } { - functionToken = + try { functionDeclaration = MethodDeclarator() {outlineInfo.addVariable(new String(functionDeclaration.name));} @@ -1109,26 +1025,15 @@ MethodDeclaration MethodDeclaration() : 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; } - { - if (currentSegment != null) { - currentSegment.add(functionDeclaration); - currentSegment = functionDeclaration; - } - currentFunction = functionDeclaration; - } + {currentSegment = functionDeclaration;} block = Block() - { - functionDeclaration.statements = block.statements; - currentFunction = null; - if (currentSegment != null) { - currentSegment = (OutlineableWithChildren) currentSegment.getParent(); - } - return functionDeclaration; - } + {functionDeclaration.statements = block.statements; + currentSegment = seg; + return functionDeclaration;} } /** @@ -1142,16 +1047,27 @@ 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(), - formalParameters, - reference != null, - pos, - SimpleCharStream.getPosition());} + identifierChar, + formalParameters, + reference != null, + pos, + SimpleCharStream.getPosition());} } /** @@ -1160,8 +1076,6 @@ MethodDeclaration MethodDeclarator() : */ Hashtable FormalParameters() : { - String expr; - final StringBuffer buff = new StringBuffer("("); VariableDeclaration var; final Hashtable parameters = new Hashtable(); } @@ -1171,9 +1085,9 @@ 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; - throw e; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } [ var = FormalParameter() {parameters.put(new String(var.name),var);} @@ -1187,9 +1101,9 @@ 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; - throw e; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } {return parameters;} } @@ -1216,32 +1130,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() : @@ -1263,7 +1168,7 @@ Expression Expression() : VarAssignation varAssignation() : { String varName; - final Expression expression; + final Expression initializer; final int assignOperator; final int pos = SimpleCharStream.getPosition(); } @@ -1271,19 +1176,19 @@ VarAssignation varAssignation() : varName = VariableDeclaratorId() assignOperator = AssignmentOperator() try { - expression = Expression() + initializer = Expression() } catch (ParseException e) { if (errorMessage != null) { throw e; } errorMessage = "expression expected"; errorLevel = ERROR; - errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = jj_input_stream.getPosition() + 1; + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; throw e; } {return new VarAssignation(varName.toCharArray(), - expression, + initializer, assignOperator, pos, SimpleCharStream.getPosition());} @@ -1430,8 +1335,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; } { @@ -1504,8 +1409,8 @@ Expression MultiplicativeExpression() : 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; } ( @@ -1575,8 +1480,8 @@ final int operator; final int pos = SimpleCharStream.getPosition(); } { - ( {operator = OperatorIds.PLUS_PLUS;} - | {operator = OperatorIds.MINUS_MINUS;}) + ( {operator = OperatorIds.PLUS_PLUS;} + | {operator = OperatorIds.MINUS_MINUS;}) expr = PrimaryExpression() {return new PrefixedUnaryExpression(expr,operator,pos);} } @@ -1598,8 +1503,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;} @@ -1627,8 +1532,8 @@ Expression PostfixExpression() : } { expr = PrimaryExpression() - [ {operator = OperatorIds.PLUS_PLUS;} - | {operator = OperatorIds.MINUS_MINUS;}] + [ {operator = OperatorIds.PLUS_PLUS;} + | {operator = OperatorIds.MINUS_MINUS;}] { if (operator == -1) { return expr; @@ -1641,7 +1546,6 @@ Expression PrimaryExpression() : { final Token identifier; Expression expr; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); } { @@ -1663,6 +1567,11 @@ Expression PrimaryExpression() : {return expr;} } +/** + * An array declarator. + * array(vars) + * @return an array + */ ArrayInitializer ArrayDeclarator() : { final ArrayVariableDeclaration[] vars; @@ -1687,9 +1596,10 @@ Expression PrimaryPrefix() : | expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr, OperatorIds.NEW, pos);} -| var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(), - pos, - SimpleCharStream.getPosition());} +| var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment, + var.toCharArray(), + pos, + SimpleCharStream.getPosition());} } PrefixedUnaryExpression classInstantiation() : @@ -1750,8 +1660,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, @@ -1764,8 +1674,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());} @@ -1782,7 +1692,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(); @@ -1793,7 +1703,7 @@ Literal Literal() : FunctionCall Arguments(Expression func) : { -ArgumentDeclaration[] args = null; +Expression[] args = null; } { [ args = ArgumentList() ] @@ -1802,8 +1712,8 @@ 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());} @@ -1814,72 +1724,33 @@ ArgumentDeclaration[] args = null; * argumentDeclaration() (, argumentDeclaration)* * @return an array of arguments */ -ArgumentDeclaration[] ArgumentList() : +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;} } /** - * Here is an argument declaration. - * It's [&]$variablename[=variableInitializer] - */ -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. */ Statement StatementNoBreak() : @@ -1893,11 +1764,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; } } @@ -1912,8 +1783,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;} @@ -1961,17 +1832,18 @@ HTMLBlock htmlBlock() : try { ( | ) } catch (ParseException e) { - errorMessage = "End of file unexpected, ' expression = Expression() @@ -2108,24 +1979,23 @@ EchoStatement EchoStatement() : )* try { - { - Expression[] exprs = new Expression[expressions.size()]; - expressions.toArray(exprs); - return new EchoStatement(exprs,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; @@ -2152,8 +2022,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; } } @@ -2178,8 +2048,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; } } @@ -2214,8 +2084,8 @@ 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() {list.add(statement);} @@ -2225,8 +2095,8 @@ Block Block() : } 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; } { @@ -2240,9 +2110,21 @@ Statement BlockStatement() : final Statement statement; } { - statement = Statement() {return statement;} + try { + statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement); + return statement;} + } catch (ParseException e) { + if (errorMessage != null) throw 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); + currentSegment.add((MethodDeclaration) statement); + return statement;} } /** @@ -2255,7 +2137,8 @@ Statement BlockStatementNoBreak() : { statement = StatementNoBreak() {return statement;} | statement = ClassDeclaration() {return statement;} -| statement = MethodDeclaration() {return statement;} +| statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement); + return statement;} } VariableDeclaration[] LocalVariableDeclaration() : @@ -2286,7 +2169,7 @@ VariableDeclaration LocalVariableDeclarator() : return new VariableDeclaration(currentSegment, varName.toCharArray(), pos, - jj_input_stream.getPosition()); + SimpleCharStream.getPosition()); } return new VariableDeclaration(currentSegment, varName.toCharArray(), @@ -2305,7 +2188,7 @@ EmptyStatement EmptyStatement() : return new EmptyStatement(pos-1,pos);} } -Statement StatementExpression() : +Expression StatementExpression() : { Expression expr,expr2; int operator; @@ -2314,10 +2197,10 @@ Statement StatementExpression() : expr = PreIncDecExpression() {return expr;} | expr = PrimaryExpression() - [ {return new PostfixedUnaryExpression(expr, + [ {return new PostfixedUnaryExpression(expr, OperatorIds.PLUS_PLUS, SimpleCharStream.getPosition());} - | {return new PostfixedUnaryExpression(expr, + | {return new PostfixedUnaryExpression(expr, OperatorIds.MINUS_MINUS, SimpleCharStream.getPosition());} | operator = AssignmentOperator() expr2 = Expression() @@ -2339,8 +2222,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 { @@ -2351,8 +2234,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 { @@ -2360,8 +2243,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)) @@ -2385,8 +2268,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; } } @@ -2418,8 +2301,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 { @@ -2431,8 +2314,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; } } @@ -2466,7 +2349,6 @@ AbstractCase switchLabel0() : */ Expression SwitchLabel() : { - final Token token; final Expression expr; } { @@ -2477,8 +2359,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 { @@ -2487,8 +2369,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; } | @@ -2499,8 +2381,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; } } @@ -2517,8 +2399,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());} @@ -2526,7 +2408,7 @@ Break BreakStatement() : IfStatement IfStatement() : { - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); Expression condition; IfStatement ifStatement; } @@ -2546,21 +2428,21 @@ 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) : @@ -2600,8 +2482,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 { @@ -2609,8 +2491,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; } { @@ -2628,10 +2510,10 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) : stmts.toArray(statementsArray); return new IfStatement(condition, new Block(statementsArray,pos,endStatements), - elseIfs, - elseStatement, - pos, - SimpleCharStream.getPosition()); + elseIfs, + elseStatement, + pos, + SimpleCharStream.getPosition()); } } @@ -2650,8 +2532,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; } ] @@ -2749,8 +2631,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 { @@ -2762,8 +2644,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; } | @@ -2785,8 +2667,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; } } @@ -2795,7 +2677,6 @@ ForeachStatement ForeachStatement() : { Statement statement; Expression expression; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); ArrayVariableDeclaration variable; } @@ -2806,8 +2687,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 { @@ -2815,8 +2696,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 { @@ -2824,8 +2705,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 { @@ -2833,8 +2714,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 { @@ -2842,8 +2723,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 { @@ -2852,8 +2733,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, @@ -2868,9 +2749,9 @@ ForStatement ForStatement() : { final Token token; final int pos = SimpleCharStream.getPosition(); -Statement[] initializations = null; +Expression[] initializations = null; Expression condition = null; -Statement[] increments = null; +Expression[] increments = null; Statement action; final ArrayList list = new ArrayList(); final int startBlock, endBlock; @@ -2882,8 +2763,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() ] @@ -2914,8 +2795,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 { @@ -2927,38 +2808,38 @@ 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; } ) } -Statement[] ForInit() : +Expression[] ForInit() : { - Statement[] statements; + Expression[] exprs; } { LOOKAHEAD(LocalVariableDeclaration()) - statements = LocalVariableDeclaration() - {return statements;} + exprs = LocalVariableDeclaration() + {return exprs;} | - statements = StatementExpressionList() - {return statements;} + exprs = StatementExpressionList() + {return exprs;} } -Statement[] StatementExpressionList() : +Expression[] StatementExpressionList() : { final ArrayList list = new ArrayList(); - Statement expr; + Expression expr; } { expr = StatementExpression() {list.add(expr);} ( StatementExpression() {list.add(expr);})* { - Statement[] stmtsArray = new Statement[list.size()]; - list.toArray(stmtsArray); - return stmtsArray;} + Expression[] exprsArray = new Expression[list.size()]; + list.toArray(exprsArray); + return exprsArray;} } Continue ContinueStatement() : @@ -2974,8 +2855,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; } } @@ -2993,8 +2874,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