Using builders with a parser

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

Using builders with a parser

fge
Hello,

Here is an attempt to use Parboiled for parsing a URI Template, as defined by RFC 6570, though this parser, right now, only (tries and) handles variable specifications as defined by section 2.3 and 2.4 of the RFC.

For this, I use the builder pattern, and intend to use it for other parts of the specification. But it fails miserably, always with the same exception: "Illegal rule definition: Unwrapped action expression!"

I don't get it, since using ACTION normally wraps any boolean expression, doesn't it? (and for the needs of parboiled, I had to make builder setters return a boolean instead of the builder itself or void)

I am doing something wrong, probably many things so. But what things? :(
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using builders with a parser

mathias
Administrator
The problem is that your code is calling `peek` during parser construction, not during parser execution.

This rule:

    public Rule VarName()
    {
        final VariableBuilder builder = (VariableBuilder) peek();
        return Sequence(
            OneOrMore(FirstOf(NotPercentEscape(), PercentEscape())),
            ACTION(builder.setName(match()))
        );
    }

should look like this:

    public Rule VarName()
    {
        return Sequence(
            OneOrMore(FirstOf(NotPercentEscape(), PercentEscape())),
            ((VariableBuilder) peek()).setName(match())
        );
    }

Cheers,
Mathias

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

On 01.01.2013, at 18:23, fge [via parboiled users] <[hidden email]> wrote:

>
>
> Hello,
>
> Here <https://gist.github.com/4428744>   is an attempt to use Parboiled for
> parsing a URI Template, as defined by  RFC 6570
> <"http://tools.ietf.org/html/rfc6570>  , though this parser, right now, only
> (tries and) handles variable specifications as defined by section 2.3 and
> 2.4 of the RFC.
>
> For this, I use the builder pattern, and intend to use it for other parts of
> the specification. But it fails miserably, always with the same exception:
> "Illegal rule definition: Unwrapped action expression!"
>
> I don't get it, since using ACTION normally wraps any boolean expression,
> doesn't it? (and for the needs of parboiled, I had to make builder setters
> return a boolean instead of the builder itself or void)
>
> I am doing something wrong, probably many things so. But what things? :(
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Using-builders-with-a-parser-tp4024116.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, visit
fge
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Using builders with a parser

fge
Ah, OK... I though the stack was "free for use" but apparently not ;)

Since then I have solved the problem another way, but I'll keep this in mind, thanks!
Loading...