Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Set indention between squared brackets(... using the formatter)
Set indention between squared brackets [message #1713335] Tue, 03 November 2015 13:01 Go to next message
John Cole is currently offline John ColeFriend
Messages: 66
Registered: June 2013
Member
Hello,

currently, I am working with the Formatter class, to autoformat my DSL code using the Eclipse shortcut CTRL + Shift + F.

In my DSL definition I have the following rules:

Element:
	'Element' name=ID
	description=STRING?
	('param1' param1=DOUBLE)?
	nestedElement=NestedElement?
	'end' 'Element' 
;

NestedElement:
	'NESTEDELEMENT' '[' (
		('param2' param2=DOUBLE)?
		('param3' param3=DOUBLE)?
		('param4' param4=DOUBLE)?
	) ']'
;



This allows me to define the following code in my editor:

Element MyElement
	"My description"
	param1 0.4
	
	NESTEDELEMENT [
		param2 1.2
		param3 3.2
		param4 4.1
	]
	
end Element


So inside my element I have another nested element, which is defined between squared brackets. This is the way, I am formatting the code, without consideration of the nested element:

@Override
protected void configureFormatting(final FormattingConfig c) {
	ElementElements in = f.getElementAccess();
	
	c.setIndentation(in.getNameAssignment_0_1(), in.getEndKeyword_1_1());
	wrapAfter(in.getNameAssignment_0_1());
	wrapAfter(in.getDescriptionAssignment_0_2());
	wrapAfter(in.getNestedElementAssignment_0_3_1());
	c.setSpace("\n").before(in.getEndKeyword_1_1());
}


What I am trying to do is, to to indent the params of the nested elements as you can see in the second listing. How do I access the code between the squared brackets?
Re: Set indention between squared brackets [message #1713384 is a reply to message #1713335] Tue, 03 November 2015 17:07 Go to previous messageGo to next message
Thomas Fritsch is currently offline Thomas FritschFriend
Messages: 28
Registered: April 2013
Location: Germany
Junior Member
Try something like this in your configureFormatting method:
for (Pair<Keyword, Keyword> pair : getGrammarAccess().findKeywordPairs("[", "]") {
	c.setIndentation(pair.getFirst(), pair.getSecond());
	c.setLinewrap().after(pair.getFirst());
	c.setLinewrap().around(pair.getSecond());
}
Re: Set indention between squared brackets [message #1713436 is a reply to message #1713384] Wed, 04 November 2015 07:42 Go to previous message
John Cole is currently offline John ColeFriend
Messages: 66
Registered: June 2013
Member
Hello Thomas,

thank you very much for the quick response!
It does exactly what I wanted. Many thanks! Smile
Previous Topic:Navigating from an EObjectNode to its EObject
Next Topic:Refer to existing plugin (Xcore) metamodel
Goto Forum:
  


Current Time: Fri Apr 26 19:24:58 GMT 2024

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

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

Back to the top