Hi Mike,

 

The best way to handle this is add a lexer rule ANSI_QUOTED_ID_OPEN (or
similar) which matches the quoted string when it's missing the final
character.

 

--

Sam Harwell

Owner, Lead Developer

Description: Description: C:\Users\sam\Documents\Work\TVL\tvl_logo_small.png

 <http://tunnelvisionlabs.com/> http://tunnelvisionlabs.com

 

From: Mike Lischke [mailto:[email protected]] 
Sent: Tuesday, May 22, 2012 7:43 AM
To: ANTLR Mailing Mailing List
Subject: [antlr-dev] Forcing a lexer rule

 

Hi all,

 

for code completion I need a way to force a lexer to match somehow even if
it is not complete. Sounds weird, I know. What I have in mind is this:
Imagine you have defined special identifiers which can be quoted (double
quote char). When the user has started typing something like this:

 

select "abc

 

and now invokes code completion I want to show all possible identifiers. But
with a lexer rule like this:

 

ANSI_QUOTED_ID:

            DOUBLE_QUOTE 

            ( options {greedy=false;} :

                        ESCAPE_SEQUENCE         

                        | .

            )* DOUBLE_QUOTE

;

 

I only get an error node plus a not so helpful error message:

 

1 errors found

-end of input-(1)  : error 3 : , at offset 0, at <EOF> : cannot match to any
predicted input...

 

The AST looks like:

 

(1, 0, nil)    nil

                (1, 0, SELECT_SYM55 [418])    select

                (0, 0, <invalid> [0])    Tree Error Node

                (1, 0, (null) [-1])    <EOF>

 

However, what I would like is to get ANSI_QUOTED_ID to match the entire rest
of the input and return this as the ID (plus the error, so I know it was
incorrect). This way I know we are looking for a (possibly quoted)
identifier and, also important, get the text written already. Using EOF or
an empty alternative for the closing DOUBLE_QUOTE gives me various
ambiguities, so this is not a solution either.

 

Scanning the text in the editor backwards is another option, but requires
more processing so I would prefer a (simple) solution in the grammar, if
possible.

 

Mike
-- 
www.soft-gems.net

 

<<image001.png>>

_______________________________________________
antlr-dev mailing list
[email protected]
http://www.antlr.org/mailman/listinfo/antlr-dev

Reply via email to