EvgeniyPeshkov / syntax-highlighter

Syntax Highlighter extension for Visual Studio Code (VSCode). Based on Tree-sitter.
https://marketplace.visualstudio.com/items?itemName=evgeniypeshkov.syntax-highlighter
MIT License
210 stars 43 forks source link

[C++] Exceptions #15

Closed alekseyt closed 5 years ago

alekseyt commented 5 years ago

Example code:

#include <stdexcept>
#include <iostream>

int main() {
    const std::string message = "sup";

    try {
        throw std::runtime_error(message);
    }
    catch (const std::exception &e) {
        std::cout << e.what() << std::endl;
    }

    return 0;
}

Screenshot:

image

Note that

1) throw is not a keyword 2) message in std::runtime_error(message) is highlighted in cyan for some reason (i have cyan assigned to syntax.type) 3) :: in std::runtime_error is highlighted differently from :: in std::string or std::cout

Is this related to upstream tree-sitter or to this extension?

I've also tried to add throw to keywords:

         "\"try\"": "control",
+        "\"throw\"": "control",
         "\"catch\"": "control",

but this doesn't help.

Any ideas?

EvgeniyPeshkov commented 5 years ago

Hello @alekseyt , welcome to {Syntax Highlighter}. I'm afraid tree-sitter cannot handle throw statements properly. It's a bug in tree-sitter. I do not use exceptions at all, so I had no chance to check this. Tree-sitter takes them for in-code declaration of function. In other words, the next two statements are syntactically the same: throw std::runtime_error(message); vs Type function(int); The same happens with construction of variable as we have discussed in other issue. Class variable(parameter);. But in the later case we can think of constructors as special functions, that have the same name as class.

alekseyt commented 5 years ago

the next two statements are syntactically the same

Except throw is a keyword. But whatever, if it's an issue in tree-sitter then i'm closing this one.

EvgeniyPeshkov commented 5 years ago

I meant, the same for tree-sitter, of course (=. I collect such issues and intend to address them to tree-sitter community one day. Maybe in future they'll fix these issues.

EvgeniyPeshkov commented 5 years ago

Hi @alekseyt , I just wanted to let you know, that the latest version of tree-sitter-cpp fixes this issue. I'll publish an update in a day. image