[antlr-interest] Reading block of arbitrary text delimited by curly braces

Burton Samograd burton.samograd at markit.com
Tue Jul 17 12:57:48 PDT 2012


Hello,

We have a requirement where we need to include a block of arbitrary text in a block, like so:

BLOCK { some arbitrary text here }

We initially got around this by making the whole block a token, like:

BLOCK : 'BLOCK (' '|'\t'|'\r'|'\n')* '{' (~'}')*  '}' ;

but this is less than ideal.  I am thinking that we would use something like:

block : BLOCK RCURLY BLOCK_DATA LCURLY

with BLOCK : 'BLOCK' and LCURLY/RCURLY as { and }.

I am stuck on specifying BLOCK_DATA which is basically .* to the lexer.  I have attempted to access the input stream from the parser RECOGNIZER but have not been able to come up with a solution.

I am looking to basically hijack the input stream after seeing a BLOCK token so I can read the arbitrary text; I can parse out the  { } as needed.

Is this possible?

--
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