Last active
August 29, 2015 14:15
-
-
Save PuercoPop/dd5fb114aad284cd1e15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require ometa) | |
(define-ometa-namespace parser) | |
(define-ometa py-parser | |
(literal (seq (list (atom lit) (bind value (atom anything))) | |
(-> value)))) | |
(omatch | |
py-parser | |
literal | |
'(lit 1) | |
parser) |
argh, did a bunch of edits to my reply. Sorry, I haven't touched this code in a long while and got confused 😄
in fact for something like you want above, you don't even have to touch Racket code, but rather define a helper rule or grammar that defines the kind of list
you mean in your code. So you can and probably should stay in the realm of OMeta for that one.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how about that:
If you look carefully the grammar rule for
(list e)
expects valid ometa expression as argument. That is it has to be one of these:So you need to wrap a sequence of patterns in a
seq
or some such. This is annoying, of course. Writing your variant would be more natural. ometa-racket at the state I left it is very much an assembler. You can slap as much sugar on top of it as you like. Shouldn't be too difficult to teach it your syntax.On a separate note, I must warn you it's not a complete implementation. For instance it won't understand indirectly left-recursive rules. Basically, there's a bunch of stuff that I'd like to happen before I'd ever use it for anything serious. Not to mention it's effectively an interpreter - not a Rackety way of doing stuff like this. But as @DalekBaldwin experience with https://github.com/DalekBaldwin/clometa showed the code is clean enough for anyone to dive in and tweak it to their fancy.