PetitParser - skip everything up to X

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

PetitParser - skip everything up to X

Sean P. DeNigris
Administrator
I've been playing with PetitParser and I keep running into what seems like a common case.  I want to skip everything up to the first match of my second parser.
For example, if I don't care about anything in a string that comes before 'dd', I write:
parser2 := 'dd' asParser negate plus, 'dd' asParser ==> [ :nodes | nodes second ].
parser2 parse: 'kslkxjclkxjcdd'. "Returns  'dd'"

This gets the job done, but seems awkward. What's the most elegant way?
I thought maybe "'dd' asParser not plus, 'dd' asParser."
But the image just hangs.

Thanks.
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - skip everything up to X

Tudor Girba
Hi Sean,

#negate is the way to go. #not does not consume the stream.

Cheers,
Doru


On 12 Nov 2010, at 00:25, Sean P. DeNigris wrote:

>
> I've been playing with PetitParser and I keep running into what seems like a
> common case.  I want to skip everything up to the first match of my second
> parser.
> For example, if I don't care about anything in a string that comes before
> 'dd', I write:
> parser2 := 'dd' asParser negate plus, 'dd' asParser ==> [ :nodes | nodes
> second ].
> parser2 parse: 'kslkxjclkxjcdd'. "Returns  'dd'"
>
> This gets the job done, but seems awkward. What's the most elegant way?
> I thought maybe "'dd' asParser not plus, 'dd' asParser."
> But the image just hangs.
>
> Thanks.
> Sean
> --
> View this message in context: http://forum.world.st/PetitParser-skip-everything-up-to-X-tp3038824p3038824.html
> Sent from the Moose mailing list archive at Nabble.com.
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

--
www.tudorgirba.com

"Yesterday is a fact.
 Tomorrow is a possibility.
 Today is a challenge."




_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - skip everything up to X

Sean P. DeNigris
Administrator
What do you think of adding it to the API?

Something like PPParser-skipUntil.st:

PPParser>>skipUntil

        ^ self negate plus, self ==> [ :nodes | nodes second ].

parser2 := 'dd' asParser skipUntil.
parser2 parse: 'kslkxjclkxjcdd'. "Returns 'dd'"

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - skip everything up to X

Lukas Renggli
I doubt this is generally useful. Sometimes you might want the skipped
input, sometimes you might want it as a token, sometimes as a trimmed
token, sometimes you need the end as a token, sometimes the end as a
trimmed token, sometimes both or a combination of any of the two.

Lukas

On 11 November 2010 20:36, Sean P. DeNigris <[hidden email]> wrote:

>
> What do you think of adding it to the API?
>
> Something like  http://forum.world.st/file/n3038839/PPParser-skipUntil.st
> PPParser-skipUntil.st :
>
> PPParser>>skipUntil
>
>        ^ self negate plus, self ==> [ :nodes | nodes second ].
>
> parser2 := 'dd' asParser skipUntil.
> parser2 parse: 'kslkxjclkxjcdd'. "Returns 'dd'"
>
>
> --
> View this message in context: http://forum.world.st/PetitParser-skip-everything-up-to-X-tp3038824p3038839.html
> Sent from the Moose mailing list archive at Nabble.com.
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>



--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - skip everything up to X

Sean P. DeNigris
Administrator
Lukas Renggli wrote
I doubt this is generally useful. Sometimes you might want the skipped
input, sometimes you might want it as a token, sometimes as a trimmed
token, sometimes you need the end as a token, sometimes the end as a
trimmed token, sometimes both or a combination of any of the two.
Okay, thanks for the reply.  I'm really enjoying PetitParser!

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser - skip everything up to X

Tudor Girba
In reply to this post by Lukas Renggli
+1

Doru


On 12 Nov 2010, at 03:40, Lukas Renggli wrote:

> I doubt this is generally useful. Sometimes you might want the skipped
> input, sometimes you might want it as a token, sometimes as a trimmed
> token, sometimes you need the end as a token, sometimes the end as a
> trimmed token, sometimes both or a combination of any of the two.
>
> Lukas
>
> On 11 November 2010 20:36, Sean P. DeNigris <[hidden email]> wrote:
>>
>> What do you think of adding it to the API?
>>
>> Something like  http://forum.world.st/file/n3038839/PPParser-skipUntil.st
>> PPParser-skipUntil.st :
>>
>> PPParser>>skipUntil
>>
>>        ^ self negate plus, self ==> [ :nodes | nodes second ].
>>
>> parser2 := 'dd' asParser skipUntil.
>> parser2 parse: 'kslkxjclkxjcdd'. "Returns 'dd'"
>>
>>
>> --
>> View this message in context: http://forum.world.st/PetitParser-skip-everything-up-to-X-tp3038824p3038839.html
>> Sent from the Moose mailing list archive at Nabble.com.
>> _______________________________________________
>> Moose-dev mailing list
>> [hidden email]
>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>>
>
>
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

--
www.tudorgirba.com

"No matter how many recipes we know, we still value a chef."







_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev