Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Not valid for cross reference
Not valid for cross reference [message #1839377] Fri, 19 March 2021 15:16 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi all,
I have the following grammar:


Element:
name="element"
;
Type:
A | B | C
;
A:
name=ID
;
B:
name=ID
;
C:
name=ID
;
Machine:
name = ID find = [Type | Element]

However, I get the following error:
The rule 'Element' is not valid for a cross reference since it
does not return an EString. You'll have to wrap it in a data
type rule.

Any idea on how to solve that?

Thanks,
John
Re: Not valid for cross reference [message #1839384 is a reply to message #1839377] Fri, 19 March 2021 16:26 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14666
Registered: July 2009
Senior Member
find = [Type | Element] means reference a Type and Parse an Element.
do you mean Type or Element? then you need a common rule: TypeOrElement: Type|Element; find=[TypeOrElement|ID] ir short find=[TypeOrElement]
or just type which would be find=[Type|ID]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Not valid for cross reference [message #1839409 is a reply to message #1839384] Sat, 20 March 2021 11:27 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Christian,

If I try to follow your approach by having the following grammar:

Element:
name="element"
;
Type:
A | B | C
;
A:
name=ID
;
B:
name=ID
;
C:
name=ID
;
TypeorElement:
Type | Element
;
Machine:
name = ID find = [TypeorElement]

I get this error:

Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2, 3.
I believe this is because A,B,C are identified by an ID and Xtext will now know if what we are writing belong to A,B, or C. How could it work in this case? Without changing the ID for A,B,C.

Furthermore, one other thing is that A,B,C are reachable from the root rule, while Element is not. I want to say that the rule Element has this specific keyword "element", and when I am at the rule Machine, I will either get suggestions for the names of A,B,C which I have defined prior, or the "element" suggestion.

Hope this is clear enough :)

Thank you!

[Updated on: Sat, 20 March 2021 11:27]

Report message to a moderator

Re: Not valid for cross reference [message #1839412 is a reply to message #1839409] Sat, 20 March 2021 12:15 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14666
Registered: July 2009
Senior Member
Your rules A B C are identical and thus ambiguous

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Not valid for cross reference [message #1839413 is a reply to message #1839412] Sat, 20 March 2021 12:24 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Yes, but I cannot change that, so would there be a solution in this case so that find can consider both the Type and Element ?
Re: Not valid for cross reference [message #1839415 is a reply to message #1839413] Sat, 20 March 2021 15:23 Go to previous message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14666
Registered: July 2009
Senior Member
As I said. The Problem is a b c and not type element

Consider this model

z

Is this an a or a b or a c

You may also need a

MY_ID: ID|"element";

And then use thiamine in the by clause of the reference

name = ID find = [TypeorElemement|MY_ID]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 20 March 2021 17:36]

Report message to a moderator

Previous Topic:How to get xtext comment information?
Next Topic:Grammar ambiguity
Goto Forum:
  


Current Time: Fri Apr 26 16:34:32 GMT 2024

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

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

Back to the top