Closed theronic closed 5 months ago
The notion of what is the :start
rule in one parser doesn't really make sense as a thing to compose within another parser. What you really want to compose is the individual rules from another grammar map, which you can do as long as you've given them non-conflicting names. You can retrieve the grammar map from inside a parser with :grammar
.
(defparser thing
{:ABC (c/cat (regexp "abc"))}
:start :ABC)
(defparser container
{:S (c/cat (:grammar thing) (regexp "def")}
:start :S)
I would love to be able to compose parsers, e.g.
(As an aside, I find the combinator syntax much more flexible and readable than dealing with the string-based EBNF and ABNF syntaxes.)