petitparser2 icon indicating copy to clipboard operation
petitparser2 copied to clipboard

Skip-Until

Open seandenigris opened this issue 4 years ago • 2 comments

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?

seandenigris avatar Apr 17 '20 14:04 seandenigris

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 🙄)

kursjan avatar May 17 '20 20:05 kursjan

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...

seandenigris avatar Dec 13 '20 16:12 seandenigris