[antlr-interest] ANTLR for syntax highlighting and word completion
Paul Bouché
paul.bouche at apertio.com
Sun Feb 1 16:57:46 PST 2009
Hi,
I am about to build a new parser for our rules language replacing a hand
written parser. So I want to show the hand-written-parser disciples what
ANTLR is all about ;-)
Anyway, I have read on this list that someone planned an integrated
environment for doing just that - where can I find it?
I have heard that Eclipse uses ANTLR internally for its highlighting and
word completion features - can you confirm this?
I have read somewhere else that it uses the Jikes Parser Generator
(jikespg).
Actually I have already completed a preliminary version of a grammer
which does syntax highlighting by providing a list of marker objects
where each marker is created of a token has sucessfully been recognized
with the start and end position, i.e.:
@members {
}
public void marker(String kind) {
// get last delivered token - I thought my I idea
doing this is pretty slick
Token token = input.LT(-1);
if (token instanceof CommonToken) {
CommonToken ct = (CommonToken) token;
Marker marker =
new Marker(ct.getStartIndex(),
ct.getStopIndex() -
ct.getStartIndex() + 1,
kind);
marks.add(marker);
}
}
}
statment :
JUMP { marker("Keyword"); } destination { marker("Variable"); }
;
destination : NAME | VARIABLE ;
...
I would enrich this grammar with completion actions, in the case of
exceptions and being in "completion mode". It also took me so fiddling
to find out how make ANTLR recover the way I want (I should've read the
book first ;-)).
A co-worder suggested constructing an AST first (cleaner parser and more
flexibilty), also Terence does so in the book and in the AST parser then
do the things I'd like. The deal is that my predecessor did this for
another project and the Tree parser is 7 times slower than the previous
non-AST parser. Do you have any suggestion what to avoid so that there
won't be a significant loss of speed? This is especially important for
syntax highlighting because the GUI user must not be hindered by the
highlighting process.
Any other comments or suggestions on syntax highlighting or word
completion with ANTLR are highly appreciated!
Have a great day,
Paul
More information about the antlr-interest
mailing list