-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sdfmt: Explicitly parse shortened function syntax #380
base: master
Are you sure you want to change the base?
Conversation
53df1a8
to
817c2a2
Compare
src/format/parser.d
Outdated
@@ -2503,6 +2511,18 @@ private: | |||
assert(0); | |||
} | |||
|
|||
void parseShortenedFunctionBody() in(match(TokenType.FatArrow)) { | |||
auto spanGuard = span!Span(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you not splice it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it, not entirely sure if I know what the difference is precisely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dump the IR, but long story short, the span is extended leftward in a way that fits the hierarchy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if there is already a span that does that, then maybe it's not useful to add one more, but I don't remember what is the generated IR here.
src/format/parser.d
Outdated
space(); | ||
parseExpression(); | ||
split(); | ||
nextToken(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to check it is the token you expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should it do if it's not? Nothing, then return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, pretty much.
int _______________________(int x) | ||
=> x + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's good. We also need a test case where the expression in there splits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added something that breaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this looks good. One thing I have though of since is that we maybe break after the type, in which case I think we do not indent. The way the span are laid out might break this, so it's a good idea to check.
817c2a2
to
7920bbf
Compare
nextToken(); | ||
space(); | ||
parseExpression(); | ||
if (match(TokenType.Semicolon)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a function that does that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look for runOnType
.
This goes some way to Fix snazzy-d#359, but the result could probably be improved somewhat with a clever span somewhere. This feature is presumably only used for things with fairly short names so one imagines the line wrapping behaviour won't be noticed much anyway...
7920bbf
to
bbf6406
Compare
@@ -2503,6 +2511,19 @@ private: | |||
assert(0); | |||
} | |||
|
|||
void parseShortenedFunctionBody() in(match(TokenType.FatArrow)) { | |||
auto spanGuard = spliceSpan(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it change something if you remove this? There might be a span here already, but if there isn't this is good to have.
0896895
to
5a79292
Compare
7ce40a5
to
4dbe602
Compare
This goes some way to Fix #359, but the result could probably be improved somewhat with a clever span somewhere.
This feature is presumably only used for things with fairly short names so one imagines the line wrapping behaviour won't be noticed much anyway...