|Re: Get position of a keyword/ rule, formatter [message #1032360 is a reply to message #1031928]
||Tue, 02 April 2013 23:02
| Henrik Lindberg
Registered: July 2009
On 2013-02-04 13:32, Maximilian Girlich wrote:|
> 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
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.
|Re: Get position of a keyword/ rule, formatter [message #1034290 is a reply to message #1031928]
||Fri, 05 April 2013 08:54
| Claudio Heeg
Registered: April 2013
Maximilian Girlich wrote on Tue, 02 April 2013 07:32|
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.
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
| Henrik Lindberg
Registered: July 2009
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:
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.
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.
Powered by FUDForum
. Page generated in 1.27710 seconds