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.

# query example query:[ select foo from table X where foo.whatever is acceptable ]
# template example identifier TEMPLATE { code; code; code; query:[....]; more code that uses query results; etc. }
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.

$TemplateParser = new Parse::RecDescent(<<'__GRAMMAR__'); template: identifier 'TEMPLATE' '{' statement(s) '}' statement: expression | conditional | loopcontrol | <do-this-other-parser: $QueryParser->query() > __GRAMMAR__
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?

--
[ e d @ h a l l e y . c c ]


In reply to using two Parse::RecDescent parsers together by halley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.