The trick doesn't work for a rule that may be consumed without object instantiation [message #1787156] |
Sun, 20 May 2018 10:39 |
Alex Mising name Messages: 149 Registered: March 2010 |
Senior Member |
|
|
Hello,
So I came across what seems to be a common issue as searching yields lots of questions on it, the message:
The rule 'BlockType' may be consumed without object instantiation. Add an action to ensure object creation, e.g. '{BlockType}'.
Basically, all answers just say "add {rulename}" and the reply is "oh thanks, it works" but in my case it doesn't. See self-contained grammar for my case.
grammar org.thisAndThat.dsl.SbeDsl with org.eclipse.xtext.common.Terminals
generate thatThatDsl "http://www.thisAndThat.org/dsl/thatThatDsl"
Specification:
As = TheAs Bs=TheBs;
TheAs:
'theAs' '{' (theAs+=A)+ '}';
TheBs:
'theBs' '{'(theBs+=B)+ '}';
A:
'a' name=Name;
B:
'b' name=Name '{'
block=BlockType
'}';
BlockType: {BlockType}
(thisFields+=This)* | (thatFields+=That)*;
This:
'this' name=Name ':' type=[A];
That:
'that' name=Name ':' type=[A];
Name:
ID;
I would appreciate if you would explain what exactly is happening under the hood as it seems like nobody really goes into the subject... From what I gather, each rule creates an object of some (generated) type under the hood, so the fact that there are two optional (*) groups (thisFields and thatFields) means that "it may be consumed without object instantiation". Indeed, forcing "thatFields" makes the warning go away:
BlockType: {BlockType}
(thisFields+=This)* | (thatFields+=That)+;
However, forcing "thisFields" does not have the same effect, as the below makes the warning persist:
BlockType: {BlockType}
(thisFields+=This)+ | (thatFields+=That)*;
In reality however, I don't want my grammar to require the presence of "that": it should be possible to have only "this" or only "that" or both.
1) What is the implication of this warning if I leave BlockType as-is?
2) If I wanted to only exclude the ABSENCE of both, I would need to do that outside the grammar with custom validation, correct?
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02904 seconds