Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Cross-referencing two different rules?
Cross-referencing two different rules? [message #1841696] Tue, 25 May 2021 21:31 Go to next message
M D is currently offline M DFriend
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14736
Registered: July 2009
Senior Member
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
Re: Cross-referencing two different rules? [message #1841796 is a reply to message #1841699] Sun, 30 May 2021 09:13 Go to previous message
M D is currently offline M DFriend
Messages: 33
Registered: January 2021
Member
Thanks!
Previous Topic:Git / Maven Setup for standalone build
Next Topic:Using the Xtext.xtext grammar in another DSL gives "Couldn't resolve reference to EClassifier&q
Goto Forum:
  


Current Time: Wed Dec 11 19:15:10 GMT 2024

Powered by FUDForum. Page generated in 0.03648 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top