>
>> Hm, interesting, though I can't imagine the situation where one
>> wouldn't want to see autocompletion offering the next set of possible
>> tokens. Do you have an example in mind that would help me understand?
>
> The most useful autocompletion is IMHO to autocomplete identifiers.
> Then, the grammar will tell you "identifier expected next", but you
> can't do much with only this information.
Exactly! And that's why the parser's follow set is almost useless for this task. Additionally, while doing auto completion you almost always have an incorrect grammar which the parser is usually not well forgiving (maybe ANTLR 4 is better in this regard, but in general this holds true and it certainly behaves differently with certain parse strategies, like backtracking).
So, what one really needs is the list of possible parser rules (non-terminals) at a given point, provided that the grammar is organized such that a rule name uniquely determines the context information at that point (say, in an SQL command you start auto completion after a schema name and a dot which would then show all possible table names, which could be represented as a rule "table_identifier" in the grammar).
This however requires to parse your grammar, put it in a set of data structures that you can walk for a given input to collect that list (up to the caret position). A similar approach is the list of parse trees ANTLRWorks2 generates, IIRC. See
https://github.com/tunnelvisionlabs/antlrworks2/tree/master/org-antlr-works-editor/src/org/antlr/works/editor/grammar/completion for code details.
Mike
--
www.soft-gems.net