Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Formatting keywords
Formatting keywords [message #1786338] Tue, 01 May 2018 11:57 Go to next message
Eclipse UserFriend
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 12:18 Go to previous messageGo to next message
Eclipse UserFriend
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
			}

		})
	}

Re: Formatting keywords [message #1786388 is a reply to message #1786339] Wed, 02 May 2018 10:48 Go to previous messageGo to next message
Eclipse UserFriend
Thanks, that works.
Re: Formatting keywords [message #1799010 is a reply to message #1786339] Wed, 28 November 2018 11:20 Go to previous messageGo to next message
Eclipse UserFriend
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 11:55 Go to previous messageGo to next message
Eclipse UserFriend
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

[Updated on: Wed, 28 November 2018 16:04] by Moderator

Re: Formatting keywords [message #1799048 is a reply to message #1799015] Thu, 29 November 2018 06:55 Go to previous messageGo to next message
Eclipse UserFriend
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 07:03 Go to previous message
Eclipse UserFriend
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
Previous Topic:Xtext version working with Java 11
Next Topic:Saving Multiple Xtext Resources with Cyclic Cross References
Goto Forum:
  


Current Time: Sat Jun 21 17:23:35 EDT 2025

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

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

Back to the top