[racket] parser tools - defining tokens

From: George Neuner (gneuner2 at gmail.com)
Date: Tue Oct 4 15:21:06 EDT 2011

Hi all,

I am playing with the parser tools in Racket.  I would like to be 
able pass a separately defined list of symbols to define-empty-tokens 
(which is a syntax macro defined in 
parser-tools/private-lex/token.rkt).  Unfortunately passing a list to 
define-empty-tokens doesn't work because the macro is expecting to 
find the token symbols coded in-line.

My lexer uses a hash table to distinguish the reserved words in my 
language from other identifiers.  The object is to initialize the 
parser and the hash table from the same list of symbols ... I don't 
want to have to maintain 2 identical lists.

Currently I'm doing the following:


  (define *reserved-words* '(word1 word2 ...))

  (define *reserved-word-hash*
    (for/hash ((sym *reserved-words*))
      (values (string-downcase (symbol->string sym)) sym)

  (eval `(define-empty-tokens RESERVED ,*reserved-words*))


This works, but using eval seems like a hack and the code fails 
syntax checking in DrRacket (the parser generator code complains that 
the RESERVED token group is undefined).

I probably could modify the macro to return the symbols passed into 
it (I'm sure I don't know how to make it accept a separate 
list).  But I'm not sure it is a good idea to mess with the macro 
anyway ... there is enough black magic in the yacc/lex implementation already.

Any thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111004/9c874770/attachment.html>

Posted on the users mailing list.