Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Migrating from formatting to formatting2
icon5.gif  Migrating from formatting to formatting2 [message #1699469] Wed, 24 June 2015 13:18 Go to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
The DSL I am working on is huge and my formatter is complicated. I have built it with formatting (the old version). I am facing some problems that were addressed in the formatting2 (the newer version). I want to migrate from the formatting to formatting2.
Syntax wise, What is the best and fastest way to go from formatting to formatting2 keeping the same results?
Can I use java for formatting2? Because the examples I have seen are all in Xtend.
Are there any examples or tutorials for formatting2?

Thanks.

[Updated on: Wed, 24 June 2015 13:18]

Report message to a moderator

Re: Migrating from formatting to formatting2 [message #1699471 is a reply to message #1699469] Wed, 24 June 2015 13:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

yes you can use java but the api will be tons more painful. i dont know if the new formatter will solve your problems.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1699472 is a reply to message #1699471] Wed, 24 June 2015 13:26 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
From the release notes and bug fixes especially it should be able to fix my problem. Please check my stackoverflow question:
http://stackoverflow.com/questions/31022234/xtext-comments-formatting
and this too:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=313133
Re: Migrating from formatting to formatting2 [message #1699496 is a reply to message #1699472] Wed, 24 June 2015 15:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
here is an example with the new formatter

Model:
elements+=Element*;

Element:
'element' name=ID '{'
features+=Feature*
'}';

terminal SL_COMMENT : '--' !('\n'|'\r')* ('\r'? '\n')?;

Feature: "feature" name=ID;

and here the formatter

class MyDslFormatter extends AbstractFormatter2 {

@Inject extension MyDslGrammarAccess

def dispatch void format(Model model, extension IFormattableDocument document) {

for (Element elements : model.getElements()) {
format(elements, document);
}
}

def dispatch void format(Element element, extension IFormattableDocument document) {
element.prepend[newLine]
val begin = element.regionForKeyword("{").prepend[space = " ";setNewLines(0,0,0)]
.append[newLine; increaseIndentation]
val end = element.regionForKeyword("}")
end.append[newLine; decreaseIndentation]
for (Feature features : element.getFeatures()) {
format(features, document);
}
}

def dispatch void format(Feature element, extension IFormattableDocument document) {
element.prepend[newLine]
}

override createCommentReplacer(IComment comment) {
val ge = comment.grammarElement
if (ge instanceof AbstractRule) {
if ("SL_COMMENT" == ge.name) {
return new SinglelineCodeCommentReplacer(comment, "--") {

override configureWhitespace(WhitespaceReplacer leading, WhitespaceReplacer trailing) {
leading.getFormatting().asFormatter();
}

}
}
}
super.createCommentReplacer(comment)
}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700147 is a reply to message #1699496] Tue, 30 June 2015 12:25 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Hi Christian, I fixed my grammar! and now I am able to use formatting2. I though have a question that is bugging me. How can I access particular keywords like I used to in formatting1 using the GrammarAccess like this for example:
GrammarAccess.getRuleNameAccess().getKeyowrd_0()


And um, How can I print the "textRegionAccess"?
Re: Migrating from formatting to formatting2 [message #1700148 is a reply to message #1700147] Tue, 30 June 2015 12:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700154 is a reply to message #1700148] Tue, 30 June 2015 12:46 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
How can I access keywords like that in formatting2?
GrammarAccess.getRuleNameAccess().getKeyowrd_0()

Because I can't do it in formatting2.
Re: Migrating from formatting to formatting2 [message #1700156 is a reply to message #1700154] Tue, 30 June 2015 12:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
regionForKeyword("keyword")

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700157 is a reply to message #1700156] Tue, 30 June 2015 13:00 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
I have a case where some parts has multiple keywords that are the same.
'element'
    ...
'end' 'element'

How can I select the second element keyword and not the first one?
Re: Migrating from formatting to formatting2 [message #1700158 is a reply to message #1700157] Tue, 30 June 2015 13:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
https://bugs.eclipse.org/bugs/show_bug.cgi?id=464867

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700161 is a reply to message #1700158] Tue, 30 June 2015 13:12 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Okay from what I understand there is a
ISemanticRegion regionForKeyword(EObject owner, Keyword keyword);

How can I supply the second argument?
Re: Migrating from formatting to formatting2 [message #1700163 is a reply to message #1700161] Tue, 30 June 2015 13:14 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
GrammarAccess.getRuleNameAccess().getKeyowrd_0() ??????????????????

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700164 is a reply to message #1700163] Tue, 30 June 2015 13:15 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Doesn't work for me using formatting2. Functions are not found.
Re: Migrating from formatting to formatting2 [message #1700166 is a reply to message #1700164] Tue, 30 June 2015 13:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
@Inject YourdslGrammarAccess grammarAccess?????? please give more context

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700167 is a reply to message #1700166] Tue, 30 June 2015 13:20 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Yes, I had a problem with the inject statement it was
@Inject extension MyDslGrammarAccess

not
@Inject extension MyDslGrammarAccess GrammarAccess


Thanks
Re: Migrating from formatting to formatting2 [message #1700169 is a reply to message #1700166] Tue, 30 June 2015 13:22 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
I have another question. For general keywords that exists in a lot of places such as ';' How can I format it like it used to be in formatting1
for (Keyword keyword : grammar.findKeywords(s)) 
      {
         c.setNoSpace().before(keyword);
         c.setLinewrap().after(keyword);
      }
Re: Migrating from formatting to formatting2 [message #1700171 is a reply to message #1700169] Tue, 30 June 2015 13:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
srz cannot say

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700174 is a reply to message #1700169] Tue, 30 June 2015 13:25 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
format(EObject object, extension IFormattableDocument document)
Re: Migrating from formatting to formatting2 [message #1700175 is a reply to message #1700171] Tue, 30 June 2015 13:29 Go to previous messageGo to next message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Christian Dietrich wrote on Tue, 30 June 2015 13:25
srz cannot say

What?
Re: Migrating from formatting to formatting2 [message #1700176 is a reply to message #1700175] Tue, 30 June 2015 13:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
i do not know!

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Migrating from formatting to formatting2 [message #1700179 is a reply to message #1700176] Tue, 30 June 2015 13:36 Go to previous message
ayman salah is currently offline ayman salahFriend
Messages: 131
Registered: June 2015
Senior Member
Okay. Chill out.

Thanks for everything, you helped me a lot.
Previous Topic:Switching to Formatting2
Next Topic:How to disable formatter?
Goto Forum:
  


Current Time: Sat Apr 20 00:48:07 GMT 2024

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

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

Back to the top