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: 72
Registered: February 2016
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


Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
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: 14665
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
				}
				
			}


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: 72
Registered: February 2016
Member
Great, thanks for the pointer Christian! I managed to hack a small wrapping algorithm to produce the replacement with your code snippet.

Elie Richa, Ph.D
Software Engineer, AdaCore
https://www.adacore.com
Previous Topic:Formatter is discarding empty lines between comments
Next Topic:Breakpoint in xtext dsl editor
Goto Forum:
  


Current Time: Thu Apr 18 16:07:35 GMT 2024

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

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

Back to the top