1) Fixed the parser problem with the '::' (Paamayim Nekudotayim).
authorrobekras <robert.kraske@weihenstephan.org>
Sat, 8 Dec 2012 11:05:14 +0000 (12:05 +0100)
committerrobekras <robert.kraske@weihenstephan.org>
Sat, 8 Dec 2012 11:06:47 +0000 (12:06 +0100)
Signed-off-by: robekras <robert.kraske@weihenstephan.org>

net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java

index 70a2d12..98c996d 100644 (file)
@@ -862,16 +862,35 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                        case RETURN:
                                expression = null;
                                getNextToken();
+/*
+                               if (token == TokenName.VARIABLE) {
+                                       getNextToken ();
+
+                                       if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
+                                               getNextToken ();
+
+                                               if (token != TokenName.IDENTIFIER) {
+                                                       throwSyntaxError("identifier expected after '::'.");
+                                               }
+                                               else {
+                                                       getNextToken ();
+                                               }
+                                       }
+                               }
+*/
                                if (token != TokenName.SEMICOLON) {
                                        expression = expr();
                                }
+
                                if (token == TokenName.SEMICOLON) {
                                        sourceEnd = scanner.getCurrentTokenEndPosition();
                                        getNextToken();
-                               } else {
+                               }
+                               else {
                                        if (token != TokenName.INLINE_HTML) {
                                                throwSyntaxError("';' expected after 'return'.");
                                        }
+
                                        sourceEnd = scanner.getCurrentTokenEndPosition();
                                        getNextToken();
                                }
@@ -1100,16 +1119,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                        case CLASS:
                        case INTERFACE:
                                try {
-                                       TypeDeclaration typeDecl = new TypeDeclaration(
-                                                       this.compilationUnit.compilationResult);
-                                       typeDecl.declarationSourceStart = scanner
-                                                       .getCurrentTokenStartPosition();
-                                       typeDecl.declarationSourceEnd = scanner
-                                                       .getCurrentTokenEndPosition();
+                                       TypeDeclaration typeDecl = new TypeDeclaration (this.compilationUnit.compilationResult);
+                                       typeDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
+                                       typeDecl.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
                                        typeDecl.name = new char[] { ' ' };
                                        // default super class
-                                       typeDecl.superclass = new SingleTypeReference(
-                                                       TypeConstants.OBJECT, 0);
+                                       typeDecl.superclass = new SingleTypeReference(TypeConstants.OBJECT, 0);
                                        compilationUnit.types.add(typeDecl);
                                        pushOnAstStack(typeDecl);
                                        unticked_class_declaration_statement(typeDecl);
@@ -1119,6 +1134,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                        astLengthPtr--;
                                }
                                return statement;
+
                        case LBRACE:
                                getNextToken();
                                if (token != TokenName.RBRACE) {
@@ -1147,12 +1163,22 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                }
                                else {
                                        if (token == TokenName.RBRACE) {
-                                               reportSyntaxError("';' expected after expression (Found token: "
+                                               reportSyntaxError ("';' expected after expression (Found token: "
                                                                + scanner.toStringAction(token) + ")");
                                        }
                                        else {
-                                               if (token != TokenName.INLINE_HTML && token != TokenName.EOF) {
-                                                       throwSyntaxError("';' expected after expression (Found token: "
+                                               if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
+                                                       getNextToken ();
+
+                                                       if (token != TokenName.IDENTIFIER) {
+                                                               throwSyntaxError("identifier expected after '::'.");
+                                                       }
+                                                       else {
+                                                               getNextToken ();
+                                                       }
+                                               }
+                                               else if (token != TokenName.INLINE_HTML && token != TokenName.EOF) {
+                                                       throwSyntaxError ("';' expected after expression (Found token: "
                                                                        + scanner.toStringAction(token) + ")");
                                                }
                                                getNextToken();
@@ -1917,16 +1943,16 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                if (token == TokenName.OP_AND) {
                        getNextToken();
                }
-               
+
                methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
                methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
-               
+
                if (Scanner.isIdentifierOrKeyword (token) ||
                    token == TokenName.LPAREN) {
-                   
+
                    if (token == TokenName.LPAREN) {
                        methodDecl.selector = scanner.getCurrentIdentifierSource();
-                   
+
                 if (token.compareTo (TokenName.KEYWORD) > 0) {
                     problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
                                                        scanner.getCurrentTokenStartPosition(),
@@ -1937,7 +1963,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                    }
                    else {
                        methodDecl.selector = scanner.getCurrentIdentifierSource();
-                       
+
                        if (token.compareTo (TokenName.KEYWORD) > 0) {
                            problemReporter.phpKeywordWarning (new String[] {scanner.toStringAction(token) },
                                                                               scanner.getCurrentTokenStartPosition(),
@@ -1945,10 +1971,10 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                                                               referenceContext,
                                                                               compilationUnit.compilationResult);
                        }
-                       
+
                        getNextToken();
                    }
-                   
+
                        if (token == TokenName.LPAREN) {
                                getNextToken();
                        }
@@ -1956,15 +1982,15 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
                                throwSyntaxError("'(' expected in function declaration.");
                        }
-                       
+
                        if (token != TokenName.RPAREN) {
                                parameter_list(methodDecl);
                        }
-                       
+
                        if (token != TokenName.RPAREN) {
                                methodDecl.sourceEnd = scanner.getCurrentTokenStartPosition() - 1;
                                throwSyntaxError("')' expected in function declaration.");
-                       } 
+                       }
                        else {
                                methodDecl.bodyStart = scanner.getCurrentTokenEndPosition() + 1;
                                getNextToken();
@@ -2545,7 +2571,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
         * @param only_variable
         * @param initHandler
         */
-       private Expression expr_without_variable (boolean only_variable, 
+       private Expression expr_without_variable (boolean only_variable,
                                                  UninitializedVariableHandler initHandler,
                                                  boolean bColonAllowed) {
                int exprSourceStart    = scanner.getCurrentTokenStartPosition();
@@ -2895,11 +2921,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
 
                                        if (token == TokenName.IDENTIFIER) {
                                                lhs = identifier(true, true, bColonAllowed);
+
                                                if (lhs != null) {
                                                        expression = lhs;
                                                }
-                                       } else {
-                                               lhs = variable(true, true);
+                                       }
+                                       else {
+                                               lhs = variable (true, true);
 
                                                if (lhs != null) {
                                                        expression = lhs;
@@ -2991,7 +3019,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                                                }
                                                        } else {
                                                                Expression rhs = expr_without_variable (only_variable, initHandler, bColonAllowed);
-                                                               
+
                                                                if (lhs != null && lhs instanceof FieldReference) {
                                                                        if (rhs != null && rhs instanceof FieldReference) {
                                                                                // example:
@@ -3235,7 +3263,7 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                                        case INSTANCEOF:
                                                getNextToken();
                                                TypeReference classRef = class_name_reference();
-                                               
+
                                                if (classRef != null) {
                                                        expression = new InstanceOfExpression (expression, classRef, OperatorIds.INSTANCEOF);
                                                        expression.sourceStart = exprSourceStart;
@@ -3875,6 +3903,14 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                        method_or_not();
                        variable_properties();
                }
+               else if (token == TokenName.PAAMAYIM_NEKUDOTAYIM) {
+                       ref = null;
+                       getNextToken();
+                       object_property();
+                       method_or_not();
+                       variable_properties();
+               }
+               
                return ref;
        }
 
@@ -4080,9 +4116,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers,
                        method_or_not();
                        variable_properties();
                }
-               
+
                // A colon is only allowed here if it is an expression read after a '?'
-               
+
                if ((token == TokenName.COLON) &&
                    (!bColonAllowed)) {
                    throwSyntaxError ("No ':' allowed");