Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatting keywords
Formatting keywords [message #1786338] Tue, 01 May 2018 15:57 Go to next message
Lutz Wrage is currently offline Lutz WrageFriend
Messages: 181
Registered: July 2009
Senior Member
Given a case insensitive language, is it possible to use the formatter to render all keywords in upper case letters, e.g., convert keyword Package to PACKAGE?

Thanks!
Re: Formatting keywords [message #1786339 is a reply to message #1786338] Tue, 01 May 2018 16:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

i am not aware of any native support for that but you can always create custom replacers for any regions you want e.g.

def dispatch void format(Greeting g, extension IFormattableDocument document) {
		document.addReplacer(new AbstractTextReplacer(document, g.regionFor.keyword("Hello")) {

			override createReplacements(ITextReplacerContext context) {
				context.addReplacement(region.replaceWith(region.text.toUpperCase))
				return context
			}

		})
	}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Formatting keywords [message #1786388 is a reply to message #1786339] Wed, 02 May 2018 14:48 Go to previous messageGo to next message
Lutz Wrage is currently offline Lutz WrageFriend
Messages: 181
Registered: July 2009
Senior Member
Thanks, that works.
Re: Formatting keywords [message #1799010 is a reply to message #1786339] Wed, 28 November 2018 16:20 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
The addReplacer approach works however if I do the following it never works:
g.regionFor.keyword("Hello").replaceWith("HELLO");



Why doesn't it work?

It is way simpler and cleaner.
Re: Formatting keywords [message #1799015 is a reply to message #1799010] Wed, 28 November 2018 16:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Can you provide a complete example so that I can see if you did it right?
In general you may debug into the formatter to see why it does not work.
I assume by default there are no relplacers for keywords so that the operation goes into the void


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Wed, 28 November 2018 21:04]

Report message to a moderator

Re: Formatting keywords [message #1799048 is a reply to message #1799015] Thu, 29 November 2018 11:55 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Using the domainmodel example, I added the following to the formatter:
domainmodel.allRegionsFor.keywords("package").forEach[p |
	p.replaceWith(p.text.toUpperCase)
]


Debugging the code, I don't find anything abnormal it goes all the way to createReplacement method and returns successfully.
Re: Formatting keywords [message #1799051 is a reply to message #1799048] Thu, 29 November 2018 12:03 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
then i have no idea. you can open a ticket at github.com/eclipse/xtext-core but i have no hope you would get a fix or answer soon

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext version working with Java 11
Next Topic:Saving Multiple Xtext Resources with Cyclic Cross References
Goto Forum:
  


Current Time: Thu Apr 25 01:43:31 GMT 2024

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

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

Back to the top