[antlr-interest] recovering from incomplete syntax

Michiel Vermandel Michiel_Vermandel at axi.be
Wed Apr 12 08:22:43 PDT 2006


Hi, 

I am using Antlr 2.7.4. 
I am writing a syntax parser/checker that needs to provide code 
completion. The supported languages are Oracle Forms and a custom langauge 
of my company. I am wondering what the best approche is to recover from an 
incomplete statement and at the same time being able to offer code 
completion. Example: let's say I'm writing a forms trigger: 
This is for example what the user types in a text area: 

<pre> 
declare 
   lName varchar2(64); 
begin 
   lName := :MYBLOCK.| 

   lName := UPPER(lName); 
end; 
</pre> 

The | after :MYBLOCK. is the current position of the carret. 
So at this point he wants to be able to get a list of block fields for 
this block. (I do have a framework to get the fields for this block, once 
the code is parsed and I know :MYBLOCK is a block). 
<BR> 
However, at this point the statement is incomplete. (At the end, the user 
wants to wite lName := :MYBLOCK.MYFIELD;) 
<BR>Now I don't know how to handle this situation. The syntax is 
incomplete, thus the parser does not get to the point of building an AST, 
so I can not figure out that :MYBLOCK. is an - incomplete - reference to a 
block field. I guess I need some kind of recovering of the exception that 
occured during the parsing. 
But here I get to a second problem. I have a definition of bindVariable in 
my grammar like this: 
<pre>COLON! IDENTIFIER (DOT IDENTIFIER)? </pre> 
Since The lexer skips any space, tab or CRLF characters (usual WS 
implementation), The parser sees the following line of code: 
<tt>lName := :MYBLOCK.lName := UPPER(lName);</tt> 
So, in order to detect the real problem, I need to take the 
enter-character into account. This means that I can not set the WS lexer 
rule to type Token.SKIP. But that again will require a lot of changes into 
my parser grammer (to accept the WS characters) and probably will cause a 
lot of overhead.<br> 
So, how can I solve this issue?<br> 
=> how to make clear that the code is 
<tt>lName := :MYBLOCK.|</tt> and not 
<tt>lName := :MYBLOCK.lName := UPPER(lName);</tt><br> 
=> how to recover and complete the syntax parsing so I know I have an 
incomplete block field reference? 
(I wanted to extend my bindVariable definition with a second rule: 
<BR>incomplete_bindVariable: IDENTIFIER DOT WS 
) 

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060412/68c9810a/attachment.html


More information about the antlr-interest mailing list