[antlr-interest] Code-Completion & Code-Highlighting with ANTLR

David Ewing dewing at apple.com
Mon Jun 27 10:25:19 PDT 2005


On Jun 26, 2005, at 3:57 PM, houman babai wrote:

> Hello everyone,
>
> About 2 years ago I used ANTLR in a java project to
> help me evaluate sql like queries stored in a file.
> It was a great experience.
>
> Now I need to write a live-parser for a very simple
> language.  I have a feeling that antlr will be of
> great help.  I just don't have a good idea of how I
> can leverage antlr to process incomplete statements...
>
> So I have a few questions:
> 1. Is there an example out there that demonstrates how
> to use antlr to do live-parsing (for the purposes of
> code-completion & code-highlighting).

I haven't seen any, but I haven't looked.

> 2. How would one go abuot parsing statements as they
> are being entered without the parser generating an
> error?  In other words, how will the parser know that
> the statement is not yet complete, but as far as it
> can see, it is still valid.

Xcode (Apple's Mac OS X IDE) does this by being particularly sneaky.  
We have all of the statement/expression rules return values that  
amount to the current type of the expression (the devil is in the  
details here). We pass the current statement/expression to the parser  
(after already determining all the relevant context), let the types  
fall through, and in places where we're willing to do completion,  
like after a '.' in the grammar, we have the action remember the  
type. The parse will normally end on an error, but the last type  
that's remembered is the one we want to complete on. There is a lot  
of infrastructure outside the grammar that's necessary for all this,  
but I hope that points you in a useful direction.

Dave




More information about the antlr-interest mailing list