PetitParser: Parse recursive blocks

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

PetitParser: Parse recursive blocks

Alberto Bacchelli
Hi all,

 I am trying to parse recursive blocks, i.e., blocks that can contain other sub-blocks, by using PetitParser.

This is how I would do it:

blockParser := ${ asParser, ( blockParser / ( ($} asParser) not, #any asParser)) star, $} asParser

It works, but I am not sure it is the most convenient way.

Could I have your opinion?

Thank you,
 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: Parse recursive blocks

Lukas Renggli
Hi Alberto,

You need some kind of recursive grammar to match each opening token
with its closing one. So in the most simple form this is usually
written something along the following code:

   block := open , block , close
             / something.

Of course you cannot directly write that in Smalltalk like this,
because 'block' is defined and used in the same expression. So you
need something along:

   block := PRUndefinedParser new.
   block def: open , block , close / something.

Also look at PPComposedTest, there are various tests that exercise
these kind of recursive grammars.

Cheers,
Lukas

On 17 November 2010 12:03, Alberto Bacchelli <[hidden email]> wrote:

> Hi all,
>
>  I am trying to parse recursive blocks, i.e., blocks that can contain other sub-blocks, by using PetitParser.
>
> This is how I would do it:
>
> blockParser := ${ asParser, ( blockParser / ( ($} asParser) not, #any asParser)) star, $} asParser
>
> It works, but I am not sure it is the most convenient way.
>
> Could I have your opinion?
>
> Thank you,
>  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