ReportingParseRunner: wrong assertion

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

ReportingParseRunner: wrong assertion

sulfinu
Hello again.

In ReportingParseRunner, at line 73, there's an assertion about the number of error gathered as a result of the second pass. This assertion is simply wrong - maybe you did not take into account "hand-made" errors via ActionException?

I have a text that does not match, because one of the actions throws an ActionException. At line 73 in ReportingParseRunner the collection of errors has two items, one BasicParseError without any contained message and an ActionError that wraps the thrown exception. Both errors point to the same position in the input text.

How can it be mended?

PS: I'm using Parboiled 1.0.0.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

mathias
Administrator
Good point, thanks a lot for this analysis.
The assertion in line 73 is nothing more than a "safety net", making assumptions I had at the time of writing explicit.
Taking into account your use case I think the line really should be:

Preconditions.checkState(result.parseErrors.size() >= 1);

I'll make the right now.

Thanks again for the report!

Cheers,
Mathias

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

On 28.07.2011, at 11:26, sulfinu [via parboiled users] wrote:

> Hello again.
>
> In ReportingParseRunner, at line 73, there's an assertion about the number of error gathered as a result of the second pass. This assertion is simply wrong - maybe you did not take into account "hand-made" errors via ActionException?
>
> I have a text that does not match, because one of the actions throws an ActionException. At line 73 in ReportingParseRunner the collection of errors has two items, one BasicParseError without any contained message and an ActionError that wraps the thrown exception. Both errors point to the same position in the input text.
>
> How can it be mended?
>
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/ReportingParseRunner-wrong-assertion-tp3206183p3206183.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

sulfinu
Err, thank you for responsiveness, may I abuse it? :)
I've just hit another problem - Parboiled instrumented code does not "initialize" my ContextAware helper class, used in ACTION(...). How can I investigate, what should I look for?

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

mathias
Administrator
Could you post a sample snippet?

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

On 28.07.2011, at 12:14, sulfinu [via parboiled users] wrote:

> Err, thank you for responsiveness, may I abuse it? :)
> I've just hit another problem - Parboiled instrumented code does not "initialize" my ContextAware helper class, used in ACTION(...). How can I investigate, what should I look for?
>
> Thank you.
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/ReportingParseRunner-wrong-assertion-tp3206183p3206248.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

sulfinu
I think my code doesn't get instrumented at all, since the exception stack does not show Parboiled generated methods...
I have prepared a most simple test:

public class ParserPlayground extends BaseParser
{
        Support support = new Support();
       
        class Support implements ContextAware
        {
                Context context;
               
                @Override
                public void setContext(Context context)
                {
                        this.context = context;
                }
               
                public boolean someTest()
                {
                        context.getValueStack();
                        return true;
                }
        }
       
        Rule ALL()
        {
                return Sequence(ACTION(support.someTest()), EOI);
        }
       
        public static void main(String[] args) throws IOException
        {
                ParserPlayground parser = new ParserPlayground();
                ParsingResult result = new BasicParseRunner(parser.ALL()).run("");
                if (! result.matched)
                        if (result.hasErrors())
                                throw new ParsingException(ErrorUtils.printParseErrors(result));
                        else throw new ParsingException();
        }
}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

mathias
Administrator
The problem is this line:

> ParserPlayground parser = new ParserPlayground();

You are creating the parser instance yourself, rather than letting parboiled do it.
The line should read:

        ParserPlayground parser = Parboiled.createParser(ParserPlayground.class);

Cheers,
Mathias

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

On 28.07.2011, at 12:49, sulfinu [via parboiled users] wrote:

> I think my code doesn't get instrumented at all, since the exception stack does not show Parboiled generated methods...
> I have prepared a most simple test:
>
> public class ParserPlayground extends BaseParser
> {
>       Support support = new Support();
>
>       class Support implements ContextAware
>       {
>               Context context;
>
>               @Override
>               public void setContext(Context context)
>               {
>                       this.context = context;
>               }
>
>               public boolean someTest()
>               {
>                       context.getValueStack();
>                       return true;
>               }
>       }
>
>       Rule ALL()
>       {
>               return Sequence(ACTION(support.someTest()), EOI);
>       }
>
>       public static void main(String[] args) throws IOException
>       {
>               ParserPlayground parser = new ParserPlayground();
>               ParsingResult result = new BasicParseRunner(parser.ALL()).run("");
>               if (! result.matched)
>                       if (result.hasErrors())
>                               throw new ParsingException(ErrorUtils.printParseErrors(result));
>                       else throw new ParsingException();
>       }
> }
>
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/ReportingParseRunner-wrong-assertion-tp3206183p3206311.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

sulfinu
This post was updated on .
Damn, I forgot about that, sorry about this...
I felt it had to be something wrong with the basics, but... Anyway, thank you and my apologies :$
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ReportingParseRunner: wrong assertion

mathias
Administrator
No reason to apologize...

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

On 28.07.2011, at 19:05, sulfinu [via parboiled users] wrote:

> Damn, sorry about that...
> I felt it has to be something wrong with the basics, but... Anyway, thank you and my apologies :$
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/ReportingParseRunner-wrong-assertion-tp3206183p3207145.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Loading...