2003/06/18 07:45:48
[org.ibex.core.git] / src / org / xwt / js / Parser.java
index c3f90ca..670f68e 100644 (file)
@@ -133,7 +133,7 @@ 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 new ParserException("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
+        if (getToken() != code) throw pe("expected " + codeToString[code] + ", got " + (op == -1 ? "EOF" : codeToString[op]));
     }
 
     /**
@@ -152,7 +152,7 @@ class Parser extends Lexer implements ByteCodes {
         CompiledFunctionImpl b = appendTo;
 
         switch (tok) {
-        case -1: throw new ParserException("expected expression");
+        case -1: throw pe("expected expression");
 
         // all of these simply push values onto the stack
         case NUMBER: b.add(parserLine, LITERAL, number); break;
@@ -195,7 +195,7 @@ class Parser extends Lexer implements ByteCodes {
         case INC: case DEC: {  // prefix (not postfix)
             startExpr(b, precedence[tok]);
             if (b.get(b.size() - 1) != GET)
-                throw new ParserException("prefixed increment/decrement can only be performed on a valid assignment target");
+                throw pe("prefixed increment/decrement can only be performed on a valid assignment target");
             b.set(b.size() - 1, tok, new Boolean(true));
             break;
         }
@@ -209,7 +209,7 @@ class Parser extends Lexer implements ByteCodes {
             if (peekToken() != RC)
                 while(true) {
                     if (peekToken() != NAME && peekToken() != STRING)
-                        throw new ParserException("expected NAME or STRING");
+                        throw pe("expected NAME or STRING");
                     getToken();
                     b.add(parserLine, LITERAL, string);                          // grab the key
                     consume(COLON);
@@ -284,7 +284,7 @@ class Parser extends Lexer implements ByteCodes {
 
             break;
         }
-        default: throw new ParserException("expected expression, found " + codeToString[tok] + ", which cannot start an expression");
+        default: throw pe("expected expression, found " + codeToString[tok] + ", which cannot start an expression");
         }
 
         // attempt to continue the expression
@@ -561,7 +561,7 @@ class Parser extends Lexer implements ByteCodes {
                     b.add(parserLine, BREAK);                      // break out of the loop if we 'fall through'
                     break;
                 } else {
-                    throw new ParserException("expected CASE, DEFAULT, or RC; got " + codeToString[peekToken()]);
+                    throw pe("expected CASE, DEFAULT, or RC; got " + codeToString[peekToken()]);
                 }
             b.set(size0 - 1, new Integer(b.size() - size0 + 1));      // end of the loop
             break;
@@ -735,8 +735,7 @@ class Parser extends Lexer implements ByteCodes {
 
 
     // ParserException //////////////////////////////////////////////////////////////////////
-    
-    private class ParserException extends IOException { public ParserException(String s) { super(sourceName + ":" + parserLine + " " + s); } }
+    private IOException pe(String s) { return new IOException(sourceName + ":" + parserLine + " " + s); }
     
 }