Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to autowrap comments
How to autowrap comments [message #1785976] Mon, 23 April 2018 17:43 Go to next message
Elie Richa is currently offline Elie RichaFriend
Messages: 14
Registered: February 2016
Junior Member
Hello,

I would like to have the XText formatter of my language auto-wrap multi-line comments, and maybe even single-line comments (by joining together successive single-line comments).

So far I have been able to perform auto-wrapping for semantic elements by calling "autowrap" before or after certain keywords of the grammar. However comments are handled by MultilineCommentReplacer and SinglelineDocCommentReplacer.

I know that I can provide my own implementations of these classes by overriding AbstractFormatter2::createCommentReplacer() but I have no idea what I should do in the implementations that I provide.

Any hints? :)

Thanks!

--
Elie
Re: How to autowrap comments [message #1785978 is a reply to message #1785976] Mon, 23 April 2018 18:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12388
Registered: July 2009
Senior Member
i have no idea how to properly implement it or elegantly but if you move to logic completely to your code you could try something like (just a starting point

if(ruleName.startsWith("ML")) return new MultilineCommentReplacer(comment, Character.valueOf('*').charValue) {
				
				override createReplacements(ITextReplacerContext context) {
					var ITextRegionAccess access = comment.getTextRegionAccess();
					val region = access.regionForOffset(comment.offset, comment.length)
					context.addReplacement(region.replaceWith("/* TODO */"))
					context
				}
				
			}


Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to autowrap comments [message #1786051 is a reply to message #1785978] Tue, 24 April 2018 21:19 Go to previous message
Elie Richa is currently offline Elie RichaFriend
Messages: 14
Registered: February 2016
Junior Member
Great, thanks for the pointer Christian! I managed to hack a small wrapping algorithm to produce the replacement with your code snippet.
Previous Topic:Formatter is discarding empty lines between comments
Next Topic:Breakpoint in xtext dsl editor
Goto Forum:
  


Current Time: Sat Nov 17 02:07:29 GMT 2018

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

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

Back to the top