Closed lucaswerkmeister closed 10 years ago
I suppose the spacing rules should be the same one as for #35…
Okay, regardless of that, this is definitely a bug:
options.``option.name`` = option;
// →
options.``option.name `` = option;
I have no idea why that space is missing there, because writer.write(" return baseOptions.`` option.name ``;\n");
works just fine.
Seeing as spaces in string templates account for the biggest part of the changes for #29, I guess I’ll implement it like #35… that should also fix the bug mentioned above.
Oh, I see now why the spacing is strange… there’s no visitStringLiteral
, string literals are handled in the generic visitLiteral
, with this:
fWriter.writeToken {
that.mainToken;
spaceBefore = 1;
spaceAfter = 1;
linebreaksBefore = visitingAnnotation then 0..3 else 0..1;
};
No, actually, there’s a different reason for that: In
"foo
bar ``1`` baz"
the "foo\nbar``` is written as a line, and then
3 ` baz"
is written as the next line. That means that when the 3
token is checking for its previous token’s spaceAfter
, it’s gone – already wiped from the token queue. That means another FormattingWriter attribute to carry over that state. Gah :-/
So, this issue went completely differently than I anticipated :D I had thought I’d have to get rid of most true
s and false
s for spaceBefore
, spaceAfter
, but it turns out I didn’t have to change any at all – which makes sense, because any expression that can appear in a string template can also appear, for example, as the single argument in a positional argument list, where you wouldn’t want spaces around it as well. Instead, I found some bugs in the FormattingWriter.
Currently, string templates will always be spaced:
instead of
I’m not sure if this is critical… I’m kinda reluctant to fix it, because it means I no longer get to use
true
forspaceBefore
andspaceAfter
, but instead have to use some slightly lower value that the string template’sfalse
can still beat. Not difficult, but annoying :D