[antlr-interest] Using $ as delimiter in StringTemplate from ANTRL rewriter grammars

Janico Greifenberg jgre at acm.org
Tue Feb 9 11:43:42 PST 2010


Thanks Terence, Andre,

I had somehow failed to see the setTemplateLib method. Seems obvious
in hindsight...
Anyway, it works now.

Janico

On Tue, Feb 9, 2010 at 4:37 AM, andre rutti <andre.rutti at gmail.com> wrote:
> Hi Janico,
>
> when you create the string template, you can specify which 'TemplateLexer'
> to use; what I do for 'html' is as follow:
>
> ...
>
> // LOAD TEMPLATES (via classpath)
> ClassLoader _classLoader = 'your'.class.getClassLoader();
> InputStream _inputStream =
> _classLoader.getResourceAsStream(_templatesFilename);
> Reader _streamReader = new InputStreamReader(_inputStream);
>
> // StringTemplateGroup _templateGroup = new
> StringTemplateGroup(_streamReader); // uses '<' '>' delimiters
> StringTemplateGroup _templateGroup = new StringTemplateGroup(_streamReader,
> DefaultTemplateLexer.class); // uses '$' '$' delimiters
>
> _streamReader.close();
>
> ...
>
> Regards,
> Andre
>
> On Mon, Feb 8, 2010 at 10:46 PM, Terence Parr <parrt at cs.usfca.edu> wrote:
>>
>> Hi Janico, you are the one that creates the string template group and
>> passes it to the parser. so, it will use whatever you give it. That way,
>> your templates can use whichever  delimiter.
>> Ter
>> On Feb 8, 2010, at 9:22 AM, Janico Greifenberg wrote:
>>
>> > Hi,
>> >
>> > I'm trying to write an ANTLR3 grammar that generates HTML output using
>> > StringTemplate. To avoid having to escape all the HTML tags in the
>> > template rules (e.g. \<p\><variable>\</p\>), I'd prefer to use dollar
>> > as the delimiter for StringTemplate (e.g. <p>$variable$</p>).
>> >
>> > While the latter seems to be the default when StringTemplate is used
>> > on its own, the parser code generated by ANTRL always uses
>> > AngleBracketTemplateLexer when initializing StringTemplate.
>> >
>> > How can I get ANTLR to generate code using DefaultTemplateLexer (i.e.
>> > the variant that uses dollar as the delimiter)?
>> >
>> > Janico
>> >
>> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> > Unsubscribe:
>> > http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>>
>>
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe:
>> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>
>



-- 
http://jgre.org


More information about the antlr-interest mailing list