[antlr-interest] grammar to latex

Ana Nelson nelson.ana at gmail.com
Fri Jun 27 15:42:28 PDT 2008


Okay, I think I've worked out the last few kinks in the pygments
grammar. Examples are (temporarily) here:

http://ananelson.com/tmp/antlr-actionscript/
http://ananelson.com/tmp/antlr-c/
http://ananelson.com/tmp/antlr-csharp/
http://ananelson.com/tmp/antlr-java/
http://ananelson.com/tmp/antlr-python/

If you have any valid ANTLR v3 grammars that you think might be useful
test grammars, especially ones with a different target language,
please send them on to me, or if you prefer you can run pygments
yourself. My grammar is here with basic installation instructions:
http://pastie.org/223723

I did decide to just limit the grammar to ANTLR v3 for simplicity's
sake. Sorry if this puts anyone out but if anyone else wants to add v2
support it shouldn't be that hard, I won't get to it anytime soon
though.

While I was working on this, I came across a Ruby syntax highlighter
called Ultraviolet which, by virtue of the fact that it uses TextMate
bundles, also has ANTLR support:
http://ultraviolet.rubyforge.org/

I haven't used Ultraviolet so I can't give any useful comparisons.


A few of the C Sharp grammars do have 1 error in them, in lines such as this:

@header {
    #pragma warning disable 0219
}

The # before pragma is showing up as an error. Maybe someone can tell
me, is that valid C sharp? If so then I think the C Sharp grammar
might need a tweak.




2008/6/4 Ana Nelson <nelson.ana at gmail.com>:
> The red boxes are where the grammar detects an error in syntax. (As I said,
> the grammar isn't quite finished yet, so those should go away, at least for
> valid ANTLR files.)
>
> Regarding automatic linebreaks, I don't think it's currently supported in
> pygments, but it should be possible to implement. I know for java code it's
> almost a necessity, I've done it by hand before and it's no fun.
>
>
>
> 2008/6/4 Johannes Luber <JALuber at gmx.de>:
>>
>> > Okay, for anyone who is interested in colour and/or font syntax
>> > highlighting
>> > of ANTLR grammars, say if you happen to be writing a book featuring
>> > loads
>> > of
>> > ANTLR code snippets or something, examples are here (in no particular
>> > order):
>> >
>> > (temporary URLs)
>> > http://dev.agent.ie/antlr-python-example.pdf
>> > http://dev.agent.ie/antlr-java-example.pdf
>> > http://dev.agent.ie/antlr-ruby-example.pdf
>> >
>> > Adding new target languages takes about 30 seconds. Pygments is just
>> > brilliant. :-)
>> >
>> > The grammar's not quite finished yet, and I probably won't get back to
>> > it
>> > for a week or two, but it's close enough to get the idea.
>> >
>> > I did a quick hack just now to see if I could get typewriter, roman and
>> > sans
>> > serif fonts in latex, and it worked. :-) (That's why those PDFs have
>> > horrible unaligned code.) So, Felix, I think this might work for you.
>> >
>> > If anyone needs this urgently feel free to contact me off-list,
>> > otherwise
>> > I'll post here when the code is suitable for human consumption.
>> >
>> > -Ana
>>
>> Looking through the files I noticed two problems, all in the Java example.
>> The first is that the labels a1 and a2 aren't formatted correctly. The
>> numbers are red-boxed. Also I haven't figured quite out what the red boxes
>> should show actually. The second problem is that overly long lines don't
>> receive automatic linebreaks. So some text is practically invisible. Can
>> that be helped?
>>
>> Johannes
>> >
>> >
>> >
>> > 2008/6/1 Ana Nelson <nelson.ana at gmail.com>:
>> >
>> > > Hi, Felix,
>> > >
>> > > Don't worry, this wasn't your fault. :-) These things are just
>> > addictive.
>> > > And, when I read your email I wasn't sure if this was exactly what
>> > > were
>> > > looking for so I just did this out of curiosity.
>> > >
>> > > If you want syntax highlighting using fonts rather than colours, this
>> > > should be possible to implement in Pygments but it's not supported at
>> > the
>> > > moment, just bold/italic etc. are. I think it'd just be a case of
>> > writing a
>> > > custom latex formatter which emitted e.g. \textrm rather than
>> > > \colorbox.
>> > >
>> > > It would probably be useful to have this option for people needing to
>> > > publish in black and white. I might take a quick look, but I don't
>> > > know
>> > if
>> > > I'll have time to do this myself.
>> > >
>> > > Anyway, if you think you want to use this you might try installing
>> > > Pygments, preferably the development version, and see how you get on
>> > with
>> > > it.
>> > >
>> > > You could alternatively search for a syntax highlighter with font
>> > support
>> > > already (I don't know if there is one or not) and write a grammar for
>> > that.
>> > > Or, if you are just looking for very basic decorations, maybe an
>> > existing
>> > > grammar would be close enough. (I used to use highlight
>> > > http://www.andre-simon.de/ and it worked fine, but I never tried
>> > modifying
>> > > a grammar.)
>> > >
>> > > -Ana
>> > >
>> > >
>> > > 2008/5/31 Felix Dorner <felix_do at web.de>:
>> > >
>> > >> Hei Ana,
>> > >>
>> > >> gee, I hope I didn't keep you from socializing this weekend... The
>> > example
>> > >> looks cool. I don' t know pygments, what I really would like is not
>> > syntax
>> > >> coloring, but fontification, such that terminals (Strings in ' '
>> > >> would
>> > get
>> > >> typewriter font, braces and other ebnf specials roman, and all other
>> > stuff
>> > >> (rules and subrules) italic. Would this be easy too?
>> > >>
>> > >> Felix
>> > >>
>> > >
>> > >
>>
>> --
>> Psssst! Schon vom neuen GMX MultiMessenger gehört?
>> Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
>
>


More information about the antlr-interest mailing list