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 f82c7cd..af9d369 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -159,6 +159,7 @@ public final class PHPParser extends PHPParserSuperclass { } setMarker(e); errorMessage = null; + if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e); } /** @@ -510,7 +511,7 @@ MORE : TOKEN : { - < IDENTIFIER: (|) (||)* > + |) (||)* > | < #LETTER: ["a"-"z"] | ["A"-"Z"] @@ -1130,10 +1131,31 @@ ConstantIdentifier Type() : Expression Expression() : { final Expression expr; + Expression initializer = null; + int assignOperator = -1; + final int pos = SimpleCharStream.getPosition(); +} +{ + LOOKAHEAD(2) + expr = ConditionalExpression() [ assignOperator = AssignmentOperator() initializer = Expression() ] + { + if (assignOperator == -1) return expr; + return new VarAssignation(expr, + initializer, + assignOperator, + pos, + SimpleCharStream.getPosition()); + return expr;} +| expr = ExpressionWBang() {return expr;} +} + +Expression ExpressionWBang() : +{ + final Expression expr; final int pos = SimpleCharStream.getPosition(); } { - expr = Expression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} + expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);} | expr = ExpressionNoBang() {return expr;} } @@ -1144,44 +1166,12 @@ Expression ExpressionNoBang() : { 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 + * Any assignement operator. + * @return the assignement operator id */ -VarAssignation varAssignation() : -{ - final String varName; - final Expression initializer; - final int assignOperator; - final int pos = SimpleCharStream.getPosition(); -} -{ - varName = VariableDeclaratorId() - assignOperator = AssignmentOperator() - try { - initializer = Expression() - } catch (ParseException e) { - if (errorMessage != null) { - throw e; - } - errorMessage = "expression expected"; - errorLevel = ERROR; - errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1; - errorEnd = SimpleCharStream.getPosition() + 1; - throw e; - } - {return new VarAssignation(varName.toCharArray(), - initializer, - assignOperator, - pos, - SimpleCharStream.getPosition());} -} - int AssignmentOperator() : {} { @@ -1477,11 +1467,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() @@ -1536,18 +1527,6 @@ Expression PrimaryExpression() : 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()) @@ -1558,21 +1537,6 @@ Expression PrimaryExpression() : {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 +1557,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 +1613,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 +1820,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 +2147,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);