If you know what you do then parsers can have side-effects:
| head tail char |
head := #any asParser ==> [ :c | char := c ].
tail := PPPredicateObjectParser
on: [ :c | char = c ]
message: 'same expected'.
parser := head , (tail min: n - 1).
Alternative you can modify the grammar itself on the fly:
| head tail |
head := #any asParser ==> [ :c | tail setParser: c asParser. c ].
tail := PPDelegateParser new.
parser := head , (tail min: n - 1).
Cheers,
Lukas
On Thursday, 3 February 2011, Tudor Girba <tudor.girba(a)gmail.com> wrote:
As far as I understand, you would want something that
parses any of the following:
"aa"
"bb"
"cc"
"dd"
The simplest way would be something like:
($a asParser , $a asParser) / ($b asParser , $b asParser) ...
The problem is that this will result in many objects and redundant checks.
I think I would implement it as a specialization of PPPredicateSequenceParser in which
you store the first element, and add the extra condition that any of the following
elements must be the same.
Cheers,
Doru
On 3 Feb 2011, at 14:23, sback wrote:
$a asParser min: n
is fine for one character, but what if I want to specify that I want
any character, or digit, repeated at least n times?
I could do:
($a asParser min: n) / ($b asParser min: n) / ...
but that would be a bit ugly :)
Thanks
--
View this message in context:
http://moose-dev.97923.n3.nabble.com/PetitParser-same-character-multiple-ti…
Sent from the moose-dev mailing list archive at
Nabble.com.
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
--
www.tudorgirba.com
"Presenting is storytelling."
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev