Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Possible to convert part of STRING to an object's ID using a value converter?
Possible to convert part of STRING to an object's ID using a value converter? [message #1830812] Tue, 04 August 2020 16:37 Go to next message
Tomas Öberg is currently offline Tomas ÖbergFriend
Messages: 14
Registered: February 2020
Junior Member
Is it possible to declare a variable within a STRING and then use a substring of that string as an cross reference later for the declaration (with the help of a value converter)?

Use case:
field "injected*PART_REMOVED_OR_MANIPULATED_IN_A_VALUE_CONVERTER";

class TestObject	
	injected {

	}
;

(Where the 'injected' field in TestObject is a cross reference to the earlier declared TemplateField declaration above the TestObject)
I'm thinking something along the following pseudo grammar here, but not sure how to do it since the TemplateField would require an ID but I still only want to provide a STRING for it to be able to use the pseudo code above:

TemplateField: 
	'field' name=STRING '{' '}'
;
ObjectDeclaration:
	'class' name=ID '{'
		field+=[TemplateField|ID]*
	'}' 
;


I have seen how to convert a STRING to an Integer using a value converter, but I'm not sure how to convert that into an ID if that field is missing in the EObject. Can perhaps an additional invisible ID be declared on the TemplateField that can be pick up cross references later?
Re: Possible to convert part of STRING to an object's ID using a value converter? [message #1830813 is a reply to message #1830812] Tue, 04 August 2020 16:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
i am not sure about the substring. can you be more precise with a complete example?
with the one you showed:
if you implement the value converter (or maybe better IQualifiedNameProvider) it should work fine.
https://dietrich-it.de/xtext/2011/07/16/iqualifiednameproviders-in-xtext-2.0/


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

[Updated on: Tue, 04 August 2020 17:02]

Report message to a moderator

Re: Possible to convert part of STRING to an object's ID using a value converter? [message #1830816 is a reply to message #1830813] Tue, 04 August 2020 17:43 Go to previous messageGo to next message
Tomas Öberg is currently offline Tomas ÖbergFriend
Messages: 14
Registered: February 2020
Junior Member
Alright, thanks for the link! a more complete example would be this, with the use case below. The substring thing I was talking about is a wildcard token for the template that I want to remove so I can preserve the cross reference.


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

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

Model:
	directives+=Directive*
	;

Directive:
	TemplateDeclaration|ClassDeclaration
;

TemplateDeclaration: 
	'template' name=STRING parameters+=Parameters 
	'{' 
		//... properties here		
	'}'
;

Parameters:
	'(' ID? (',' ID)* ')'
;

ClassDeclaration:
	'class' name=ID '{'
		templates+=Template*
	'}' 
;

Template:
	name=[TemplateDeclaration|ID] parameters+=Parameters '{'
		//...properties
	'}'
;






Usage with wildcard that should be ignored:

template "test*" (arg1, arg2) {
	   //...properties here	
	
}

class TestClass {
	test(parameter1, parameter2) {
	    //...properties here
		
	}
} 

[Updated on: Tue, 04 August 2020 18:13]

Report message to a moderator

Re: Possible to convert part of STRING to an object's ID using a value converter? [message #1830819 is a reply to message #1830816] Tue, 04 August 2020 19:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13628
Registered: July 2009
Senior Member
In this case adopting the name provider should work

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: Possible to convert part of STRING to an object's ID using a value converter? [message #1830823 is a reply to message #1830819] Tue, 04 August 2020 20:41 Go to previous message
Tomas Öberg is currently offline Tomas ÖbergFriend
Messages: 14
Registered: February 2020
Junior Member
It did! And much easier than I thought it would be. Thanks a lot!
Previous Topic:Synchronize changes from the Model to the Embedded Editor in Xtext
Next Topic:Support of OSGI DS 1.3 annotations in Xtend?
Goto Forum:
  


Current Time: Fri Oct 23 01:04:32 GMT 2020

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

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

Back to the top