[antlr-interest] syntax highlighting & pretty printing

Arnulf Heller aheller at gmx.at
Tue Jan 3 00:54:14 PST 2006


Hi there,

have there been any thoughts to include such features directly into 
the design of ANTLR?

I never designed a syntax highlighter by myself (just listened to the 
discussions in this list), so please forgive obvious statements.

Each time one designs a language, there is usually demand for a 
modern way of editing in the target language. In my understanding the 
grammar definition of a language is the right starting point for 
doing SH and PP. What I wanted to have as a user of ANTLR is a common 
base - the grammar files - and ANTLR spit out the lexer/parser plus 
SH/PP stuff.

So, given a valid ANTLR grammar file, is there an easy way to 
generate token definition files for popular editors like eclipse on the fly?
Maybe ANTLR itself would be the right tool for syntax highlighting, 
provided it offers the required interface to, e.g., eclipse (in order 
to embed an grammar driven parser into eclipse).

I recognize that this might be hard to do for languages that need 
user code for code books etc, but at least that should work for 
simple grammars.

Concerning pretty printing: What if ANTLR generates string templates 
for every rule in the grammar? I'm not too familiar with how 
stringtemplate works, but I think the return value of each rule 
should be a instance of a string template.

So, if one has a rule like:

ifrule : "if" LPAREN boolexpr RPAREN LCURLY stmts RCURLY;

a proper string template might be (remove syntax errors):

ifrule(boolexpr,stmts) ::= <<
if ( $boolexpr$ )
{
	$stmts$
}
 >>

arnulf



More information about the antlr-interest mailing list