kursjan / petitparser2

A high-performance top-down parser
MIT License
41 stars 17 forks source link

Skip-Until #59

Open seandenigris opened 4 years ago

seandenigris commented 4 years ago

I had suggested this API addition to the original PP after repeatedly needing it:

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

To be used like:

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

Do we now have this with island parsing, or could this be a useful addition?

kursjan commented 4 years ago

Hi Sean, that sounds like a nice extension.

I find 'dd' asPParser skipUntil a bit unintuitive. Would something like #any asPParser skipUntil: 'dd' asPParser work for as well? It's clearer for me what I want, but the syntax is longer. Maybe 'dd' asPParser skipAnyUntil 🤔. But that sounds as good as skipUntil... 🤷

I will add it as soon as I figure out why Pharo stopped rendering properly my Chromebook (yes, I use chromebook 🙄)

seandenigris commented 3 years ago

I wonder if this is still needed now that we have island parsing, @kursjan. Thoughts? I guess this is slightly different in that it only considers sea before and not necessarily after...