Home » Modeling » TMF (Xtext) » Cross-referencing two different rules?
Cross-referencing two different rules? [message #1841696] |
Tue, 25 May 2021 21:31 |
M D Messages: 33 Registered: January 2021 |
Member |
|
|
I have a rule that has feature value. I want value to be a cross-reference to either Object or Array. Both shall use STRING_WITH_TOKENS.
ReferenceDataType:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"type"' ':' '"reference"' ','
// '"value"' ':' (value = [Object|STRING_WITH_TOKENS] | value = [Array|STRING_WITH_TOKENS])
'}'
;
This, however, gives: Decision can match input such as "RULE_STRING_WITH_TOKENS" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
The following alternatives can never be matched: 2
Don't really see the problem, as both Object and Array differs. Backtrack lexer is set to true.
The grammar is here:
Element:
Object | Array | Alternative | Attribute
;
Object:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"name"' ':' name = STRING_WITH_TOKENS ','
'"type"' ':' '"object"' ','
'"isOptional"' ':' isOptional = BOOLEAN ','
'"children"' ':' '[' elements += Element? (',' elements += Element)* ']' ','
'"dataTypes"' ':' '[' ']'
'}'
;
Array:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"name"' ':' name = STRING_WITH_TOKENS ','
'"type"' ':' '"array"' ','
'"isOptional"' ':' isOptional = BOOLEAN ','
'"children"' ':' '[' elements += Element? (',' elements += Element)* ']' ','
'"dataTypes"' ':' '[' ']'
'}'
;
Alternative:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"name"' ':' name = STRING_WITH_TOKENS ','
'"type"' ':' '"alternative"' ','
'"isOptional"' ':' isOptional = BOOLEAN ','
'"children"' ':' '[' elements += Element? ']' ','
'"dataTypes"' ':' '[' dataTypes += DataType (',' dataTypes += DataType)* ']'
'}'
;
Attribute:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"name"' ':' name = STRING_WITH_TOKENS ','
'"type"' ':' '"attribute"' ','
'"isOptional"' ':' isOptional = BOOLEAN ','
'"children"' ':' '[' ']' ','
'"dataTypes"' ':' '[' dataType = DataType ']'
'}'
;
DataType:
CustomDataType | PredefinedDataType | ReferenceDataType
;
CustomDataType:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"type"' ':' '"custom"' ','
'"value"' ':' value = [Rule|STRING_WITH_TOKENS]
'}'
;
PredefinedDataType:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"type"' ':' '"predefined"' ','
'"value"' ':' value = PREDEFINED_TYPE
'}'
;
ReferenceDataType:
'{'
'"column"' ':' column = INT ','
'"row"' ':' row = INT ','
'"type"' ':' '"reference"' ','
'"value"' ':' (value = [Object|STRING_WITH_TOKENS] | value = [Array|STRING_WITH_TOKENS])
'}'
;
[Updated on: Tue, 25 May 2021 21:32] Report message to a moderator
|
|
|
Re: Cross-referencing two different rules? [message #1841699 is a reply to message #1841696] |
Wed, 26 May 2021 04:21 |
|
Grammar wise
// '"value"' ':' (value = [Object|STRING_WITH_TOKENS] | value = [Array|STRING_WITH_TOKENS])
Is the same as
// '"value"' ':' (value =STRING_WITH_TOKENS | value = STRING_WITH_TOKENS
Which should give you an idea why it is ambiguous
So you have basically two options
(A) have different syntaxes for both refs
(B) have only on ref
ArrayOrObject: Array|Object; //new rule , uncalled , to introduce common supertype
':' (value = [ArrayOrObject|STRING_WITH_TOKENS]
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
|
|
| |
Goto Forum:
Current Time: Wed Dec 11 19:15:10 GMT 2024
Powered by FUDForum. Page generated in 0.03648 seconds
|