Quantcast

Actions consuming input

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

Actions consuming input

sulfinu
Does anyone know how could an action "instruct" the current ParseRunner to skip some characters in the parsed input? Apparently it's not possible to consume input in an action, but still...
Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Actions consuming input

sulfinu
Here's a workaround.
If the number of characters that must be skipped is saved during the action in a variable called 'toBeSkipped', then a subsequent rule like the following will do it:

ZeroOrMore(
                                                CharRange('\u0000', '\uFDCF'),  // special Parboiled characters are above this range
                                                new Action() {
                                                        @Override
                                                        public boolean run(Context context)
                                                        {
                                                                return toBeSkipped-- > 0;
                                                        }
                                                }
)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Actions consuming input

mathias
Administrator
Sulfino,

sorry for taking so long in responding to your question.
I was going to suggest something exactly along the lines you described in your own reply.
Actions cannot directly move the parsing cursor but with some helper rules that match the relevant character subset you can pretty much achieve anything you likeā€¦

Cheers,
Mathias

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

On 05.09.2011, at 19:12, sulfinu [via parboiled users] wrote:

> Here's a workaround.
> If the number of characters that must be skipped is saved during the action in a variable called 'toBeSkipped', then a subsequent rule like the following will do it:
>
> ZeroOrMore(
>                                                 CharRange('\u0000', '\uFDCF'),  // special Parboiled characters are above this range
>                                                 new Action() {
>                                                         @Override
>                                                         public boolean run(Context context)
>                                                         {
>                                                                 return toBeSkipped-- > 0;
>                                                         }
>                                                 }
> )
>
> If you reply to this email, your message will be added to the discussion below:
> http://users.parboiled.org/Actions-consuming-input-tp3298292p3311422.html
> To start a new topic under parboiled users, email [hidden email]
> To unsubscribe from parboiled users, click here.

Loading...