Giter Club home page Giter Club logo

Comments (10)

matter123 avatar matter123 commented on June 1, 2024

[[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.

jeff-hykin avatar jeff-hykin commented on June 1, 2024

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.

matter123 avatar matter123 commented on June 1, 2024

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.

jeff-hykin avatar jeff-hykin commented on June 1, 2024

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.

matter123 avatar matter123 commented on June 1, 2024

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.

matter123 avatar matter123 commented on June 1, 2024

It seems that function attributes in namespaces are the issue.

Image:
Screenshot from 2019-04-03 16-31-02

Unsurprisingly even without the issues caused by namespace, some patterns need to be adjusted to account for [[attributes]].

from better-cpp-syntax.

jeff-hykin avatar jeff-hykin commented on June 1, 2024

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.

matter123 avatar matter123 commented on June 1, 2024

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.

peaceshi avatar peaceshi commented on June 1, 2024

image
Same problem.

from better-cpp-syntax.

matter123 avatar matter123 commented on June 1, 2024

@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.

Image:
Screenshot from 2019-04-06 16-33-04

from better-cpp-syntax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.