2004/01/03 04:27:27
[org.ibex.core.git] / 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 {
-        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]));
+        }
     }
 
     /**