[Ur] Obtaining location information
Adam Chlipala
adamc at csail.mit.edu
Sun Mar 15 20:29:58 EDT 2015
Let's see if I understand right: you want some token you can write in
source code, to be replaced at compile time by the location of the
token, along the lines of C's __FILE__ and __LINE__.
Yes, it sounds like an easy feature to add. I would actually do it
entirely in the parser. I'd extend src/urweb.lex with a production for
a new reserved identifier for this 'macro', and I'd extend one of the
expression nonterminals in src/urweb.grm with a rule that translates the
source location of said token into an Ur/Web string literal, using
[ErrorMsg.spanToString], getting ahold of the span in the same way that
it is already being produced to label each expression with its location
for purposes of later error messages.
On 03/14/2015 09:27 AM, Sergey Mironov wrote:
> Hi. I'd like to experiment with establishing a connection between
> Ur/Web application and the OpenSource hosting such as GitHub. The idea
> is to provide the user with links like 'patch this place' or even
> 'translate this section'. In order to generate such a link I need to
> calculate a) current revision and b) source location of the current
> expression. I already know how to do the first point, but AFAIK there
> is no way to extract the latter at the moment. I would be happy to try
> myself in urweb hacking and implement it. My plan is to provide
> necessary definitions in basis.urs and then instruct the compiler to
> replace the function calls with the exact location value calculated by
> the compiler. Does it sound real? Is monoize.sml the best place to
> insert the hook?
>
More information about the Ur
mailing list