Am 07.06.2011 um 15:46 schrieb Lukas Renggli:
PPCompositeParser has its limits. I hate the instance
variable mess,
but it kind of makes it convenient to refer to other productions.
In Helvetia there is a different implementation of PPCompositeParser
that works with the same grammar source but compiles variable accesses
to use a dictionary instead. This then scales to an almost infinite
number of productions. I agree that introducing the Helvetia
dependendency is not feasible though.
Well, it might be feasible for me :) I downloaded the Helvetia one-click and
couldn't find the different impementation of PPCompositeParser.
I wonder if we could use some other trick that
wouldn't require a
custom compiler and that would work across platforms?
That would be wonderful. The only cross-platform trick that I know is adding
"self" in front of a ruleName :)
Another way
would be to access some of the parser via method calls instead of accessing the instVar
parsers.
That is a possiblity, if they don't depend on each other circularly
and if you don't mind the object duplication.
I think that is my only chance at the moment.
Also you can build your productions more imperatively
(like in many
examples and the tests you see floating around) instead of purely
declaratively as it is mostly done with PPCompositeParser.
I have to look into this. As I have more than 254 rules it means the grammer is
rather complex. One reason I would like to do it in a declarative fashion because I think
it increases maintainability.
So does
anybody has some experience in how to structure parsers?
Typically grammars are quite clustered and have complex leaf nodes
(the tokens in general, string and number literals, comments, etc.)
that can be factored out.
That is what I did. I factored out the leaf rules into a base class before I
encountered the problem. I'm using an ugly approach now. I include a delegate in
parser that contains the basic type rules. In my parser I have rules that need to be
changed from
^ bString / hString / definedValue
to
^ basicType bString / basicType hString / definedValue
I don't really like it and it makes the usage of the petit parser UI more cumbersome.
But it is the best thing at the moment that lets me proceed.
Norbert
Cheers,
Lukas
--
Lukas Renggli
www.lukas-renggli.ch
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev