Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Formatting my Xtext Language
Formatting my Xtext Language [message #810606] Thu, 01 March 2012 10:10 Go to next message
Heinz Huber is currently offline Heinz HuberFriend
Messages: 45
Registered: February 2012
Member
Hi,

now that my grammar is finished i'm going to build a auto formatter.
I found nearly no information in this board and the web, so im asking for your help or some links!

I found a small article in the Eclipse SDK Help which helped me a little bit.

If a got for example the following grammer code:
Destination:
	StartZeichen name=ID
	'Sender' '=' sender=[Sender|ID]
	EndZeichen;


If i now want to get a newline after the name=ID, sender=[Sender|ID] element -> Is there a way to access the "name" or "sender" element? And then tell him, that after this element there must be a newline?

After ID maybe it is possible with the .after(ID) thing, but for the sender thing i found nothing! .bevor(EndZeichen) is no possiblity, because this symbol is used very very often and not every time is the newline needed.

Hope someone could help me out with some example code or a link to something.

Thanks in advance! Smile
Re: Formatting my Xtext Language [message #810717 is a reply to message #810606] Thu, 01 March 2012 13:19 Go to previous messageGo to next message
Heinz Huber is currently offline Heinz HuberFriend
Messages: 45
Registered: February 2012
Member
I think i found a way myself.
I'll post if it doesn't work like i am expecting it! :>
Re: Formatting my Xtext Language [message #811475 is a reply to message #810717] Fri, 02 March 2012 11:44 Go to previous messageGo to next message
Heinz Huber is currently offline Heinz HuberFriend
Messages: 45
Registered: February 2012
Member
Hi,

i am nearly done with writing my own formatter.
So far everything works very fine!

The only thing, which i have to solve is, that i could disable the OneWhitespaceFormatter.
I got a class which extends AbstractDeclarativeFormatter!
In the API is written, that this will automatically bring the OneWhitespaceFormatter within. Is there a way to deactivate this?
Or is it possibile to extend another class which has the same features like AbstractDeclarativeFormatter but without the OneWhitespace thing?

Hope someone got an idea for me Smile
Thanks in advance!
Re: Formatting my Xtext Language [message #811629 is a reply to message #811475] Fri, 02 March 2012 16:17 Go to previous messageGo to next message
Heinz Huber is currently offline Heinz HuberFriend
Messages: 45
Registered: February 2012
Member
I got the solution ...
After many many hours of using google and working on it!

Walk through the list of Keywords and then use "c.setNoSpace().after(var);" at these ones where no whitespace is wanted works very nice!
Hope i could save anyones time if he reads this ... ^^

Formatting [done]

[Updated on: Fri, 02 March 2012 17:06]

Report message to a moderator

Re: Formatting my Xtext Language [message #813406 is a reply to message #811629] Mon, 05 March 2012 08:15 Go to previous message
Heinz Huber is currently offline Heinz HuberFriend
Messages: 45
Registered: February 2012
Member
Hi,

i just found a little bug in my formatting.
When there is a comment in my language, the formatter doesn't break the line before starting the comment.
For example:

XML=- 1 # Tracing=on
# TracingLevel=debug


Is there a way to access the comment rule? I just want to say, that the formatter breaks the line, so that this "problem" is gone :>

Hope someone got an idea! Smile
Previous Topic:[Xtend] How to do equivalent of java Class.forName(String className)
Next Topic:[Xtext 1] How to serialize inter-model cross references, or, how to automatically generate input sta
Goto Forum:
  


Current Time: Thu Mar 28 21:07:25 GMT 2024

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

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

Back to the top