Hi all,
Is there an easy way to define the equivalent of the following regular expression in PetitParser?
a{n,}
which that the character 'a' must appear at least n times.
Thank you!
Cheers, Alberto
To be more precise, I cannot use
#letter plus
because this would imply that I can both parse:
'aa', which is correct; but also: 'ab', which is not correct.
I need a way to specify that I want the same letter, or character, to be repeated.
Thank you, Alberto
Hi, I did never use it but i found in PetitParser-Parsers this parser PPRepeatingParser that maybe can solve your problem.
Cheers,
Fabrizio
On 3 Feb 2011, at 13:09, sback wrote:
To be more precise, I cannot use
#letter plus
because this would imply that I can both parse:
'aa', which is correct; but also: 'ab', which is not correct.
I need a way to specify that I want the same letter, or character, to be repeated.
Thank you, Alberto -- View this message in context: http://moose-dev.97923.n3.nabble.com/PetitParser-same-character-multiple-tim... Sent from the moose-dev mailing list archive at Nabble.com. _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
$a min: n
On 3 February 2011 13:01, Alberto Bacchelli alberto.bacchelli@usi.ch wrote:
Hi all,
Is there an easy way to define the equivalent of the following regular expression in PetitParser?
a{n,}
which that the character 'a' must appear at least n times.
Thank you!
Cheers, Alberto _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
On 3 Feb 2011, at 13:55, Lukas Renggli wrote:
$a min: n
Cool, yes my idea was something like:
PPRepeatingParser on: $a asParser min: anInteger.
But i see that you already putted some sugar.
Cheers,
Fabrizio
On 3 February 2011 13:01, Alberto Bacchelli alberto.bacchelli@usi.ch wrote:
Hi all,
Is there an easy way to define the equivalent of the following regular expression in PetitParser?
a{n,}
which that the character 'a' must appear at least n times.
Thank you!
Cheers, Alberto _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
-- Lukas Renggli www.lukas-renggli.ch
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
$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
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-tim... Sent from the moose-dev mailing list archive at Nabble.com. _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
-- www.tudorgirba.com
"Presenting is storytelling."
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@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-tim... Sent from the moose-dev mailing list archive at Nabble.com. _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
-- www.tudorgirba.com
"Presenting is storytelling."
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
not much to do with the real topic, but just wanted to nastily point out that this is not a regular expression. :-)
You can specify that you want a particular character repeated (a+), or that you want anycharacter several repeated (.+) But I believe regular expression don't allow you to say whatever character comes may be repeated and only this one ...
nic nitpicking
----- Mail original -----
De: "Lukas Renggli" renggli@gmail.com À: "Moose-related development" moose-dev@iam.unibe.ch Envoyé: Jeudi 3 Février 2011 18:00:18 Objet: [Moose-dev] Re: PetitParser, same character multiple times 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@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-tim... Sent from the moose-dev mailing list archive at Nabble.com. _______________________________________________ Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
-- www.tudorgirba.com
"Presenting is storytelling."
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Moose-dev mailing list Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev
On 3 February 2011 18:30, Nicolas Anquetil nicolas.anquetil@inria.fr wrote:
not much to do with the real topic, but just wanted to nastily point out that this is not a regular expression. :-)
PetitParser is not about regular expressions, it parses a much larger set of languages. For example, languages like a^n b^n or a^b b^n c^n cannot be detected by regular expressions.
You can specify that you want a particular character repeated (a+), or that you want anycharacter several repeated (.+) But I believe regular expression don't allow you to say whatever character comes may be repeated and only this one ...
No, this is not true. Most today's regular expression engines support back-references and can easily implement the discussed language:
(.)\1{n}
Lukas