-
Notifications
You must be signed in to change notification settings - Fork 30
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
[[attributes]] break syntax highlighting until {
#50
Comments
[[attributes]] are technically ambiguous as |
Putting this here just for reference: 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 |
Found this quote on cppreference.com
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. |
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. |
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 |
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. |
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. |
@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 |
Similar to #37 after a C++ attribute
[[fallthrough]]
,[[nodiscard]]
, etc. Syntax highlighting breaks until{
.Example
Image:
The text was updated successfully, but these errors were encountered: