Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Get position of a keyword/ rule, formatter
Get position of a keyword/ rule, formatter [message #1031928] Tue, 02 April 2013 11:32 Go to next message
Maximilian Girlich is currently offline Maximilian GirlichFriend
Messages: 17
Registered: March 2013
Junior Member
Hi,

currently I want to create an editor for some ini files. To make the code clearer I want all "=" to be in a column. For this I need to find out what is the position of all "=" in the .ini file.

How can I do that in my formatter?

Thank you Smile

PS: Is it only me who didn't find it clear where to register my own formatter?...
Re: Get position of a keyword/ rule, formatter [message #1032360 is a reply to message #1031928] Tue, 02 April 2013 23:02 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-02-04 13:32, Maximilian Girlich wrote:
> Hi,
>
> currently I want to create an editor for some ini files. To make the
> code clearer I want all "=" to be in a column. For this I need to find
> out what is the position of all "=" in the .ini file.
>
> How can I do that in my formatter?
>
Don't think this is possible with the included formatter.

> Thank you :)
> PS: Is it only me who didn't find it clear where to register my own
> formatter?...

No, probably because it is very complicated to write a completely
different formatter (unless something has changed since I last checked).

I wrote one that is used in Geppetto; it is generic but not packaged up
as a separately consumable formatter so you would have to do that on
your own. OTOH, it supports formatting based on columns (aligning on
'=', left/right/mid alignment, alignment on special char, etc. etc.).
Alignment uses clustering to avoid pathological cases.

You can format based on content (length of lists, etc.) and
it has Cascading style sheets to control formatting.

If you are interested, look at how the formatting is done in
cloudsmith/geppetto @ github.

The other approach (not using a rule based formatter at all) entails
writing a serializer that always uses the same formatting. This is
reasonably straight forward unless your language is big or you want to
offer formatting options.

Hope that helps.
Regards
- henrik
Re: Get position of a keyword/ rule, formatter [message #1033671 is a reply to message #1031928] Thu, 04 April 2013 14:00 Go to previous messageGo to next message
Maximilian Girlich is currently offline Maximilian GirlichFriend
Messages: 17
Registered: March 2013
Junior Member
Thanks for your help! My language isn't very complicated simply an ini-grammar, so the solution with the serializer should be possible. As I am neither very experienced in plugin programming nor in xtext a bit of help for the start would be nice.

Regards,
Maximilian
Re: Get position of a keyword/ rule, formatter [message #1034290 is a reply to message #1031928] Fri, 05 April 2013 08:54 Go to previous messageGo to next message
Claudio Heeg is currently offline Claudio HeegFriend
Messages: 75
Registered: April 2013
Member
Maximilian Girlich wrote on Tue, 02 April 2013 07:32
Hi,

currently I want to create an editor for some ini files. To make the code clearer I want all "=" to be in a column. For this I need to find out what is the position of all "=" in the .ini file.

Maybe something like putting a linebreak before a "=" and then put some indents in the new line before it, too. The "=" would then be in a column, but not in the same lines as the varibale declarations they refer too.

Something like
name
                = StringValue
someInt
                = 123

That's only a workaround, but as far as I can tell, and boy FormattingConfig is barely documented, there no other decent way.

Well, maybe something like working with two Formatters could do the trick (format, so "=" are in new lines; count the characters in lines before "=" appearances; format again, so "=" are back in the old lines with the appropriate number of \t's before them), but that'd be crazy.
Re: Get position of a keyword/ rule, formatter [message #1034373 is a reply to message #1033671] Fri, 05 April 2013 11:07 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I have an implementation that I used for a while until I implemented the
rule/css based formatter.

You find the hardwired serializer/formatter code here:
https://github.com/cloudsmith/geppetto/tree/master/org.cloudsmith.geppetto.pp.dsl/src/org/cloudsmith/geppetto/pp/dsl/ppformatting

The class PPSerializer is (unsuprisingly) the serializer, and it
uses PPExpressionFormatter to produce the serialized text.

How to wire that into an environment is something you have to figure
out - I am no longer using that code so it is not in the current
configuration (maybe commented out). You have to poke around in the
Geppetto repo a bit I guess, but it should be possible to figure it out
just by looking at the two files I mentioned.

The PPExpressionFormatter is very simple, it does not do
columns/alignments or anything fancy. You have to figure out how to do
that. You may want to take a look at the rule based formatter since it
uses clustering and alignment.

Hint, do a first iteration to figure out the widths of everything you
want to align, then compute the widths to use, then format and pick up
alignment information for each element and output the extra padding to
make it aligned. You should be able to reuse the cluster logic in
Geppetto's rules based formatter to compute suitable widths.

i.e. to avoid output like this

thisissomethingverylonganduglyandcomplicatedthatruinsthelayout = 1
a = 2
b = 3


Hope that provides enough clues.

Regards
- henrik

On 2013-04-04 16:00, Maximilian Girlich wrote:
> Thanks for your help! My language isn't very complicated simply an
> ini-grammar, so the solution with the serializer should be possible. As
> I am neither very experienced in plugin programming nor in xtext a bit
> of help for the start would be nice.
>
> Regards,
> Maximilian
Re: Get position of a keyword/ rule, formatter [message #1038946 is a reply to message #1031928] Thu, 11 April 2013 14:37 Go to previous message
Maximilian Girlich is currently offline Maximilian GirlichFriend
Messages: 17
Registered: March 2013
Junior Member
As the grammar isn't very complicated I made the aligning completely without the formatter by analyzing the file myself. Though it wouldn't work for more complicated grammars, it did the job for me. Thanks for your ideas Smile
Previous Topic:Double comment bug when using autoformat
Next Topic:Cannot seem to properly reference
Goto Forum:
  


Current Time: Sat Apr 20 02:03:02 GMT 2024

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

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

Back to the top