[plt-dev] parser macros
Floating an idea:
I'd love to see an extension to the `parser' form that allows
programmers to define grammar macros. Imagine if you could do
something like this:
(parser
(start Expr)
(end EOF)
(tokens Tokens)
(macros
(define-macro (List x)
[(LPAREN (ListTail x))
$2])
(define-macro (ListTail x)
[(RPAREN) '()]
[(x COMMA (ListTail x))
(cons $1 $3)]))
(grammar
(Expr
[(Expr (List Expr))
(make-app-expr $1 $2)]
[(LAMBDA ID (List ID))
(make-lambda-expr $2 $3)]
;; etc...
)))
and imagine the macros would be expanded away as part of the expansion
of the `parser' form. This would give you the ability to define
abstractions in the grammar language in a manner that results in code
duplication rather than sharing. Obviously, it's a bit of a blunt
instrument, but in an LALR framework this kind of duplication is
sometimes necessary to avoid conflicts.
Perhaps better yet, it'd be cool if these macros could be defined
independently, like match-expanders:
(define-grammar-expander (ListTail x)
[(RPAREN) '()]
[(x COMMA (ListTail x))
(cons $1 $3)])
Thoughts?
BTW, who maintains the parser-tools these days?
Dave