[antlr-interest] grammar to latex

Ana Nelson nelson.ana at gmail.com
Sat May 31 14:13:11 PDT 2008


This looked like too much fun so I tried writing a Pygments grammar for
ANTLR myself. It's not finished, but the embedded Java syntax highlighting
works. :-) The bits in red which look like ransom-note lettering are the
parts of the grammar which I haven't completed. I'll try to finish the
basics off tomorrow or Monday. I'm just using Expr.g from the wiki which is
a pretty basic example.

I'm just delegating the Java portions to the Java syntax highlighter, which
means ANTLR variables in Java code like $ID or $expr don't get any special
treatment. But, that can be fixed pretty easily I imagine.

Also, it'll be very easy to add other target languages.

Pygments Grammar:
http://pastie.caboo.se/206505

Raw generated latex:
http://pastie.caboo.se/206509

Generated latex style file:
http://pastie.caboo.se/206512

Runnable latex file:
http://pastie.caboo.se/206513

Resulting PDF (temporary URL):
http://dev.agent.ie/antlr-example.pdf



2008/5/31 Ana Nelson <nelson.ana at gmail.com>:

> Maybe try pygments? Or some other syntax highlighter with LaTeX support.
> You'd just have to write/adapt a grammar definition for
> ANTLR-and-your-target-language.
>
> I think that would be easier and more maintainable than writing your own
> custom output templates from scratch, even with StringTemplate :-), and you
> would be able to output other formats (besides LaTeX, e.g. HTML) for free.
>
> In fact, out of curiosity I just ran 'pygmentize' on one of my java-based
> ANTLR grammar files using the java lexer and it didn't blow up. The results
> weren't perfect but I was able to paste them into a latex file and render
> it.
>
> -Ana
>
>
>
> 2008/5/31 Felix Dorner <felix_do at web.de>:
>
> Hi,
>>
>> Converting my antlr grammar to readable format (cursive nonterminals,
>> typewriter terminals, filter actions) in latex is a pain. I looked for a
>> grammar to latex converter, but didn' t find anything suitable. This would
>> be a cool antlr+stringtemplate translator huh?
>>
>> Maybe someone has already done this?
>>
>>
>> Felix
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080531/203fa155/attachment.html 


More information about the antlr-interest mailing list