PetitParser, same character multiple times

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

PetitParser, same character multiple times

Alberto Bacchelli
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
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Alberto Bacchelli

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-times-tp2412918p2412957.html
Sent from the moose-dev mailing list archive at Nabble.com.
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Fabrizio Perin
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-times-tp2412918p2412957.html
> Sent from the moose-dev mailing list archive at Nabble.com.
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Alberto Bacchelli
In reply to this post by Alberto Bacchelli
PPRepeatingParser is indeed how the 'plus' method is implemented for example.
The problem is that, by specifying
#letter asParser
I accept any kind of letter, thus
#letter asParser plus
accepts any number of any kind of letters.

The problem is that I need to accept only multiple occurrences of the same letter :)

I could do something like:

$a asParser plus / $b asParser plus / ...

but that's not really nice code :)

Anyway, thanks for the help!


On Feb 3, 2011, at 1:38 PM, Fabrizio Perin wrote:

> 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-times-tp2412918p2412957.html
>> Sent from the moose-dev mailing list archive at Nabble.com.
>> _______________________________________________
>> Moose-dev mailing list
>> [hidden email]
>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Lukas Renggli
In reply to this post by Alberto Bacchelli
$a min: n

On 3 February 2011 13:01, Alberto Bacchelli <[hidden email]> 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
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>



--
Lukas Renggli
www.lukas-renggli.ch

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Fabrizio Perin
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 <[hidden email]> 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
>> [hidden email]
>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>>
>
>
>
> --
> Lukas Renggli
> www.lukas-renggli.ch
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Alberto Bacchelli
In reply to this post by Lukas Renggli

$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-times-tp2412918p2413473.html
Sent from the moose-dev mailing list archive at Nabble.com.
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Tudor Girba
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-times-tp2412918p2413473.html
> Sent from the moose-dev mailing list archive at Nabble.com.
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

--
www.tudorgirba.com

"Presenting is storytelling."


_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Lukas Renggli
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 <[hidden email]> 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-times-tp2412918p2413473.html
>> Sent from the moose-dev mailing list archive at Nabble.com.
>> _______________________________________________
>> Moose-dev mailing list
>> [hidden email]
>> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>
> --
> www.tudorgirba.com
>
> "Presenting is storytelling."
>
>
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
>
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Nicolas Anquetil
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" <[hidden email]>
> À: "Moose-related development" <[hidden email]>
> 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 <[hidden email]>
> 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-times-tp2412918p2413473.html
> >> Sent from the moose-dev mailing list archive at Nabble.com.
> >> _______________________________________________
> >> Moose-dev mailing list
> >> [hidden email]
> >> https://www.iam.unibe.ch/mailman/listinfo/moose-dev
> >
> > --
> > www.tudorgirba.com
> >
> > "Presenting is storytelling."
> >
> >
> > _______________________________________________
> > Moose-dev mailing list
> > [hidden email]
> > https://www.iam.unibe.ch/mailman/listinfo/moose-dev
> >
> _______________________________________________
> Moose-dev mailing list
> [hidden email]
> https://www.iam.unibe.ch/mailman/listinfo/moose-dev

_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
Reply | Threaded
Open this post in threaded view
|

Re: PetitParser, same character multiple times

Lukas Renggli
On 3 February 2011 18:30, Nicolas Anquetil <[hidden email]> 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

--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
Moose-dev mailing list
[hidden email]
https://www.iam.unibe.ch/mailman/listinfo/moose-dev