Open jtmoulia opened 10 years ago
Here's a potential mapping of PEG expressions to valid Elixir expressions.
a
-> a
a b
-> a - b
a / b
-> a | b
a
-> a|:q
a*
-> a|:*
a+
-> a|:+
!a
-> !a
&a
-> &a
{a}
-> {a}
I still need to explore how Elixir applies it's order of operations when quoting expressions: a mismatch between the different expressions' OOPs will be a pain in the ass to unravel, as opposed to Elixir's quoting mechanism handling it automatically.
Other potential issues: in Elixir, parantheses seem to be used to group terms, but upon quoting are only reflected in the AST's nesting.
Leaving this open, but putting it on the backburner. I think having to shoehorn the PEG expressions into Erlang terms results in a loss of expressivity, so I'm going to just keep writing grammars instead.
At the moment, the Elixir interface specified in
ExGrammar
is nice for specifying transforms, but not expressions: indefine(id, expr, body)
,id
is an atom naming the expression, andexpr
is a String which follows the formal PEG syntax provided in Ford's original paper.ExGrammar
uses its PEG metagrammar to to parse the expression for that particular definition.Using Elixir's macro system, it is possible to make a less "stringified" interface. Something like:
I'll follow this up with a real proposal for a macro parsable PEG expression syntax, and then see what an actual implementation looks like.
Parboiled provides a demo of the general idea.