2004/01/03 04:27:27
authorbrian <brian@xwt.org>
Fri, 30 Jan 2004 07:44:04 +0000 (07:44 +0000)
committerbrian <brian@xwt.org>
Fri, 30 Jan 2004 07:44:04 +0000 (07:44 +0000)
darcs-hash:20040130074404-aa32f-96a933a67ea5a594a6d50b1ce47bb63220182367.gz

src/org/xwt/js/Parser.java

index b2e2fb1..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 {
 
     /** 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]));
+        }
     }
 
     /**
     }
 
     /**