Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatter inner block indentation(How to indent a inner block)
Formatter inner block indentation [message #1777109] Fri, 24 November 2017 14:19 Go to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 46
Registered: August 2013
Member
Hi guys, I can't format the block "entities" below, how I could get this block in my DSLFormatter? Something like:
interior(
	entities.regionFor.keyword('{').prepend[oneSpace].append[newLine],
	entities.regionFor.keyword('}').prepend[newLine],
	[indent]
)


service myService {

	entities {
		
		entity myEntity {
			one
			two
			three
		}
		
	}

}
Re: Formatter inner block indentation [message #1777110 is a reply to message #1777109] Fri, 24 November 2017 14:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12104
Registered: July 2009
Senior Member
you usually format such things at the level where they are e.g.

interior(
service.regionFor.keyword('{'),
service.regionFor.keyword('}')
)[indent]

.....

interior(
entities.regionFor.keyword('{'),
entities.regionFor.keyword('}')
)[indent]
....
interior(
entity.regionFor.keyword('{'),
entity.regionFor.keyword('}')
)[indent]


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Formatter inner block indentation [message #1777113 is a reply to message #1777110] Fri, 24 November 2017 14:56 Go to previous messageGo to next message
Márcio Koch is currently offline Márcio KochFriend
Messages: 46
Registered: August 2013
Member
Thanks for the answer. In the formatter code I don't have the "entities" object available to do the indentation. Am I doing something wrong in my grammer?
...
Service:
	'service' service=ID '{'
		('entities' '{' (entities+=Entity)* '}')?
	'}'
;

Entity:
...
Re: Formatter inner block indentation [message #1777114 is a reply to message #1777113] Fri, 24 November 2017 16:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12104
Registered: July 2009
Senior Member
you can always fall back to the region finder that uses grammar elements

class MyDslFormatter extends AbstractFormatter2 {

	@Inject extension MyDslGrammarAccess

	def dispatch void format(Service service, extension IFormattableDocument document) {
		service.regionFor.keyword(serviceAccess.leftCurlyBracketKeyword_2).append[newLine]
		service.regionFor.keyword(serviceAccess.rightCurlyBracketKeyword_4).prepend[newLine]
		service.regionFor.keyword(serviceAccess.leftCurlyBracketKeyword_3_1).append[newLine]
		service.regionFor.keyword(serviceAccess.rightCurlyBracketKeyword_3_3).prepend[newLine]
		interior(
			service.regionFor.keyword(serviceAccess.leftCurlyBracketKeyword_2),
			service.regionFor.keyword(serviceAccess.rightCurlyBracketKeyword_4)
		)[indent]
		interior(
			service.regionFor.keyword(serviceAccess.leftCurlyBracketKeyword_3_1),
			service.regionFor.keyword(serviceAccess.rightCurlyBracketKeyword_3_3)
		)[indent]
		for (Entity entity : service.getEntities()) {
			entity.format;
		}
	}

	def dispatch void format(Entity entity, extension IFormattableDocument document) {
		entity.regionFor.keyword(entityAccess.leftCurlyBracketKeyword_2).append[newLine]
		entity.regionFor.keyword(entityAccess.rightCurlyBracketKeyword_4).prepend[newLine]
		interior(
			entity.regionFor.keyword(entityAccess.leftCurlyBracketKeyword_2),
			entity.regionFor.keyword(entityAccess.rightCurlyBracketKeyword_4)
		)[indent]
	}
}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Formatter inner block indentation [message #1777116 is a reply to message #1777114] Fri, 24 November 2017 16:31 Go to previous message
Márcio Koch is currently offline Márcio KochFriend
Messages: 46
Registered: August 2013
Member
Thank you so much, your example helped me alot. It's working fine now.
Previous Topic:Xtext web support into Angular app
Next Topic:Confusion about two ways to get resourceDescription
Goto Forum:
  


Current Time: Tue Jul 17 03:28:07 GMT 2018

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

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

Back to the top