2003/06/12 17:57:37
[org.ibex.core.git] / src / org / xwt / js / Lexer.java
index f49310b..4752c64 100644 (file)
@@ -25,7 +25,7 @@ class Lexer implements Tokens {
 
     /** for debugging */
     public static void main(String[] s) throws Exception {
-       Lexer l = new Lexer(new InputStreamReader(System.in));
+       Lexer l = new Lexer(new InputStreamReader(System.in), "stdin", 0);
        int tok = 0;
        while((tok = l.getToken()) != -1) System.out.println(codeToString[tok]);
     }
@@ -46,10 +46,14 @@ class Lexer implements Tokens {
     protected int col = 0;
 
     /** the name of the source code file being lexed */
-    protected String sourceName = "unknown";
+    protected String sourceName;
 
     private SmartReader in;
-    public Lexer(Reader r) throws IOException { in = new SmartReader(r); }
+    public Lexer(Reader r, String sourceName, int line) throws IOException {
+       this.sourceName = sourceName;
+       this.line = line;
+       in = new SmartReader(r);
+    }
 
 
     // Predicates ///////////////////////////////////////////////////////////////////////
@@ -396,7 +400,7 @@ class Lexer implements Tokens {
     public int getToken() throws IOException {
        number = null;
        string = null;
-       if (pushBackDepth == 0) return _getToken();
+       if (pushBackDepth == 0) return op = _getToken();
        pushBackDepth--;
        op = pushBackInts[pushBackDepth];
        if (pushBackObjects[pushBackDepth] != null) {
@@ -407,6 +411,6 @@ class Lexer implements Tokens {
     }
 
     class LexerException extends IOException {
-       public LexerException(String s) { super(sourceName + ":" + line + "," + col + " " + s); }
+       public LexerException(String s) { super(sourceName + ":" + line + "," + col + ": " + s); }
     }
 }