Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Preserve Line Breaks
Preserve Line Breaks [message #1121060] Mon, 30 September 2013 08:20 Go to next message
Lars Martin is currently offline Lars MartinFriend
Messages: 24
Registered: July 2009
Junior Member
Following Jan's Blog post I can modify parts of my model. This works great (Xtext 2.4.3) except for Strings where line breaks need to be preserved.

IXtextDocument xtextDocument = xtextEditor.getDocument();
xtextDocument.modify(new IUnitOfWork.Void<XtextResource>() {
	public void process(XtextResource resource) {
		...
		Variable.setValue("a\nb\\nc\\\nd\\\\ne");
		...
	}
}


No matter what type of escaping the NEWLINE char I use, the Xtext editor receive exactly that passed String.

result:
V="a\nb\\nc\\\nd\\\\ne"

expected:
V="a
b
c
d
e"


Any hints how to preserve line breaks?

Regards, Lars M.

[Updated on: Mon, 30 September 2013 08:21]

Report message to a moderator

Re: Preserve Line Breaks [message #1121116 is a reply to message #1121060] Mon, 30 September 2013 09:35 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
perhaps you have to enter it as:

Variable.setValue("a
b
c
d
e");

[Updated on: Mon, 30 September 2013 09:36]

Report message to a moderator

Re: Preserve Line Breaks [message #1121181 is a reply to message #1121116] Mon, 30 September 2013 10:59 Go to previous messageGo to next message
Lars Martin is currently offline Lars MartinFriend
Messages: 24
Registered: July 2009
Junior Member
Unfortunately in Java it is not (yet) possible to use multi-line strings. Also the Xtend compiler translates multi-line strings to "...\n...".
Re: Preserve Line Breaks [message #1121221 is a reply to message #1121181] Mon, 30 September 2013 11:50 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
I assumed you were in the xtend world, not in java.

where do you see this escaped string in the XTEXT editor?

I know a couple of entry-forms which re-escape a multiline string to fit in the one-line fields
Re: Preserve Line Breaks [message #1122059 is a reply to message #1121221] Tue, 01 October 2013 07:31 Go to previous message
Lars Martin is currently offline Lars MartinFriend
Messages: 24
Registered: July 2009
Junior Member
Also the utility methods:
org.eclipse.xtext.util.Strings.convertFromJavaString
org.eclipse.xtext.util.Strings.convertToJavaString

didn't work.

My environment: My grammar contains a rule like following
Variable:
     name=ID '=' value=STRING;

The preferred formatting of "value" uses line breaks even if every WS would be legal for the post-processing step.

An extract from a sample model:

A="1
2
3"

In a Multipage Editor the user can edit the "value" of a given element in a JFace/SWT Formeditor, synchronization with the underlaying Xtext Document works well:
xtextDocument.readOnly(new IUnitOfWork...) // read the proper model element
..
xtextDocument.modify(new IUnitOfWork...) // write/update the proper model element

.. except for Strings with line breaks. Line breaks get escaped to "\n" when writing back to the XtextDocument.

Regards, Lars M.
Previous Topic:Creat automatically element in the current resource
Next Topic:Customize the xtext editor itself
Goto Forum:
  


Current Time: Fri Apr 19 08:11:03 GMT 2024

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

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

Back to the top