Merge '[', 'target' , ':' into a single token for C# attributes to prevent the target from being seen as a label.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This seems OK, but it feels a bit messy that the text [target: becomes the opening square bracket. I think this might be just good enough for these attributes, so I'm ok with this for now. But a more principled solution (for later, if we hit any dead ends with this) would be to introduce a new AnnotateToken type, like TT_CSharpAttributeTarget and make sure these are annotated properly.
clang/lib/Format/FormatTokenLexer.cpp | ||
---|---|---|
286 | Here Target is unconstrained. Can it be anything? Maybe we should check if it's an tok::identifier? Even better, seems we can even enumerate the possibilities: |
Check target type against list of C# attribute targets in https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets
This definitely feels good enough rather than ideal. We should investigate adding a new token type if this 'fix' proves to have shortcomings.
clang/lib/Format/FormatTokenLexer.cpp | ||
---|---|---|
299 | Consider using a const llvm::StringSet<> like in: |
LGTM, thanks for the patch (I've seen this in the wild where the AssemblyInfo.cs gets a bit messed up.
clang/lib/Format/FormatTokenLexer.cpp | ||
---|---|---|
287 | +1 for just supporting what it can be. |
Here Target is unconstrained. Can it be anything? Maybe we should check if it's an tok::identifier?
Even better, seems we can even enumerate the possibilities:
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/attributes/#attribute-targets