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 afc5890..9d2846a 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -87,7 +87,7 @@ public final class PHPParser extends PHPParserSuperclass { /** The cursor in expression stack. */ private static int nodePtr; - public static final boolean PARSER_DEBUG = true; + public static final boolean PARSER_DEBUG = false; public final void setFileToParse(final IFile fileToParse) { PHPParser.fileToParse = fileToParse; @@ -232,14 +232,14 @@ public final class PHPParser extends PHPParserSuperclass { e.currentToken.sourceStart, e.currentToken.sourceEnd, errorLevel, - "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd); + "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+':'+e.currentToken.sourceEnd); } else { setMarker(fileToParse, errorMessage, errorStart, errorEnd, errorLevel, - "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd); + "Line " + e.currentToken.beginLine+", "+errorStart+':'+errorEnd); errorStart = -1; errorEnd = -1; } @@ -335,9 +335,8 @@ public final class PHPParser extends PHPParserSuperclass { currentPosition > SimpleCharStream.currentBuffer.length()) { return; } - final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart, - currentPosition).toCharArray(); - pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition)); + final String html = SimpleCharStream.currentBuffer.substring(htmlStart, currentPosition); + pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition)); } /** Create a new task. */ @@ -589,19 +588,79 @@ MORE : | <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | - | | )> -| + | )> +//| | | } + SKIP : +{ + : IN_STRING +} + + TOKEN : +{ + : IN_STRING +} + + + TOKEN : +{ + : DOLLAR_IN_STRING +} + + TOKEN : +{ + : PHPPARSING +} + + TOKEN : +{ + : DOLLAR_IN_STRING_EXPR +} + + SPECIAL_TOKEN : +{ + <"{"> : SKIPSTRING +} + + SPECIAL_TOKEN : +{ + <"}"> : IN_STRING +} + + SKIP : +{ + <~[]> +} + + TOKEN : +{ + : DOLLAR_IN_STRING +} + + TOKEN : +{ + +} + + SKIP : +{ + <~[]> +} + + SKIP : +{ + <~[]> +} /* IDENTIFIERS */ TOKEN : { : IN_VARIABLE} - TOKEN : + TOKEN : { |) (||)* > | @@ -618,6 +677,10 @@ MORE : > } + SPECIAL_TOKEN : +{ + < ~[] > : IN_STRING +} /* SEPARATORS */ TOKEN : @@ -724,8 +787,8 @@ void PhpBlock() : } catch (ParseException e) { errorMessage = "'?>' expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } } @@ -830,8 +893,8 @@ Token token; } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } ( ClassBodyDeclaration(classDeclaration) )* @@ -841,8 +904,8 @@ Token token; } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); return PHPParser.token.sourceEnd; } @@ -879,7 +942,6 @@ FieldDeclaration FieldDeclaration() : token = variableDeclaration = VariableDeclaratorNoSuffix() { arrayList.add(variableDeclaration); - outlineInfo.addVariable(variableDeclaration.name()); pos = variableDeclaration.sourceEnd; } ( @@ -1024,8 +1086,8 @@ AbstractVariable VariableDeclaratorId() : } catch (ParseException e) { errorMessage = "'$' expected for variable identifier"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } } @@ -1036,13 +1098,13 @@ Variable Variable() : final Token token; } { - token = variable = Var(token) + token = variable = Var() { - return new Variable(variable,token.sourceEnd,variable.sourceEnd); + return variable; } } -Variable Var(final Token dollar) : +Variable Var() : { Variable variable = null; final Token token,token2; @@ -1050,18 +1112,21 @@ Variable Var(final Token dollar) : Expression expression; } { - token = variable = Var(token) - {return new Variable(variable,dollar.sourceEnd,variable.sourceEnd);} + token = variable = Var() + {return new Variable(variable,variable.sourceStart,variable.sourceEnd);} | token = expression = Expression() token2 = { return new Variable(expression, - dollar.sourceStart, + token.sourceStart, token2.sourceEnd); } | token = - {return new Variable(token.image,dollar.sourceStart,token.sourceEnd);} + { + outlineInfo.addVariable('$' + token.image); + return new Variable(token.image,token.sourceStart,token.sourceEnd); + } } Expression VariableInitializer() : @@ -1147,8 +1212,8 @@ MethodDeclaration MethodDeclaration() : if (errorMessage != null) throw 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; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } {currentSegment = functionDeclaration;} @@ -1167,7 +1232,7 @@ MethodDeclaration MethodDeclarator(final int start) : { Token identifier = null; Token reference = null; - final Hashtable formalParameters = new Hashtable(); + final ArrayList formalParameters = new ArrayList(); String identifierChar = SYNTAX_ERROR_CHAR; int end = start; } @@ -1216,7 +1281,7 @@ MethodDeclaration MethodDeclarator(final int start) : * FormalParameters follows method identifier. * (FormalParameter()) */ -int FormalParameters(final Hashtable parameters) : +int FormalParameters(final ArrayList parameters) : { VariableDeclaration var; final Token token; @@ -1236,10 +1301,10 @@ int FormalParameters(final Hashtable parameters) : } [ var = FormalParameter() - {parameters.put(var.name(),var);end = var.sourceEnd;} + {parameters.add(var);end = var.sourceEnd;} ( var = FormalParameter() - {parameters.put(var.name(),var);end = var.sourceEnd;} + {parameters.add(var);end = var.sourceEnd;} )* ] try { @@ -1267,6 +1332,7 @@ VariableDeclaration FormalParameter() : { [token = ] variableDeclaration = VariableDeclaratorNoSuffix() { + outlineInfo.addVariable('$'+variableDeclaration.name()); if (token != null) { variableDeclaration.setReference(true); } @@ -1576,7 +1642,7 @@ Expression MultiplicativeExpression() : expr = UnaryExpression() } catch (ParseException e) { if (errorMessage != null) throw e; - errorMessage = "unexpected token '"+e.currentToken.next.image+"'"; + errorMessage = "unexpected token '"+e.currentToken.next.image+'\''; errorLevel = ERROR; errorStart = PHPParser.token.sourceStart; errorEnd = PHPParser.token.sourceEnd; @@ -1914,6 +1980,7 @@ AbstractVariable VariableSuffix(final AbstractVariable prefix) : Literal Literal() : { final Token token; + StringLiteral literal; } { token = {return new NumberLiteral(token);} @@ -1922,26 +1989,70 @@ Literal Literal() : | token = {return new TrueLiteral(token);} | token = {return new FalseLiteral(token);} | token = {return new NullLiteral(token);} +| literal = evaluableString() {return literal;} +} + +StringLiteral evaluableString() : +{ + ArrayList list = new ArrayList(); + Token start,end; + Token token,lbrace,rbrace; + AbstractVariable var; + Expression expr; +} +{ + start = + ( + + ( + token = {list.add(new Variable(token.image, + token.sourceStart, + token.sourceEnd));} + | + lbrace = + token = + {list.add(new Variable(token.image, + token.sourceStart, + token.sourceEnd));} + rbrace = + ) + )* + end = + { + AbstractVariable[] vars = new AbstractVariable[list.size()]; + list.toArray(vars); + return new StringLiteral(SimpleCharStream.currentBuffer.substring(start.sourceEnd,end.sourceStart), + start.sourceStart, + end.sourceEnd, + vars); + } } FunctionCall Arguments(final Expression func) : { Expression[] args = null; -final Token token; +final Token token,lparen; } { - [ args = ArgumentList() ] + lparen = [ args = ArgumentList() ] try { token = {return new FunctionCall(func,args,token.sourceEnd);} } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list"; errorLevel = ERROR; - errorStart = args[args.length-1].sourceEnd+1; - errorEnd = args[args.length-1].sourceEnd+1; + if (args == null) { + errorStart = lparen.sourceEnd+1; + errorEnd = lparen.sourceEnd+2; + } else { + errorStart = args[args.length-1].sourceEnd+1; + errorEnd = args[args.length-1].sourceEnd+2; + } processParseExceptionDebug(e); } - {return new FunctionCall(func,args,args[args.length-1].sourceEnd);} + { + int sourceEnd = (args == null && args.length != 0) ? lparen.sourceEnd+1 : args[args.length-1].sourceEnd; + return new FunctionCall(func,args,sourceEnd);} } /** @@ -2141,8 +2252,8 @@ HTMLBlock htmlBlock() : } catch (ParseException e) { errorMessage = "unexpected end of file , ' - {return expr;} } catch (ParseException e) { errorMessage = "':' expected after case expression"; errorLevel = ERROR; @@ -2745,11 +2857,11 @@ Expression SwitchLabel() : errorEnd = expr.sourceEnd+1; processParseExceptionDebug(e); } + {return expr;} | token = <_DEFAULT> try { - {return null;} } catch (ParseException e) { errorMessage = "':' expected after 'default' keyword"; errorLevel = ERROR; @@ -2757,6 +2869,7 @@ Expression SwitchLabel() : errorEnd = token.sourceEnd+1; processParseExceptionDebug(e); } + {return null;} } Break BreakStatement() : @@ -2858,8 +2971,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e } catch (ParseException e) { errorMessage = "'endif' expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } try { @@ -2867,8 +2980,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e } catch (ParseException e) { errorMessage = "';' expected after 'endif' keyword"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } { @@ -2908,8 +3021,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e } errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } ] @@ -3009,8 +3122,8 @@ Statement WhileStatement0(final int start, final int end) : } catch (ParseException e) { errorMessage = "'endwhile' expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } try { @@ -3022,8 +3135,8 @@ Statement WhileStatement0(final int start, final int end) : } catch (ParseException e) { errorMessage = "';' expected after 'endwhile' keyword"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; throw e; } | @@ -3076,8 +3189,8 @@ ForeachStatement ForeachStatement() : } catch (ParseException e) { errorMessage = "'(' expected after 'foreach' keyword"; errorLevel = ERROR; - errorStart = foreachToken.sourceEnd+1; - errorEnd = foreachToken.sourceEnd+1; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); {pos = foreachToken.sourceEnd+1;} } @@ -3087,8 +3200,8 @@ ForeachStatement ForeachStatement() : } catch (ParseException e) { errorMessage = "variable expected"; errorLevel = ERROR; - errorStart = pos; - errorEnd = pos; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } try { @@ -3097,8 +3210,8 @@ ForeachStatement ForeachStatement() : } catch (ParseException e) { errorMessage = "'as' expected"; errorLevel = ERROR; - errorStart = pos; - errorEnd = pos; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } try { @@ -3108,8 +3221,8 @@ ForeachStatement ForeachStatement() : if (errorMessage != null) throw e; errorMessage = "variable expected"; errorLevel = ERROR; - errorStart = pos; - errorEnd = pos; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } try { @@ -3118,26 +3231,27 @@ ForeachStatement ForeachStatement() : } catch (ParseException e) { errorMessage = "')' expected after 'foreach' keyword"; errorLevel = ERROR; - errorStart = pos; - errorEnd = pos; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } try { statement = Statement() - {pos = rparenToken.sourceEnd+1;} + {pos = statement.sourceEnd+1;} } catch (ParseException e) { if (errorMessage != null) throw e; errorMessage = "statement expected"; errorLevel = ERROR; - errorStart = pos; - errorEnd = pos; + errorStart = e.currentToken.sourceStart; + errorEnd = e.currentToken.sourceEnd; processParseExceptionDebug(e); } - {return new ForeachStatement(expression, + { + return new ForeachStatement(expression, variable, statement, foreachToken.sourceStart, - statement.sourceEnd);} + pos);} }