Comments (10)
[[attributes]] are technically ambiguous as
foo[[]{return funcReturningVector();}()[0]]
is a valid expression. But attributes are far more comman than a self executing lambda inside a subscript operator.
from better-cpp-syntax.
Putting this here just for reference:
https://en.cppreference.com/w/cpp/language/attributes
I think the best way to match it is going to be to create a pattern/range for it and then give it higher priority than lambdas. We might want to start with a pattern, especially since most cases seem to not contain a newline.
If a lambda inside of a subscript operator is the only situation where [[
is not an attribute, then I think we can safely create a range for attributes by just looking for [[
at the start and ]]
at the end.
from better-cpp-syntax.
Found this quote on cppreference.com
Two consecutive left square bracket tokens ([[) may only appear when introducing an attribute-specifier or inside an attribute argument.
So the example I posted should above not be valid. However, attributes can be nested, so the rule should include itself to allow for that.
from better-cpp-syntax.
Great find 👍 It shouldn't be too hard to implement.
I need to focus on academics till the end of the semester so it might be awhile before I do any major contributions.
from better-cpp-syntax.
I came up with
#
# C++ Attributes
#
attributes = Range.new(
repository_name: "attributes_cpp",
tag_as: "support.other.attribute",
start_pattern: newPattern(
match: /\[\[/.or(/__attribute__\(\(/).or(/__declspec\(/),
tag_as: "punctuation.start.attribute",
),
end_pattern: newPattern(
match: /\]\]/.or(/\)\)/).or(/\)/),
tag_as: "punctuation.end.attribute",
),
includes: [
# allow nested attributes
"#attributes_cpp",
Range.new(
start_pattern: newPattern(/\(/),
end_pattern: newPattern(/\)/),
includes: [
"#strings_c",
],
),
newPattern(match: /,/, tag_as: "punctuation.separator.attribute"),
newPattern(match: /::/, tag_as: "punctuation.accessor.attribute"),
],
)
However, I can't seem to actually give it a higher priority than the lambda. Even when it is the first pattern, attributes are still tagged as lambdas.
Edit: after more looking if the attribute directly follows struct
(but not class
) than it is correctly tagged. Otherwise, it is still treated as a lambda.
from better-cpp-syntax.
It seems that function attributes in namespaces are the issue.
Unsurprisingly even without the issues caused by namespace, some patterns need to be adjusted to account for [[attributes]].
from better-cpp-syntax.
So I guess this will be decently hard to implement. If the C++ reference has enough documentation we can probably create a check list and gradually add it to each area one by one.
from better-cpp-syntax.
I've had some luck with an non greedy non range rule that includes the range rule. I'll make a PR later today to discuss specifics.
from better-cpp-syntax.
from better-cpp-syntax.
@peaceshi If you want a fix for some attributes you can copy the json file from #54 https://raw.githubusercontent.com/jeff-hykin/cpp-textmate-grammar/Fix-%2350/syntaxes/cpp.tmLanguage.json into {your vscode data dir}/extensions/jeff-hykin.better-cpp-syntax-1.6.8/syntaxes
and reload.
from better-cpp-syntax.
Related Issues (20)
- enum not highlighted if followed by type specifier without space between (c++ only)
- Raw strings fail if the last line of the sting includes a comment. HOT 1
- Packs in template template parameter are not highlighted
- field index followed by arrow operator HOT 1
- Coloring gets wrong after finding a single quote character in a raw C++ string HOT 6
- Syntax Highlighter Crashing HOT 4
- Syntax highlighting broken after member function with requires clause with less comparison
- colorization of tab character "\t" in string does not work properly HOT 2
- 改扩展似乎与clang服务器冲突, 会造成clang语言服务器多次崩溃
- Add semantic colorization for c++23 #elifdef and #elifndef HOT 1
- [Suggestion] Highlight `{}` in strings
- Wrong Token Scope for Typename
- new version is not publish to vscode market? HOT 1
- ASM will not end after '#'
- Syntax highlighting is incorrect for valid C header file
- Highlighting Incorrect After Shimming Ostream Operator
- Another conversion bug `$reference(directive)` HOT 1
- Token is not highlighted in a template
- The keyword constexpr is not highlighted HOT 1
- C++ syntax highlighting falls apart after specific struct syntax HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from better-cpp-syntax.