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
_______________________________________________
Ur mailing list
[email protected]
http://www.impredicative.com/cgi-bin/mailman/listinfo/ur