[racket] Inner workings of source annotation

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Jun 20 20:22:42 EDT 2014

On Jun 20, 2014, at 5:07 PM, Jonker, Todd wrote:

> Greetings,
> 
> I’m interested in learning how DrRacket’s “Check Syntax” feature works.
> 
> As I understand it, the process is (1) perform full macro-expansion on the source code; (2) map elements of the expanded code back to the source code; (3) use that mapping to apply annotations/markup to the source code. The documentation at http://docs.racket-lang.org/tools/Check_Syntax.html seems to cover step (3), but I’m struggling to understand how (2) works.
> 
> In other words, I’m trying to learn how the lexical information in the expanded syntax objects is mapped back to the appropriate parts of the original syntax objects. I’m reading the code to try to figure out the algorithm but hoping that there’s a paper that describes it more directly.
> 
> Thanks in advance for any pointers,



Hi Todd,  good to see you on the list. 

(1) local-expand is your friend, (2) the syntax system already propagates source location information (see syntax/loc in the docs), and (3) if I am guessing correctly you may want to look at "syntax property" lists in the docs just in case you want to implement a language of your own that needs to communicate between layers of expansion. 

The Typed Racket example is the best documented in this regard. And the best paper to read is 

  Languages as Libraries 
  http://www.ccs.neu.edu/racket/pubs/#pldi11-thacff

If you play with Typed Racket, you will see that DrRacket 'lifts through' the syntax. It will do so for any language you create in the #lang spirit (with 2) and even macros. 

There is also a paper on DrScheme and its implementation, which explains a bit about other aspects of implementing these things. It's probably much less helpful 

If this doesn't help, perhaps you can ask more specific questions. -- Matthias


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140620/ea0766a2/attachment.html>

Posted on the users mailing list.