[Ur] Proposed location literals to track caller's location in error msgs.

Adam Chlipala adamc at csail.mit.edu
Fri May 29 11:25:43 EDT 2015


I don't have a strong opinion, but I think I lean toward "_LOC_", 
between those two choices.  I'd suggesting waiting another day for any 
more opinions voiced on this mailing list and then sending me a patch 
with the appropriate version implemented.  (If you can send it in the 
special Mercurial patch format [created with 'hg export' command], that 
will be most convenient, to give you proper credit in the version history!)

On 05/29/2015 08:47 AM, Gabriel Riba wrote:
> El 28/05/15 a les 14:29, Adam Chlipala ha escrit:
>> Why not just implement this functionality purely in the lexer, lexing
>> the special marker as a string literal with the right contents? You can
>> call [ErrorMsg.spanOf] directly in the lexer, rather than via its alias
>> [s] in the parser.
>
> You are right, the simpler, the better.
>
> Here is a possible code to add to urweb.lex, leaving urweb.grm untouched.
>
> <INITIAL> "_LOC_" => (let val strLoc = ErrorMsg.spanToString 
> (ErrorMsg.spanOf (pos yypos, pos yypos + size yytext))
>                       in
>                           Tokens.STRING (strLoc, pos yypos, pos yypos 
> + size yytext)
>                       end);
>
>
> What do you prefer, the shorter _LOC_ or the PHP's style __LOC__ ?
>
> -----------
>
> Simple test sample:
>
> ---
>
> fun myPartialListHd [a] (loc: string) (li: list a): a =
>       case li of
>         | h :: t => h
>         | _ => error <xml>myPartialListHd: invalid arguments at {[loc]}
>                      </xml>
>
> fun main () : transaction page =
>    let val res = myPartialListHd _LOC_ ([] : list int)
>    in
>       return <xml><body>result: {[res]}</body></xml>
>    end



More information about the Ur mailing list