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) Thanks, Peter |
Yes, the #any asParser star consume all your stream. for your example you can do: str := 'a0b'. #digit asParser negate star, #digit asParser, #any asParser star parse: str. 2017-01-20 15:24 GMT+01:00 Peter Uhnak <[hidden email]>: Is PetitParser eager by default? Guillaume Larcheveque
|
In reply to this post by Peter Uhnak
> Am 20.01.2017 um 15:24 schrieb Peter Uhnak <[hidden email]>: > > 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 Norbert |
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: Cheers, Doru On Jan 20, 2017, at 4:38 PM, Norbert Hartl <[hidden email]> wrote:Am 20.01.2017 um 15:24 schrieb Peter Uhnak <[hidden email]>: |
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 <[hidden email]>: > >> > >> 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 |
In reply to this post by Tudor Girba-2
Hi doru where do we see it? Stef On Fri, 20 Jan 2017 16:57:51 +0100, Tudor Girba <[hidden email]> wrote: Hi, -- Using Opera's mail client: http://www.opera.com/mail/ |
Hi,
The inspector shows the PPFailure, and the Debug View presentation of PPFailure shows you the paths the parser tried. star produces a PPPossessiveRepeatingParser, and selecting it shows that it matched all three characters: they are selected in the bottom pane which shows the input string. Cheers, Doru > On Jan 21, 2017, at 11:26 AM, stepharong <[hidden email]> wrote: > > Hi doru > > where do we see it? > > > Stef > > On Fri, 20 Jan 2017 16:57:51 +0100, Tudor Girba <[hidden email]> 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: > > <Mail Attachment.png> > > Cheers, > Doru > > >> On Jan 20, 2017, at 4:38 PM, Norbert Hartl <[hidden email]> wrote: >> >> >>> Am 20.01.2017 um 15:24 schrieb Peter Uhnak <[hidden email]>: >>> >>> 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 >> >> Norbert >> >> > > -- > www.tudorgirba.com > www.feenk.com > > "What we can governs what we wish." > > > > > > > > -- > Using Opera's mail client: http://www.opera.com/mail/ -- www.tudorgirba.com www.feenk.com “The smaller and more pervasive the hardware becomes, the more physical the software gets." |
tx
On Sat, 21 Jan 2017 18:09:32 +0100, Tudor Girba <[hidden email]> wrote: > Hi, > > The inspector shows the PPFailure, and the Debug View presentation of > PPFailure shows you the paths the parser tried. > > star produces a PPPossessiveRepeatingParser, and selecting it shows that > it matched all three characters: they are selected in the bottom pane > which shows the input string. > > Cheers, > Doru > > >> On Jan 21, 2017, at 11:26 AM, stepharong <[hidden email]> wrote: >> >> Hi doru >> >> where do we see it? >> >> >> Stef >> >> On Fri, 20 Jan 2017 16:57:51 +0100, Tudor Girba <[hidden email]> >> 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: >> >> <Mail Attachment.png> >> >> Cheers, >> Doru >> >> >>> On Jan 20, 2017, at 4:38 PM, Norbert Hartl <[hidden email]> wrote: >>> >>> >>>> Am 20.01.2017 um 15:24 schrieb Peter Uhnak <[hidden email]>: >>>> >>>> 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 >>> >>> Norbert >>> >>> >> >> -- >> www.tudorgirba.com >> www.feenk.com >> >> "What we can governs what we wish." >> >> >> >> >> >> >> >> -- >> Using Opera's mail client: http://www.opera.com/mail/ > > -- > www.tudorgirba.com > www.feenk.com > > “The smaller and more pervasive the hardware becomes, the more physical > the software gets." > -- Using Opera's mail client: http://www.opera.com/mail/ |
Free forum by Nabble | Edit this page |