diff parser/Parser.d @ 88:eb5b2c719a39 new_gen

Major change to locations, tokens and expressions. A location (now SourceLocation or SLoc) is only 32 bit in size - disadvantage is that it can't find its own text. You have to go through the new SourceManager to do that. This has caused changes to a lot of stuff and removal of DataSource and the old Location Additionally Exp has gotten some location stuff, so we can give proper error messages. Not in Decl and Stmt yet, but thats coming too.
author Anders Halager <halager@gmail.com>
date Sun, 04 May 2008 18:13:46 +0200
parents cc05c041e6a3
children a49bb982a7b0
line wrap: on
line diff
--- a/parser/Parser.d	Sun May 04 12:58:02 2008 +0200
+++ b/parser/Parser.d	Sun May 04 18:13:46 2008 +0200
@@ -7,7 +7,8 @@
 
 import misc.Error;
 
-import basic.SmallArray;
+import basic.SmallArray,
+       basic.SourceManager;
 
 import tango.io.Stdout,
        Integer = tango.text.convert.Integer;
@@ -20,10 +21,11 @@
     alias Object Decl;
 
 public:
-    Decl[] parse(Lexer lexer, Action act)
+    Decl[] parse(SourceManager sm, Lexer lexer, Action act)
     {
+        this.sm = sm;
         this.lexer = lexer;
-        action = act;
+        this.action = act;
 
         Decl[] declarations;
 
@@ -427,7 +429,7 @@
             lexer.next();
             int q = op.leftAssoc? 1 + op.prec : op.prec;
             auto exp2 = parseExpression(q);
-            exp = action.actOnBinaryOp(op.operator, exp, exp2);
+            exp = action.actOnBinaryOp(next.location, op.operator, exp, exp2);
             next = lexer.peek();
         }
 
@@ -469,24 +471,28 @@
             }
         }
         else if (next.type == Tok.Cast)
-            return parseCast();
+            return parseCast(next);
         else if (next.type == Tok.Integer)
             return action.actOnNumericConstant(next);
 
-        throw error(__LINE__, "Expected expression, not '"~next.getType~"'").tok(next);
+        throw error(__LINE__, "Expected expression, not '%0'")
+            .tok(next)
+            .arg(next.getType);
         assert(0, "Should not happen");
     }
 
-    Exp parseCast()
+    Exp parseCast(ref Token _cast)
     {
         require(Tok.OpenParentheses);
         auto next = lexer.next;
         if(!next.isBasicType && !next.isIdentifier)
-            throw error(__LINE__, "Expected cast type, not "~next.get).tok(next);
+            throw error(__LINE__, "Expected cast type, not %0")
+                .tok(next)
+                .arg(next.getType);
         
         require(Tok.CloseParentheses);
         auto exp = P();
-        return action.actOnCastExpr(Id(next), exp);
+        return action.actOnCastExpr(_cast, Id(next), exp);
     }
 
     struct UnOp
@@ -565,10 +571,10 @@
 
     Error error(uint line, char[] errMsg)
     {
-        Location loc = lexer.peek.location;
+        SLoc loc = lexer.peek.location;
         auto e =
             new Error("Parser.d(" ~ Integer.toString(line) ~ "): " ~errMsg);
-            e.loc(loc);
+            //e.loc(loc);
             return e;
     }
 
@@ -584,4 +590,5 @@
     }
 
     Lexer lexer;
+    SourceManager sm;
 }