[antlr-interest] Skipping sections of the input stream

Burton Samograd burton.samograd at markit.com
Thu Jun 28 09:17:54 PDT 2012


Hello,

We have a grammar that parses files similar to the following:

SECTION "name1" {
      SUBSECTION "subs1" {
     }
     ... // subs2, subs3, etc
}

SECTION "name2" {
      SUBSECTION "subs1" {
     }
     ... // subs2, subs3, etc
}
// more SECTIONS

We allow the user to specify which section of the file that is relevant to the computation they are running.

It has been requested that we only parse the section that has been specified by the user.  I am thinking that
a strategy where we have a rule like:

section: SECTION quoted_string {
    // if quoted_string != requested_section
    // skip entire section by matching { and } parens
    }
    | SECTION quoted_string LCURLY subsection* RCURLY -> ...
    ;

First off, is what I would like to do possible and is my approach reasonable using anltr?  If it is, can I skip over and
discard large sections of the input stream like I have outlined above?

--
Burton Samograd

________________________________
This e-mail, including accompanying communications and attachments, is strictly confidential and only for the intended recipient. Any retention, use or disclosure not expressly authorised by Markit is prohibited. This email is subject to all waivers and other terms at the following link: http://www.markit.com/en/about/legal/email-disclaimer.page

Please visit http://www.markit.com/en/about/contact/contact-us.page? for contact information on our offices worldwide.


More information about the antlr-interest mailing list