Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » formatting - indentation following newline
formatting - indentation following newline [message #1771825] Thu, 31 August 2017 06:30 Go to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
Hi,

I have very trivial issue, but i'm running out of time to research it :)
I am writing a formatter - I need to newline and indent a tag, but I cannot get both commands to run in same action:

//this should newline and indent 5 spaces - but only NL happens:
[code]
visual.material.format.prepend[setNewLines(1, 1, 2); space = Strings.repeat(" ", 5)]
[code ]


if I split the commands up they both run fine - but it i split command up like below only first one i called?
How do I fix it?

//works - is newlined
visual.material.format.prepend[setNewLines(1, 1, 2)]

/works - is indented
visual.material.format.prepend[space = Strings.repeat(" ", 5)]

Re: formatting - indentation following newline [message #1771826 is a reply to message #1771825] Thu, 31 August 2017 06:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11588
Registered: July 2009
Senior Member
how does the part of the model look like
you ususally dont use space = ....
to do identation


Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: formatting - indentation following newline [message #1771857 is a reply to message #1771826] Thu, 31 August 2017 12:44 Go to previous messageGo to next message
Susie Agerholm is currently offline Susie AgerholmFriend
Messages: 54
Registered: April 2017
Member
I know but did not have any luck with indent keyword either ;)

Visual:
{Visual} 'Visual' (name=ID)?
'Geometry' geometry=Geometry
(origin=Origin | 'Material' material=Material)*

;

Material:
Texture | Color
;


Texture:
'Texture' (name=ID)?
'pathToFile' pathToFile=URDFAttrSTRING
;


// RGBA values must be floats between 0 and 1 incl
Color:
'Color' (name=ID)?
'red' red=URDFAttrFloat
'green' green=URDFAttrFloat
'blue' blue=URDFAttrFloat
'alpha' alpha=URDFAttrFloat
;
Re: formatting - indentation following newline [message #1771860 is a reply to message #1771857] Thu, 31 August 2017 13:13 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11588
Registered: July 2009
Senior Member
and what do you want to format/indent?

Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Re: formatting - indentation following newline [message #1771868 is a reply to message #1771860] Thu, 31 August 2017 13:59 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 11588
Registered: July 2009
Senior Member
(the following works for me)

fix the grammar

( 'Material' material+=Material)*

class MyDslFormatter extends AbstractFormatter2 {
	
	@Inject extension MyDslGrammarAccess

	def dispatch void format(Visual visual, extension IFormattableDocument document) {
		// TODO: format HiddenRegions around keywords, attributes, cross references, etc. 
		visual.getGeometry.format;
		visual.getMaterial.forEach[format];
		for (r : visual.allRegionsFor.keywords(visualAccess.materialKeyword_5_0)) {
			r.prepend[newLine]
		}
	}
	
	def dispatch void format(Texture m, extension IFormattableDocument document) {
		m.prepend[newLine].append[newLine].surround[indent]
		m.regionFor.keyword(textureAccess.pathToFileKeyword_2).prepend[newLine]

	}
	
	// TODO: implement for 
}




Need professional support for Xtext, Xpand, EMF?
Go to: http://xtext.itemis.com
Twitter : @chrdietrich
Blog : christiandietrich.wordpress.com
Previous Topic:Comments in Xtext
Next Topic:Trim SemanticRegion (Formatting)
Goto Forum:
  


Current Time: Thu Jan 18 06:24:40 GMT 2018

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

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