[antlr-interest] Re: Error Token

bogdan_mt bogdan_mt at yahoo.com
Wed Mar 24 07:59:34 PST 2004


Hi Jan,

If you're concerned only about strings, you can replace the string
rule with the following:

STRING_LITERAL
      : '"' (ESC|~('"'|'\\'|'\n'|'\r'))* ('"')?
      ;

This will accept unfinished strings as well. I checked it and it's
working.

The above solution will display unfinished strings with the same color
as finished ones. If you want to show unfinished strings as errors,
you can use the following:

UNFINISHED_STRING
      : '"' 
        (ESC|~('"'|'\\'|'\n'|'\r'))* 
        ('"' {$setType(STRING_LITERAL);} )?
      ;
 
In the later case, you also have to add STRING_LITERAL in the tokens
section of the lexer, and to edit the Java settings to color
UNFINISHED_STRING in a different way.

Note that you have to do something similar for CHAR.

Bogdan


--- In antlr-interest at yahoogroups.com, "Jan Oetting"
<jan.oetting at g...> wrote:
> Hi,
> thanks for your answers, Matt and Bogdan
> 
> 1. to be correct, Text is not displayed white on white, but not at all
> 2.Bodgan, my problem with unclosed Strings is even in your Java grammar
> example
> "Hello World (without " after World) is not displayed, isnt' it?
> Is this okay for you?
> 3. Matt:using Tokenstreams instead
> SATC uses the CharScanner class not a Tokenstream
> So I can not provide a ErrorFilterTokenStream and present it to SATC (i
> tried this :-(
> Probably SATC needs the CharScanner because of the MultistateLexer ( I
> guess)
> 
> 4. my new idea
> make a new class extending my Lexer and overwriting the nextToken
method,



> catching all Errors,
> extracting the text from the error text and present this class to SATC.
> Is this a good idea?
> 
> Greetings
> Jan
> 
> -- 
> +++ NEU bei GMX und erstmalig in Deutschland: TÜV-geprüfter
Virenschutz +++
> 100% Virenerkennung nach Wildlist. Infos: http://www.gmx.net/virenschutz



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list