[antlr-interest] Suppress error mesages in console

Jim Idle jimi at temporal-wave.com
Sat Feb 2 13:19:52 PST 2008


These are coming from the lexer is what I was trying to say. You have
nothing to catch characters that cannot match any rule, so you get an
error from the lexre.

 

Jim

 

From: Dmitry Gusev [mailto:dmitry.gusev at gmail.com] 
Sent: Saturday, February 02, 2008 8:13 AM
To: Jim Idle
Subject: Re: [antlr-interest] Suppress error mesages in console

 

I did implement my own error reporing routine, my grammar with that
routine is there: http://pastebin.com/f3ac5c70

But still I can't figure out where those errors are coming from... Here
is how I'm parsing the input:

            1. ANTLRStringStream input = new
CaseInsensitiveStringStream(expression);
            2. ExpressionLexer lexer = new ExpressionLexer(input);
            3. CommonTokenStream stream = new CommonTokenStream(lexer);
            4. ExpressionParser parser = new ExpressionParser(stream);
            5. try
            6. {
            7.    ExpressionParser.expr_return r = parser.expr();
            8.
            9.    return (CommonTree) r.Tree;
           10. } catch (RecognitionException) {
           11.     throw new
MultipleRecognitionExceptions(parser.GetErrors());
           12. }

The error messages I've mentioned appears in line 3

I know why the error occured, and I've made the bad input especially for
the example.

But the question is how to write the error handling routine that will
suppress that errors to be written to the standard output.

On Feb 2, 2008 6:07 PM, Jim Idle <jimi at temporal-wave.com> wrote:

Implement your own error reporting routine (should be an example in the
wiki I think) and then you can do anything you like including being
silent. However, this looks like a lexer specification problem. Do you
have something that takes a path like: '0'...'9'+ ':' and your input is
[999]? You need to allow the lexer rule to end before the ':' and let
the lexer change the type of the token to whatever that means. 

  

In a lexer, unless you feel that your rules encapsulate all input at all
points, then you may find it useful to have as your last rule: 

  

UNKNOWN : . {System.err.println("Debug: Character '" + $text + "' is not
catered for."); } ; 

  

Jim 

  

From: Dmitry Gusev [mailto:dmitry.gusev at gmail.com] 
Sent: Saturday, February 02, 2008 4:54 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] Suppress error mesages in console 

  

If I try to parse bad input I have error messages in console like this: 

line 1:6 mismatched character ']' expecting ':'

How can I suppress this output? 



-- 
Dmitry Gusev 




-- 
Dmitry Gusev 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080202/d19e5a93/attachment.html 


More information about the antlr-interest mailing list