Parse Error Handling

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Parse Error Handling

fschmidt
Administrator
I would like more control over reporting errors.  For example, in your CalculatorParser, if I input "(1+2", I get:
Parse Errors:
Invalid input 'EOI', expected Digit, '*', '/', '+', '-' or ')' (line 1, pos 5):
(1+2
    ^
It would be much nicer for the error to say "unclosed parentheses, ')' expected".  I would need some way expressing this in the parser definition, maybe something like:
    Rule Parens() {
        return Sequence('(', Expression(), OnFail(')',"unclosed parentheses, ')' expected"));
    }
Here, OnFail() would take 2 args, a Rule and a String for the error if the parse fails.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Parse Error Handling

mathias
Administrator
Interesting idea.
I'll see whether I can incorporate something like this in parboiled V2.

Cheers,
Mathias

---
[hidden email]
http://www.parboiled.org

On 25.02.2013, at 06:00, "fschmidt [via parboiled users]" <[hidden email]> wrote:

>
>
> I would like more control over reporting errors.  For example, in your
> CalculatorParser, if I input "(1+2", I get:
>
> It would be much nicer for the error to say "unclosed parentheses, ')'
> expected".  I would need some way expressing this in the parser definition,
> maybe something like:
>
> Here, OnFail() would take 2 args, a Rule and a String for the error is the
> parse fails.
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Parse-Error-Handling-tp4024153.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
Loading...