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 alberto.bacchelli@usi.ch 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 Moose-dev@iam.unibe.ch https://www.iam.unibe.ch/mailman/listinfo/moose-dev