2004/01/03 04:27:27
[org.ibex.core.git] / src / org / xwt / js / Parser.java
index 3f61832..b67b59c 100644 (file)
@@ -133,7 +133,16 @@ class Parser extends Lexer implements ByteCodes {
 
     /** gets a token and throws an exception if it is not <tt>code</tt> */
     private void consume(int code) throws IOException {
-        if (getToken() != code) throw pe("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
+        if (getToken() != code) {
+            if(code == NAME) switch(op) {
+                case RETURN: case TYPEOF: case BREAK: case CONTINUE: case TRY: case THROW:
+                case ASSERT: case NULL: case TRUE: case FALSE: case IN: case IF: case ELSE:
+                case SWITCH: case CASE: case DEFAULT: case WHILE: case VAR: case WITH:
+                case CATCH: case FINALLY:
+                    throw pe("Bad variable name; '" + codeToString[op].toLowerCase() + "' is a javascript keyword");
+            }
+            throw pe("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
+        }
     }
 
     /**
@@ -160,6 +169,18 @@ class Parser extends Lexer implements ByteCodes {
         case NULL: b.add(parserLine, LITERAL, null); break;
         case TRUE: case FALSE: b.add(parserLine, LITERAL, JS.B(tok == TRUE)); break;
 
+        // (.foo) syntax
+        case DOT: {
+            consume(NAME);
+            b.add(parserLine, TOPSCOPE);
+            b.add(parserLine, LITERAL, "");
+            b.add(parserLine, GET);
+            b.add(parserLine, LITERAL, string);
+            b.add(parserLine, GET);
+            continueExpr(b, minPrecedence);
+            break;
+        }
+
         case LB: {
             b.add(parserLine, ARRAY, JS.ZERO);                       // push an array onto the stack
             int size0 = b.size;