Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Merge cross-reference
Merge cross-reference [message #665432] Thu, 14 April 2011 15:22 Go to next message
Nela is currently offline NelaFriend
Messages: 2
Registered: April 2011
Junior Member
Hello,

I was wondering how can I merge two or more cross-references.

For illustration - I'm trying this (very simplified version of my grammar):

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Line:
  (line += ( Name1 | Name2 |Usage))*;
  
Name1:
	'NAME1' name=ID;
	
Name2:
	'NAME2' name=ID;

Usage:
	(named1=[Name1] | named2=[Name2]);


It ends up with Antl warning:
warning(200): ../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/p arser/antlr/internal/InternalMyDsl.g:286:1: Decision can match input such as "RULE_ID" using multiple alternatives: 1, 2
As a result, alternative(s) 2 were disabled for that input
warning(201): ../org.xtext.example.mydsl/src-gen/org/xtext/example/mydsl/p arser/antlr/internal/InternalMyDsl.g:286:1: The following alternatives are unreachable: 2

And then the validation doesn't work well.

I need to keep definitions of Name1 and Name2 separated, because sometimes I reference it alone. But I need to propose (and validate) it merged, too.

Is there any way how to define it correctly in the grammar? Or can I solve it only programmatically?

Thanks for your advice, I'm totally newbie.

Nela
Re: Merge cross-reference [message #665443 is a reply to message #665432] Thu, 14 April 2011 15:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

this is not possible with Xtext. But why don't you change the grammar to:
Name1or2: Name1|Name2;
Usage: name1or2=[Name1or2];


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Merge cross-reference [message #665463 is a reply to message #665443] Thu, 14 April 2011 17:01 Go to previous message
Nela is currently offline NelaFriend
Messages: 2
Registered: April 2011
Junior Member
Thank you, this works for me. Very nice.

Nela
Previous Topic:XText
Next Topic:Unable to install Xtext
Goto Forum:
  


Current Time: Thu Apr 25 05:25:33 GMT 2024

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

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

Back to the top