On Fri, Jan 20, 2017 at 04:57:51PM +0100, Tudor Girba wrote:
Hi,
When you have questions like these, you can also use the built-in debugging facilities. For example, in your case, you can see that the #any parser consumed everything like this:
Ah, thanks. I was looking for this in the debugger (because I remember there was some extension related to PetitParser) and completely missed it in the playground.
Am 20.01.2017 um 15:24 schrieb Peter Uhnak <i.uhnak@gmail.com>:
Is PetitParser eager by default?
I've used PetitParser countless times so I am really baffled why this doesn't work
str := 'a0b'. #any asParser star, #digit asParser, #any asParser star parse: str.
-> PPFailure (input expected at: 3)
PetitParser is not greedy per default. But back tracking only works if a parser fails. Using , creates a sequence of combined parsers. If one fails the whole sequence fails. As a star parser always succeeds it would be huge luck if your rule would succeed. The probability that the parser consumes exactly one character is not high. Maybe negating the first sequence part is what you want
This is not just about one character. s := 'hello 123 world'. #any asParser star , #digit asParser plus , #any asParser star parse: s. But from your explanation my understanding is that this is actually not possible with #any. Basically I was looking for the PetitParser equivalent of .*?\d+.* regex (note that even in greedy form the regex wouldn't fail because it would leave the last digit for \d) Peter