[antlr-interest] Reusing grammars

Jim Idle jimi at temporal-wave.com
Mon Feb 4 08:46:37 PST 2008


If your language change is switchable at the lexical level, then you can
use island grammars – see the example of this in the downloadable 3.0
examples.

 

Jim

 

From: Ian McDonagh [mailto:ianmdev at yahoo.co.uk] 
Sent: Monday, February 04, 2008 4:08 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Reusing grammars

 

Hi all

I want to implement my own template language (like Velocity, JSP or ASP)
and reuse an existing ANTLR 3.0 grammar I've written for evaluating
expressions.

I might have something like this:
________________________________________
Contacts:
@foreach( getPeople(lastName) )
Name: ${Name}
@end
________________________________________

This input would be parsed to construct a template, which is made up of
various nodes, which could in turn be merged with a context to produce
the template output.  The parsed template structure would look something
like this:
#Text:"Contacts:"
#ForEach: getPeople(lastName)
|----#Text:"Name: "
|----#Expression: Name

My problem is that my expression language uses some of the same tokens I
want to use in my template language, so it's difficult to use a lexical
filter only (which is pretty simple with tags like '<%' and '%>').

Is it possible to parse the entire input in one pass, switching between
different parsers?

With ANTLR 2.7 I could just use grammar inheritance.  What to do in
ANTLR 3?

Any advice would be greatly appreciated.
Thanks.



 

  _____  

Sent from Yahoo! - a smarter inbox.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080204/7e9c9fc6/attachment-0001.html 


More information about the antlr-interest mailing list