[antlr-interest] Auto-complete using ANTLR v3

Jim Idle jimi at temporal-wave.com
Thu Apr 19 09:29:13 PDT 2007


Well, if you override the error reporting for the parser, when you
trigger an error, you will be provided with an expecting token set,
which would normally be used for error reporting:

        1
Error at ^ expecting one of '1', 'Sin', 'Cos' ... 

Instead of printing the error, just return an array of strings that
represent the tokens. For displaying such things, you may want to
classify the tokens rather than just print out all of them. If you are
in an expression, you might have 30 functions, or an unknown element if
you can do X = myexternalfunc(...)

But, I suspect that this is your first shot at the title. You can also
use rule actions of course, or a combination of things.

Jim

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Eric Elliott
Sent: Thursday, April 19, 2007 8:39 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Auto-complete using ANTLR v3

I'm trying to implement a relatively simple auto-complete using ANTLR
v3.
Can anyone point me to examples or give a general overview of what is
involved in getting Antlr to give back what tokens are valid at a
particular point in an input?

As a simple example, say I have:

expr:  val ('+' val)*;

val:  '1' | ( 'Sin(' val ')' ) | ( ' Cos(' val ')');

If the user has typed 1, I should be able to present '+'.
if the user has typed 1 +, I should be able to present '1', 'Sin(', or
'Cos('.

Thanks for any input.

-- 
Eric Elliott
eric.elliott at gmail.com


More information about the antlr-interest mailing list