Hi,
I have a DSL looking like this:
a: ...
b: ...
c: ...
c: ...
d: ...
a: ...
b: ...
a: ...
'a:' defines the top elements which can be followed by other a-rules or they can contain b-rules as childrens. In the same way b-rules can only contain c-rules and so on. The deepest allowed letter is q.
All those rules are similar and should be mapped to the same java class. But now i have trouble to define a recursive grammar which maps these rules to children.
There are three situations on which the handling depends:
Adoption: We processed an a-rule and now we go on
Case 1: The next rule uses the next letter (b) and should therefore be stored in a children list of the current a-rule.
Case 2: The next rule is below the next letter (c or behind) which means this is a syntax error!
Case 3: The next rule is a rule of the same letter (a) or a letter above (not possible in this depth). In this case the a-rule is completely parsed and we can continue with the new a-rule which we have just discovered.
I have no idea how to write a grammar for this situation. I might need something like this:
Rule:
depth=RULE_DEPTH content=STRING
// add rule as children only when depth is current+1
children+=(Rule r matching r.depth==this.depth+1)*
;
terminal RULE_DEPTH returns ecore::EInt : ('a'..'q') ':'; // <- convert to numbers: a=1, b=2...
I'm not quite sure whether this is possible with xtext anyway, but probably someone knows better?