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