Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » XText Get original String from AST(Access the original string while generating code)
XText Get original String from AST [message #1746590] Tue, 01 November 2016 14:09 Go to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Hi there,

I am generating a matlab script using XText 2.9 from a requirement specification which looks like this:

requirement: {
	id: FORMAL_req_id
	description: Formal Requirement Description which is split up in many tokens
}


The Matlab script shall contain a comment with the original description.

How can I access it in the code generator.

Since XText is able to translate from grammar to AST and the other way round there shure must be a possibility

Thanks in advance.

Lukas
Re: XText Get original String from AST [message #1746591 is a reply to message #1746590] Tue, 01 November 2016 14:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
first question: why is the description not in the AST. there must be something insufficient in the grammar.
else have a look at NodeModelUtils. it allows you access to nodes which give your your original text.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Get original String from AST [message #1746602 is a reply to message #1746591] Tue, 01 November 2016 15:37 Go to previous messageGo to next message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Christian Dietrich wrote on Tue, 01 November 2016 14:14
first question: why is the description not in the AST. there must be something insufficient in the grammar.
else have a look at NodeModelUtils. it allows you access to nodes which give your your original text.


I am not shure how i should define the grammar in order to do that...

my grammar looks like this:
Root:
	(elements+=Element)*
;

Element:
	SignalDefinition | ParameterDefinition | Requirement
;

Requirement:
	'requirement:' '{'
		name=ID
		requirementDescription = RequirementDescription
	'}' 
;
RequirementDescription:
	(whileReq=While)? nestedDescription=NestedDescription
;

NestedDescription:
	(When | Ubiquitous)
;

	While:
		('WHILE' stateTrigger=StateTrigger)
	;

       Ubiquitous:
		'THE' systemName=SystemName 'SHALL' intervalSystemResponse=IntervalSystemResponse
	;

	When:
		'WHEN' expression=Expression eventTrigger=EventTrigger 
			'THE'  systemName=SystemName 'SHALL' eventSystemResponse=EventSystemResponse
	;


As for your hint. I dont know how to get an INode Object. I generate everything from this object that contains my AST
var Root root = resource.contents.head as Root

Re: XText Get original String from AST [message #1746606 is a reply to message #1746602] Tue, 01 November 2016 16:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14661
Registered: July 2009
Senior Member
you may try

NodeModelUtils.findActualNodeFor(object).text

object may be eg. your RequirementDescription


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XText Get original String from AST [message #1746608 is a reply to message #1746606] Tue, 01 November 2016 16:37 Go to previous message
Lukas Schaus is currently offline Lukas SchausFriend
Messages: 37
Registered: October 2016
Member
Thanks! That worked for me!
Previous Topic:Generate matlab script form arithmetic expression
Next Topic:Debugging non-deterministic serialization failure
Goto Forum:
  


Current Time: Fri Mar 29 14:59:36 GMT 2024

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

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

Back to the top