Skip to main content



      Home
Home » Modeling » TMF (Xtext) » formatting - indentation following newline
formatting - indentation following newline [message #1771825] Thu, 31 August 2017 02:30 Go to next message
Eclipse UserFriend
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 02:33 Go to previous messageGo to next message
Eclipse UserFriend
how does the part of the model look like
you ususally dont use space = ....
to do identation
Re: formatting - indentation following newline [message #1771857 is a reply to message #1771826] Thu, 31 August 2017 08:44 Go to previous messageGo to next message
Eclipse UserFriend
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 09:13 Go to previous messageGo to next message
Eclipse UserFriend
and what do you want to format/indent?
Re: formatting - indentation following newline [message #1771868 is a reply to message #1771860] Thu, 31 August 2017 09:59 Go to previous message
Eclipse UserFriend
(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 
}


Previous Topic:Comments in Xtext
Next Topic:Trim SemanticRegion (Formatting)
Goto Forum:
  


Current Time: Wed Jul 23 16:43:44 EDT 2025

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

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

Back to the top