Is there a way to get a partial AST when the source is not compliant with the language? (in order to propose some code completion)
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Olivier_Hubaut
Posted On:   Friday, November 26, 2004 05:55 AM

Hi, I'm trying, with my team, to implement some code completion for my language in my IDE. We already implement the grammar of the language with ANTLR and it works fine. But now, the question is, how to get a partial AST when the source isn't compliant with the grammar in order to propose some code completion to the user? I have search in different documentation but, either I don't find such mechanism, either such mechanism isn't allowed in the way I'm looking for. By the way, if there is a way to get this AST, or even something else that could give some relevant information in order to implement code completion, I would be glad if you could tell me about some good papers or links. Thanks i   More>>

Hi,

I'm trying, with my team, to implement some code completion for my language in my IDE.

We already implement the grammar of the language with ANTLR and it works fine. But now, the question is, how to get a partial AST when the source isn't compliant with the grammar in order to propose some code completion to the user?

I have search in different documentation but, either I don't find such mechanism, either such mechanism isn't allowed in the way I'm looking for.

By the way, if there is a way to get this AST, or even something else that could give some relevant information in order to implement code completion, I would be glad if you could tell me about some good papers or links.


Thanks in advance.

   <<Less

Re: Is there a way to get a partial AST when the source is not compliant with the language? (in order to propose some code completion)

Posted By:   Anonymous  
Posted On:   Friday, December 3, 2004 05:26 AM

Never done it, but here are ideas:

First of all, you should be able to have your grammar build an AST and fill some (maybe rudimentary) symbol table"on the fly". Then, if the input suddenly ends, you will have some information about the "declared things" up to that point (this is akin to the problem of error handling, where you also want to have "arbitrarily ending sequences" for wrong grammar productions).

You can then use this to guess identifiers that might follow.

If you want "higher code completion", e.g. that after typing if(space) you get if () {}, you could rely on simple prefix patterns (you match the last chars typed - maybe up to some length - with a table of predefined expansions); or you could even use the partial AST or the computation state of your parser (the "stack") to guess following symbols [maybe they are already present somewhere in ANTLR??].


Harald M.

an if statement creates

All other code completion

As I see it, there are different "code completions" around:
(a) Identifier completion: Thi

About | Sitemap | Contact