Hi,
I think I understand your problem. First, I would only use asn1Token in the Parser class
because you want the grammar to be as flexible as possible (even if sometimes appears as
an over-complication, it somehow proved to be always a good idea in the long run). The
cleanest solution is to rely on a new instance variable to distinguish between cases with
or without tokenizing.
If you hit the limit, you can create an intermediate SyntaxExtension class that can store
this. It is not ideal, but I think it solves the problem.
Another solution would be to externalize a part of the parser to another class.
Cheers,
Doru
On 30 Sep 2011, at 11:53, Norbert Hartl wrote:
Hi,
I want to ask if there is a elegant solution for the following problem:
In my grammar there are references (symbols/names that reference entities somewhere). One
is
Syntax>>typeReference
^ self failOnReservedWords: (
#uppercase asParser,
(#word asParser plus separatedBy: $- asParser) optional
) flatten
These typeReferences can be standalone tokens (parsed with a token parse class that
parses whitespaces and comments)
Syntax>>reference
^ typeReference asn1Token / valueReference asn1Token / ...
with
PPParser>>asn1Token
^ (ASN1TokenParser on: self) ==> [:node| node value]
or embedded in another type
Syntax>>valueSetFieldReference
^ $& asParser, typeReference
If have two classes, one for the syntax and for the parsing into model objects. Every
typeReference should be parsed in the parser class to
Parser>>typeReference
^ super typeReference ==> [:node|
ASN1ReferenceNode new name: node ]
The problem is that it is hard to have the typeReference be tokenized or not and make
sure they are all parsed to the ASNReferenceNode. The example above
Syntax>>reference
^ typeReference asn1Token / valueReference asn1Token / ...
does not work because typeReferences result is transformedd to the model class but the
asn1Token applied afterwards gives back a string again. I tried having a second parser
typeReferenceToken but that only works if I double the code of typeReference in syntax and
parser class. And as I am running short of instance variables I would prefer a solution
without having the need for creating new instance variables.
Any ideas?
I hope I could explain the problem enough to get you the context you need,
Norbert
_______________________________________________
Moose-dev mailing list
Moose-dev(a)iam.unibe.ch
https://www.iam.unibe.ch/mailman/listinfo/moose-dev
--
www.tudorgirba.com
"Problem solving should be focused on describing
the problem in a way that makes the solution obvious."