halley has asked for the wisdom of the Perl Monks concerning the following question:
I wrote the first parser already, and it works well. It's a complicated grammar that reads a single entity. You could think of it like "how to parse a single database query." (It's not SQL but it's roughly the same complexity.) Call the parser on a string, and it returns an entity.
I was then going to write the other parser, which sometimes needs to parse entities of the first kind. Think of it like "how to parse a user interface template" like web or gui or something. Call the parser, and read the whole template.
In several circumstances, the template could include a full "query" type entity. The question is how to parse both mini-languages which can be interlaced, without using just one huge grammar.
# query example query:[ select foo from table X where foo.whatever is acceptable ]
Now, I'm sure that technically, I *could* just write one huge massive grammar that handles both cases, where the query is just one possible sub-rule.# template example identifier TEMPLATE { code; code; code; query:[....]; more code that uses query results; etc. }
However, I don't want to go that route, since templates and queries are not really the same thing, and I want to maintain and/or release them separately.
What I'd like to see is a Parse::RecDescent way of calling a different parser to accomplish a subrule. Is there any such mechanism that I've missed in the documentation and examples?$TemplateParser = new Parse::RecDescent(<<'__GRAMMAR__'); template: identifier 'TEMPLATE' '{' statement(s) '}' statement: expression | conditional | loopcontrol | <do-this-other-parser: $QueryParser->query() > __GRAMMAR__
--
[ e d @ h a l l e y . c c ]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: using two Parse::RecDescent parsers together
by ikegami (Patriarch) on Aug 12, 2005 at 14:26 UTC | |
Re: using two Parse::RecDescent parsers together
by GrandFather (Saint) on Aug 12, 2005 at 14:10 UTC | |
by halley (Prior) on Aug 12, 2005 at 14:17 UTC |