Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Terminal Rule Token based on previous crossreference
Terminal Rule Token based on previous crossreference [message #1745587] Wed, 12 October 2016 19:06 Go to next message
Matt Se is currently offline Matt SeFriend
Messages: 29
Registered: February 2016
Junior Member
Hi,

I have a grammar which kinda looks like this
Element returns datatypes::Element:
	{datatypes::Element}
	(refVars+=[wrapper::Variable|QualifiedName] ':' TYPE_NAME)* /*the typename should equal to variable.type.name*/
;
Variable returns datatypes::Variable:
	{datatypes::Variable}
        name=EString
	type=[ecore::EObject|EString] /* the info about the name is relevent for the crossreference*/
;

terminal TYPE_NAME:
	'DOUBLE' | 'INT' | 'LONG'
;


So my element has references to a Variable, which has a specific type.
Now I want to display the name of the type after the crossreference, but only display and not assign another crossreference.
I tried this with a terminal rule.

And found my generated org.eclipse.xtext.serializer.sequencer.AbstractSyntacticSequencer a method which looks like this:
	protected String getTYPE_NAMEToken(EObject semanticObject, RuleCall ruleCall, INode node) {

		if (node != null)
			return getTokenText(node);
		return "DOUBLE";
	}


now I can return a specific String based on the semanticObject, but the semantic EObject is always the Element Object and I'm not able to identify to the Variable for which I return the String. Since the node is always null I can't figure out the current crossreference assignment.

How can display (only display, not assign anything) a specific String after a corssreference?

Many thanks in advance

[Updated on: Wed, 12 October 2016 19:13]

Report message to a moderator

Re: Terminal Rule Token based on previous crossreference [message #1745589 is a reply to message #1745587] Wed, 12 October 2016 19:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
Is this a question on the serialzation only?

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Terminal Rule Token based on previous crossreference [message #1745607 is a reply to message #1745589] Thu, 13 October 2016 09:14 Go to previous messageGo to next message
Matt Se is currently offline Matt SeFriend
Messages: 29
Registered: February 2016
Junior Member
Yes, I need to know to tell the sequencer which specific token for a terminal rule should be serialized based on a previous cross-reference.
Is that possible, or is my approach with a terminal rule not suitable?
Re: Terminal Rule Token based on previous crossreference [message #1745615 is a reply to message #1745607] Thu, 13 October 2016 11:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
simply add getTYPE_NAMEToken to the workflow should give you a place where you can manually implement org.xtext.example.mydsl3.serializer.AbstractMyDslSyntacticSequencer.getTYPE_NAMEToken(EObject, RuleCall, INode)

there you have access to the semantic object and can query the information you need cant you?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Terminal Rule Token based on previous crossreference [message #1745624 is a reply to message #1745615] Thu, 13 October 2016 13:38 Go to previous messageGo to next message
Matt Se is currently offline Matt SeFriend
Messages: 29
Registered: February 2016
Junior Member
Thx, I did that already, but unfortunately I can't access any context information about the actual crossreference for which the getTYPE_NAMEToken is called, because the semanticElement is not the referenced eobject, but the owner of the cross-reference...

But I think I kinda solved it, I wrapped it in a Datatype rule like:

QualifiedName:
EString ':' TYPE_NAME;

and then introduced a qualifiedname provider for the Variable class, which returns a string like QualifiedName.

I believe that's the better approach in this case.
Re: Terminal Rule Token based on previous crossreference [message #1745630 is a reply to message #1745624] Thu, 13 October 2016 15:35 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13887
Registered: July 2009
Senior Member
Alternatively you could put the ref type pair to a own object

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/it-services/methods-and-tools/xtext
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Default Ordering of XText Content Assistant
Next Topic:Odd problem with terminal ID
Goto Forum:
  


Current Time: Tue Apr 20 11:03:17 GMT 2021

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

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

Back to the top