The simplest way to add the caller's location is to have a location literal, in the spirit of PHP's __LINE__, and pass it as a string parameter.

I am going to use the mlyacc error span meccanism and name the literal _LOC_ (LOC surrounded by a single underscore).

Addtion to "urweb.lex":

<INITIAL> "_LOC_" => (Tokens.LOCATION (pos yypos, pos yypos + size yytext));


Addition to "urweb.grm":

* In the terminals %term clause add

 | LOCATION

* In the "eterm" production clause add

       | LOCATION    (let
val strLoc = ErrorMsg.spanToString (s (LOCATIONleft, LOCATIONright))
                     in
(EPrim (Prim.String (Prim.Normal, strLoc)), s (LOCATIONleft, LOCATIONright))
                     end)










--- ../../urweb-20150520/src/urweb.grm	2015-04-12 20:22:03.000000000 +0200
+++ urweb-20150520/src/urweb.grm	2015-05-25 09:48:56.000000000 +0200
@@ -405,6 +405,7 @@
  | CIF | CTHEN | CELSE
  | FWDAPP | REVAPP | COMPOSE | ANDTHEN
  | BACKTICK_PATH of string
+ | LOCATION
 
 %nonterm
    file of decl list
@@ -1384,6 +1385,11 @@
        | FLOAT                          (EPrim (Prim.Float FLOAT), s (FLOATleft, FLOATright))
        | STRING                         (EPrim (Prim.String (Prim.Normal, STRING)), s (STRINGleft, STRINGright))
        | CHAR                           (EPrim (Prim.Char CHAR), s (CHARleft, CHARright))
+       | LOCATION                       (let
+                                             val strLoc = ErrorMsg.spanToString (s (LOCATIONleft, LOCATIONright))
+                                         in
+                                             (EPrim (Prim.String (Prim.Normal, strLoc)), s (LOCATIONleft, LOCATIONright))
+                                         end)
 
        | path DOT idents                (let
                                              val loc = s (pathleft, identsright)
--- ../../urweb-20150520/src/urweb.lex	2015-04-12 20:22:03.000000000 +0200
+++ urweb-20150520/src/urweb.lex	2015-05-26 15:34:23.193897000 +0200
@@ -539,6 +539,8 @@
 
 <INITIAL> "CURRENT_TIMESTAMP" => (Tokens.CURRENT_TIMESTAMP (pos yypos, pos yypos + size yytext));
 
+<INITIAL> "_LOC_" => (Tokens.LOCATION (pos yypos, pos yypos + size yytext));
+
 <INITIAL> {id}        => (Tokens.SYMBOL (yytext, pos yypos, pos yypos + size yytext));
 <INITIAL> {cid}       => (Tokens.CSYMBOL (yytext, pos yypos, pos yypos + size yytext));
 
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur

Reply via email to