This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Merge name and colon into a single token for C# named arguments
ClosedPublic

Authored by jbcoe on Feb 20 2020, 4:52 AM.

Details

Summary

Merge 'argumentName' and ':' into a single token in foo(argumentName: bar).

Add C# named argument as a token type.

Diff Detail

Event Timeline

jbcoe created this revision.Feb 20 2020, 4:52 AM
krasimir added inline comments.Feb 20 2020, 5:23 AM
clang/lib/Format/FormatTokenLexer.cpp
189

Please add a comment with an example how is this merge expected to work (like token followed by : is merged etc.)

190

did you mean Tokens.size() < 3? Below, you look at the last 3 tokens from Tokens.

194

You might need to skip over comment while searching for CommaOrLeftParen.
I'm not 100% sure of that, because comment tokens might be handled in a separate token sequence etc.

Could you please check if your code works on this variation of the test case:

  verifyFormat(R"(//
PrintOrderDetails(orderNum: 31, productName: "Red Mug", // comment
                  sellerName: "Gift Shop");)",
               Style);
jbcoe updated this revision to Diff 245635.Feb 20 2020, 6:19 AM

Fix token-length check as 3 tokens are read not 2.

jbcoe updated this revision to Diff 245661.Feb 20 2020, 8:29 AM

Handle comments in named argument lists.

jbcoe marked 3 inline comments as done.Feb 20 2020, 8:29 AM
jbcoe updated this revision to Diff 245665.Feb 20 2020, 8:35 AM

remove commented out code

jbcoe marked an inline comment as done.Feb 20 2020, 8:41 AM
jbcoe added inline comments.
clang/lib/Format/FormatTokenLexer.cpp
190

We only take two tokens now without checking that we've not run out.

krasimir accepted this revision.Feb 20 2020, 10:21 AM
krasimir marked an inline comment as done.

Thank you!

clang/lib/Format/FormatTokenLexer.cpp
204

great comment!

This revision is now accepted and ready to land.Feb 20 2020, 10:21 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 20 2020, 11:25 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript