[racket] Look-ahead in parser-tools?

From: Simon Haines (simon.haines at con-amalgamate.net)
Date: Tue Jan 17 17:47:44 EST 2012

Hi Eric,

On 17 January 2012 14:19, Erik Silkensen <eriksilkensen at gmail.com> wrote:

> Hi Simon,
> I think one problem might be that 'any-string' is including whitespace.
>  Could you define alias and fact in some way that's more specific?  For
> example, if you had an 'id' token of just letters ((:+ alphabetic)
> (token-id lexeme)) then maybe your grammar is just...

Unfortunately I'd like an alias or a fact to include whitespace. I guess
for this, parser-tools would need genuine look-ahead which it doesn't seem
to offer. Ideally, I'd just like to lex either 'word' or 'address' tokens
and have the grammar compile these in to place, so I could express the
language as:
'Remember <word>+ is <address>' -> '(remember ,$2 ,$4)
'Remember <word>+' -> '(fact ,$2)

I could probably fudge something like this in the lexer, but I'd then have
to regex the lexeme to extract the relevant parts. Another problem is the
parser-tools parser (and bison, for that matter) can't compile arbitrary
tokens--they need to be declared beforehand, so I can't have a
transformation rule 'word-token whose value is "is"', for example.

It looks like my best approach is a phalanx of regexes, so I'll give this a
try. Many thanks for your reply and suggestions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120118/c7a7af6f/attachment.html>

Posted on the users mailing list.