X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.java b/net.sourceforge.phpeclipse/src/test/PHPParser.java index 18848d5..f0ea36f 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.java @@ -39,7 +39,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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. */ @@ -50,6 +49,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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 @@ -62,12 +63,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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; @@ -86,11 +81,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon */ 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; } @@ -111,83 +102,10 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } } - 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); @@ -196,9 +114,11 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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); } @@ -214,7 +134,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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); @@ -230,8 +150,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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 { @@ -359,7 +279,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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)); } @@ -367,12 +287,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon phpFile(); } - static final public void phpTest() throws ParseException { - Php(); - jj_consume_token(0); - PHPParser.createNewHTMLCode(); - } - static final public void phpFile() throws ParseException { try { label_1: @@ -448,7 +362,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon * or */ static final public void PhpBlock() throws ParseException { - final int start = jj_input_stream.getPosition(); + final int start = SimpleCharStream.getPosition(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case PHPECHOSTART: phpEchoBlock(); @@ -510,7 +424,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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; - {if (true) throw e;} + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } break; default: @@ -626,43 +540,48 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon final Token className; Token superclassName = null; final int pos; + char[] classNameImage = SYNTAX_ERROR_CHAR; + char[] superclassNameImage = null; jj_consume_token(CLASS); + pos = SimpleCharStream.getPosition(); try { - pos = jj_input_stream.getPosition(); className = jj_consume_token(IDENTIFIER); + 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; - {if (true) throw e;} + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case EXTENDS: jj_consume_token(EXTENDS); try { superclassName = jj_consume_token(IDENTIFIER); + 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; - {if (true) throw e;} + errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; + errorEnd = SimpleCharStream.getPosition() + 1; + processParseException(e); + superclassNameImage = SYNTAX_ERROR_CHAR; } break; default: jj_la1[6] = jj_gen; ; } - 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); } @@ -682,8 +601,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } 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; {if (true) throw e;} } label_3: @@ -704,8 +623,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } 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; {if (true) throw e;} } } @@ -719,11 +638,10 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case FUNCTION: method = MethodDeclaration(); - classDeclaration.addMethod(method); + method.setParent(classDeclaration); break; case VAR: field = FieldDeclaration(); - classDeclaration.addVariable(field); break; default: jj_la1[8] = jj_gen; @@ -766,22 +684,23 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } 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; - {if (true) 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); {if (true) return new FieldDeclaration(list, pos, - SimpleCharStream.getPosition());} + SimpleCharStream.getPosition(), + currentSegment);} throw new Error("Missing return statement in function"); } static final public VariableDeclaration VariableDeclarator() throws ParseException { - final String varName, varValue; + final String varName; Expression initializer = null; - final int pos = jj_input_stream.getPosition(); + final int pos = SimpleCharStream.getPosition(); varName = VariableDeclaratorId(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: @@ -791,8 +710,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } 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; {if (true) throw e;} } break; @@ -804,7 +723,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon {if (true) return new VariableDeclaration(currentSegment, varName.toCharArray(), pos, - jj_input_stream.getPosition());} + SimpleCharStream.getPosition());} } {if (true) return new VariableDeclaration(currentSegment, varName.toCharArray(), @@ -843,8 +762,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } 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; {if (true) throw e;} } throw new Error("Missing return statement in function"); @@ -872,15 +791,15 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon {if (true) return token.image.substring(1);} } buff = new StringBuffer(token.image); - buff.append('{'); + buff.append("{"); buff.append(expression.toStringExpression()); - buff.append('}'); + buff.append("}"); {if (true) return buff.toString();} break; case DOLLAR: jj_consume_token(DOLLAR); expr = VariableName(); - {if (true) return expr;} + {if (true) return "$" + expr;} break; default: jj_la1[12] = jj_gen; @@ -900,9 +819,9 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon jj_consume_token(LBRACE); expression = Expression(); jj_consume_token(RBRACE); - buff = new StringBuffer('{'); + buff = new StringBuffer("{"); buff.append(expression.toStringExpression()); - buff.append('}'); + buff.append("}"); {if (true) return buff.toString();} break; case IDENTIFIER: @@ -921,15 +840,15 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon {if (true) return token.image;} } buff = new StringBuffer(token.image); - buff.append('{'); + buff.append("{"); buff.append(expression.toStringExpression()); - buff.append('}'); + buff.append("}"); {if (true) return buff.toString();} break; case DOLLAR: jj_consume_token(DOLLAR); expr = VariableName(); - buff = new StringBuffer('$'); + buff = new StringBuffer("$"); buff.append(expr); {if (true) return buff.toString();} break; @@ -1098,30 +1017,25 @@ Expression expr,expr2; */ static final public MethodDeclaration MethodDeclaration() throws ParseException { final MethodDeclaration functionDeclaration; - Token functionToken; final Block block; - functionToken = jj_consume_token(FUNCTION); + jj_consume_token(FUNCTION); try { functionDeclaration = MethodDeclarator(); outlineInfo.addVariable(new String(functionDeclaration.name)); } catch (ParseException e) { - if (errorMessage != null) { - {if (true) throw e;} - } + if (errorMessage != null) {if (true) 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; {if (true) throw e;} } if (currentSegment != null) { currentSegment.add(functionDeclaration); currentSegment = functionDeclaration; } - currentFunction = functionDeclaration; block = Block(); functionDeclaration.statements = block.statements; - currentFunction = null; if (currentSegment != null) { currentSegment = (OutlineableWithChildren) currentSegment.getParent(); } @@ -1139,6 +1053,7 @@ Expression expr,expr2; Token reference = null; final Hashtable formalParameters; final int pos = SimpleCharStream.getPosition(); + char[] identifierChar = SYNTAX_ERROR_CHAR; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case BIT_AND: reference = jj_consume_token(BIT_AND); @@ -1147,10 +1062,19 @@ Expression expr,expr2; jj_la1[21] = jj_gen; ; } - identifier = jj_consume_token(IDENTIFIER); + try { + identifier = jj_consume_token(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(); {if (true) return new MethodDeclaration(currentSegment, - identifier.image.toCharArray(), + identifierChar, formalParameters, reference != null, pos, @@ -1163,8 +1087,6 @@ Expression expr,expr2; * (FormalParameter()) */ static final public Hashtable FormalParameters() throws ParseException { - String expr; - final StringBuffer buff = new StringBuffer("("); VariableDeclaration var; final Hashtable parameters = new Hashtable(); try { @@ -1172,8 +1094,8 @@ Expression expr,expr2; } 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; {if (true) throw e;} } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { @@ -1206,8 +1128,8 @@ Expression expr,expr2; } 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; {if (true) throw e;} } {if (true) return parameters;} @@ -1243,56 +1165,47 @@ Expression expr,expr2; case STRING: jj_consume_token(STRING); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.STRING, - pos,pos-6);} + {if (true) return new ConstantIdentifier(Types.STRING,pos,pos-6);} break; case BOOL: jj_consume_token(BOOL); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.BOOL, - pos,pos-4);} + {if (true) return new ConstantIdentifier(Types.BOOL,pos,pos-4);} break; case BOOLEAN: jj_consume_token(BOOLEAN); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.BOOLEAN, - pos,pos-7);} + {if (true) return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);} break; case REAL: jj_consume_token(REAL); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.REAL, - pos,pos-4);} + {if (true) return new ConstantIdentifier(Types.REAL,pos,pos-4);} break; case DOUBLE: jj_consume_token(DOUBLE); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.DOUBLE, - pos,pos-5);} + {if (true) return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);} break; case FLOAT: jj_consume_token(FLOAT); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.FLOAT, - pos,pos-5);} + {if (true) return new ConstantIdentifier(Types.FLOAT,pos,pos-5);} break; case INT: jj_consume_token(INT); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.INT, - pos,pos-3);} + {if (true) return new ConstantIdentifier(Types.INT,pos,pos-3);} break; case INTEGER: jj_consume_token(INTEGER); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.INTEGER, - pos,pos-7);} + {if (true) return new ConstantIdentifier(Types.INTEGER,pos,pos-7);} break; case OBJECT: jj_consume_token(OBJECT); pos = SimpleCharStream.getPosition(); - {if (true) return new ConstantIdentifier(Types.OBJECT, - pos,pos-6);} + {if (true) return new ConstantIdentifier(Types.OBJECT,pos,pos-6);} break; default: jj_la1[25] = jj_gen; @@ -1371,8 +1284,8 @@ Expression expr,expr2; } 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; {if (true) throw e;} } {if (true) return new VarAssignation(varName.toCharArray(), @@ -1676,8 +1589,8 @@ Expression expr,expr2; } 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; {if (true) throw e;} } expr = new BinaryExpression(expr,expr2,operator); @@ -1815,13 +1728,11 @@ Expression expr,expr2; try { expr = UnaryExpression(); } catch (ParseException e) { - if (errorMessage != null) { - {if (true) throw e;} - } + if (errorMessage != null) {if (true) 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; {if (true) throw e;} } label_18: @@ -1892,7 +1803,7 @@ Expression expr,expr2; case LPAREN: case DOLLAR_ID: expr = AtUnaryExpression(); - {if (true) return expr;} + {if (true) return expr;} break; default: jj_la1[48] = jj_gen; @@ -2056,8 +1967,8 @@ final int operator; } 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; {if (true) throw e;} } {if (true) return expr;} @@ -2141,7 +2052,6 @@ final int pos = SimpleCharStream.getPosition(); static final public Expression PrimaryExpression() throws ParseException { final Token identifier; Expression expr; - final StringBuffer buff = new StringBuffer(); final int pos = SimpleCharStream.getPosition(); if (jj_2_5(2)) { identifier = jj_consume_token(IDENTIFIER); @@ -2333,8 +2243,8 @@ final int pos = SimpleCharStream.getPosition(); } 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; {if (true) throw e;} } {if (true) return new ClassAccess(prefix, @@ -2424,8 +2334,8 @@ final int pos = SimpleCharStream.getPosition(); } 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; {if (true) throw e;} } {if (true) return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());} @@ -2455,7 +2365,7 @@ final int pos = SimpleCharStream.getPosition(); case STRING_LITERAL: token = jj_consume_token(STRING_LITERAL); pos = SimpleCharStream.getPosition(); - {if (true) return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);} + {if (true) return new StringLiteral(token.image.toCharArray(),pos-token.image.length());} break; case TRUE: jj_consume_token(TRUE); @@ -2481,11 +2391,29 @@ final int pos = SimpleCharStream.getPosition(); } static final public FunctionCall Arguments(Expression func) throws ParseException { -ArgumentDeclaration[] args = null; +Expression[] args = null; jj_consume_token(LPAREN); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { + case ARRAY: + case LIST: + case PRINT: + case NEW: + case NULL: + case TRUE: + case FALSE: + case AT: case DOLLAR: + case BANG: + case INCR: + case DECR: + case PLUS: + case MINUS: case BIT_AND: + case INTEGER_LITERAL: + case FLOATING_POINT_LITERAL: + case STRING_LITERAL: + case IDENTIFIER: + case LPAREN: case DOLLAR_ID: args = ArgumentList(); break; @@ -2498,19 +2426,23 @@ 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; {if (true) throw e;} } {if (true) return new FunctionCall(func,args,SimpleCharStream.getPosition());} throw new Error("Missing return statement in function"); } - static final public ArgumentDeclaration[] ArgumentList() throws ParseException { -ArgumentDeclaration arg; +/** + * An argument list is a list of arguments separated by comma : + * argumentDeclaration() (, argumentDeclaration)* + * @return an array of arguments + */ + static final public Expression[] ArgumentList() throws ParseException { +Expression arg; final ArrayList list = new ArrayList(); -ArgumentDeclaration argument; - arg = argumentDeclaration(); + arg = Expression(); list.add(arg); label_21: while (true) { @@ -2524,63 +2456,19 @@ ArgumentDeclaration argument; } jj_consume_token(COMMA); 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; {if (true) throw e;} } } - ArgumentDeclaration[] args = new ArgumentDeclaration[list.size()]; - list.toArray(args); - {if (true) return args;} - throw new Error("Missing return statement in function"); - } - - static final public ArgumentDeclaration argumentDeclaration() throws ParseException { - boolean reference = false; - String varName; - Expression initializer = null; - final int pos = SimpleCharStream.getPosition(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case BIT_AND: - jj_consume_token(BIT_AND); - reference = true; - break; - default: - jj_la1[71] = jj_gen; - ; - } - varName = VariableDeclaratorId(); - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case ASSIGN: - jj_consume_token(ASSIGN); - 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; - {if (true) throw e;} - } - break; - default: - jj_la1[72] = jj_gen; - ; - } - if (initializer == null) { - {if (true) return new ArgumentDeclaration(varName.toCharArray(), - reference, - pos);} - } - {if (true) return new ArgumentDeclaration(varName.toCharArray(), - reference, - initializer, - pos);} + Expression[] arguments = new Expression[list.size()]; + list.toArray(arguments); + {if (true) return arguments;} throw new Error("Missing return statement in function"); } @@ -2595,11 +2483,11 @@ ArgumentDeclaration argument; try { jj_consume_token(SEMICOLON); } 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; {if (true) throw e;} } } @@ -2630,8 +2518,8 @@ ArgumentDeclaration argument; } 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; {if (true) throw e;} } {if (true) return statement;} @@ -2682,7 +2570,7 @@ ArgumentDeclaration argument; token = jj_consume_token(AT); break; default: - jj_la1[73] = jj_gen; + jj_la1[71] = jj_gen; ; } statement = IncludeStatement(); @@ -2700,7 +2588,7 @@ ArgumentDeclaration argument; {if (true) return statement;} break; default: - jj_la1[74] = jj_gen; + jj_la1[72] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -2760,7 +2648,7 @@ ArgumentDeclaration argument; {if (true) return statement;} break; default: - jj_la1[75] = jj_gen; + jj_la1[73] = jj_gen; jj_consume_token(-1); throw new ParseException(); } @@ -2782,7 +2670,7 @@ ArgumentDeclaration argument; ; break; default: - jj_la1[76] = jj_gen; + jj_la1[74] = jj_gen; break label_22; } phpEchoBlock(); @@ -2796,21 +2684,22 @@ ArgumentDeclaration argument; jj_consume_token(PHPSTARTSHORT); break; default: - jj_la1[77] = jj_gen; + jj_la1[75] = jj_gen; jj_consume_token(-1); throw new ParseException(); } } catch (ParseException e) { errorMessage = "End of file unexpected, '