I've recently realized that the reason I seem unable to find a satisfactory syntax highlighting strategy, is that I don't really need any help to tell keywords from variables, strings from operators and so on, but rather to catch subtle mistakes like undefined functions or mispelled variable names. These all look like valid syntactic tokens, but are semantically wrong. To recognize such cases, a tool should understand where some word is declared/defined and where it is merely used, which is a task much more complex than what can be accomplished by any regex.
I wonder if any editor, or plugin for editor, but without having to invoke a real compiler, exists that can at least satisfy requirement #1 below. Bonus points if it can also satisfy requirements #2 and #3 (all examples are in C as the archetype of many similar constructs in other languages).
Requirement #1
Given this snippet, it should highlight control and conrtol in lines 1 and 2 with different styles:
foo() {
int control;
control = 1; // line 1
conrtol = 1; // line 2
}
Requirement #2Given this snippet, it should highlight local ang global with different styles:
int global;
foo() {
int local;
local = 1; // line 3
global = 1; // line 4
}
Requirement #3Given this snippet, it should highlight Type in a different style than aaa and ppp:
typedef int Type;
int aaa;
int *ppp;
...
return (Type) * (ppp); // line 5
return (aaa) * (aaa); // line 6
...
Note that lines 5 and 6 have exactly the same structure: not even tree-sitter recognizes that the first is a cast + dereference, while the second is a multiplication.Loading...