|Keep It Simple, Stupid|
using two Parse::RecDescent parsers togetherby halley (Prior)
|on Aug 12, 2005 at 14:03 UTC||Need Help??|
halley has asked for the
wisdom of the Perl Monks concerning the following question:
I have an application which has two separate mini-languages. What the languages are, doesn't really matter, so I'll use surrogates that people are familiar with.
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.
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.
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?