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 8ee1085..3156846 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -159,10 +159,11 @@ public final class PHPParser extends PHPParserSuperclass { } setMarker(e); errorMessage = null; + // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e); } /** - * Create marker for the parse error + * Create marker for the parse error. * @param e the ParseException */ private static void setMarker(final ParseException e) { @@ -194,12 +195,12 @@ public final class PHPParser extends PHPParserSuperclass { final int indx, final int brIndx) throws CoreException { String current; - StringBuffer lineNumberBuffer = new StringBuffer(10); + final StringBuffer lineNumberBuffer = new StringBuffer(10); char ch; current = output.substring(indx, brIndx); if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) { - int onLine = current.indexOf("on line "); + final int onLine = current.indexOf("on line "); if (onLine != -1) { lineNumberBuffer.delete(0, lineNumberBuffer.length()); for (int i = onLine; i < current.length(); i++) { @@ -209,9 +210,9 @@ public final class PHPParser extends PHPParserSuperclass { } } - int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); + final int lineNumber = Integer.parseInt(lineNumberBuffer.toString()); - Hashtable attributes = new Hashtable(); + final Hashtable attributes = new Hashtable(); current = current.replaceAll("\n", ""); current = current.replaceAll("", ""); @@ -278,17 +279,16 @@ public final class PHPParser extends PHPParserSuperclass { pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition)); } - /** - * Create a new task. - */ + /** Create a new task. */ public static final void createNewTask() { final int currentPosition = SimpleCharStream.getPosition(); - final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1, + final String todo = SimpleCharStream.currentBuffer.substring(currentPosition-3, SimpleCharStream.currentBuffer.indexOf("\n", currentPosition)-1); + PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString()); try { setMarker(fileToParse, - "todo : " + todo, + todo, SimpleCharStream.getBeginLine(), TASK, "Line "+SimpleCharStream.getBeginLine()); @@ -501,16 +501,16 @@ MORE : <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | | | )> -| -| -| +| +| +| } /* IDENTIFIERS */ TOKEN : { - < IDENTIFIER: (|) (||)* > + |) (||)* > | < #LETTER: ["a"-"z"] | ["A"-"Z"] @@ -717,21 +717,21 @@ void ClassBody(final ClassDeclaration classDeclaration) : try { } catch (ParseException e) { - errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected"; errorLevel = ERROR; errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = SimpleCharStream.getPosition() + 1; - throw e; + processParseException(e); } ( ClassBodyDeclaration(classDeclaration) )* try { } catch (ParseException e) { - errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected"; + 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; - throw e; + processParseException(e); } } @@ -801,7 +801,7 @@ VariableDeclaration VariableDeclarator() : errorLevel = ERROR; errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; errorEnd = SimpleCharStream.getPosition() + 1; - throw e; + processParseException(e); } ] { @@ -1130,58 +1130,60 @@ ConstantIdentifier Type() : Expression Expression() : { final Expression expr; + Expression initializer = null; + int assignOperator = -1; final int pos = SimpleCharStream.getPosition(); } { - expr = Expression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} -| expr = ExpressionNoBang() {return expr;} -} - -Expression ExpressionNoBang() : -{ - final Expression expr; -} -{ - expr = PrintExpression() {return expr;} -| expr = ListExpression() {return expr;} -| LOOKAHEAD(varAssignation()) - expr = varAssignation() {return expr;} -| expr = ConditionalExpression() {return expr;} -} - -/** - * A Variable assignation. - * varName (an assign operator) any expression - */ -VarAssignation varAssignation() : -{ - final String varName; - final Expression initializer; - final int assignOperator; - final int pos = SimpleCharStream.getPosition(); -} -{ - varName = VariableDeclaratorId() - assignOperator = AssignmentOperator() + LOOKAHEAD(1) + expr = ConditionalExpression() + [ assignOperator = AssignmentOperator() try { initializer = Expression() } catch (ParseException e) { if (errorMessage != null) { throw e; } - errorMessage = "expression expected"; + errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; + errorEnd = SimpleCharStream.getPosition(); throw e; } - {return new VarAssignation(varName.toCharArray(), + ] + { + if (assignOperator == -1) return expr; + return new VarAssignation(expr, initializer, assignOperator, pos, - SimpleCharStream.getPosition());} + SimpleCharStream.getPosition()); + return expr;} +| expr = ExpressionWBang() {return expr;} } +Expression ExpressionWBang() : +{ + final Expression expr; + final int pos = SimpleCharStream.getPosition(); +} +{ + expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} +| expr = ExpressionNoBang() {return expr;} +} + +Expression ExpressionNoBang() : +{ + final Expression expr; +} +{ + expr = PrintExpression() {return expr;} +| expr = ListExpression() {return expr;} +} + +/** + * Any assignement operator. + * @return the assignement operator id + */ int AssignmentOperator() : {} { @@ -1477,11 +1479,12 @@ final int operator; Expression UnaryExpressionNotPlusMinus() : { final Expression expr; + final int pos = SimpleCharStream.getPosition(); } { -// expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} LOOKAHEAD( (Type() | ) ) expr = CastExpression() {return expr;} +| expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} | expr = PostfixExpression() {return expr;} | expr = Literal() {return expr;} | expr = Expression() @@ -1531,48 +1534,20 @@ Expression PostfixExpression() : Expression PrimaryExpression() : { - final Token identifier; Expression expr; - final int pos = SimpleCharStream.getPosition(); } { - LOOKAHEAD(2) - identifier = expr = ClassIdentifier() - {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(), - pos, - SimpleCharStream.getPosition()), - expr, - ClassAccess.STATIC);} - ( - LOOKAHEAD(PrimarySuffix()) - expr = PrimarySuffix(expr))* - {return expr;} -| expr = PrimaryPrefix() ( LOOKAHEAD(PrimarySuffix()) - expr = PrimarySuffix(expr))* + expr = PrimarySuffix(expr) + )* {return expr;} | expr = ArrayDeclarator() {return expr;} } -/** - * An array declarator. - * array(vars) - * @return an array - */ -ArrayInitializer ArrayDeclarator() : -{ - final ArrayVariableDeclaration[] vars; - final int pos = SimpleCharStream.getPosition(); -} -{ - vars = ArrayInitializer() - {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());} -} - Expression PrimaryPrefix() : { final Expression expr; @@ -1593,6 +1568,36 @@ Expression PrimaryPrefix() : SimpleCharStream.getPosition());} } +AbstractSuffixExpression PrimarySuffix(final Expression prefix) : +{ + final AbstractSuffixExpression suffix; + final Expression expr; +} +{ + suffix = Arguments(prefix) {return suffix;} +| suffix = VariableSuffix(prefix) {return suffix;} +| expr = ClassIdentifier() + {suffix = new ClassAccess(prefix, + expr, + ClassAccess.STATIC); + return suffix;} +} + +/** + * An array declarator. + * array(vars) + * @return an array + */ +ArrayInitializer ArrayDeclarator() : +{ + final ArrayVariableDeclaration[] vars; + final int pos = SimpleCharStream.getPosition(); +} +{ + vars = ArrayInitializer() + {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());} +} + PrefixedUnaryExpression classInstantiation() : { Expression expr; @@ -1619,25 +1624,18 @@ ConstantIdentifier ClassIdentifier(): final String expr; final Token token; final int pos = SimpleCharStream.getPosition(); + final ConstantIdentifier type; } { token = {return new ConstantIdentifier(token.image.toCharArray(), pos, SimpleCharStream.getPosition());} +| type = Type() {return type;} | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(), pos, SimpleCharStream.getPosition());} } -AbstractSuffixExpression PrimarySuffix(final Expression prefix) : -{ - final AbstractSuffixExpression expr; -} -{ - expr = Arguments(prefix) {return expr;} -| expr = VariableSuffix(prefix) {return expr;} -} - AbstractSuffixExpression VariableSuffix(final Expression prefix) : { String expr = null; @@ -1833,10 +1831,7 @@ Define defineStatement() : processParseException(e); } try { - ( defineValue = PrintExpression() - | LOOKAHEAD(varAssignation()) - defineValue = varAssignation() - | defineValue = ConditionalExpression()) + defineValue = Expression() } catch (ParseException e) { errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected"; errorLevel = ERROR; @@ -2163,17 +2158,8 @@ Statement BlockStatement() : final Statement 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() {if (phpDocument == currentSegment) pushOnAstNodes(statement); currentSegment.add((MethodDeclaration) statement);