by layer8 · 2y ago · 0 comments
Of course, for syntax highlighting this is only relevant if you want to highlight the multiplication operator differently from the dereferencing operator, or declarations differently from expressions.
More generally, however, I find it useful to highlight (say) types differently from variables or functions, which in some (most?) popular languages requires full parsing and symbol table information. Some IDEs therefore implement two levels of syntax highlighting, a basic one that only requires lexical information, and an extended one that kicks in when full grammar and type information becomes available.
Can you mention one editor which does that?
/* given foo.c */
int main() {
int a, *b;
a = 5 * 10;
b = &a;
printf("a is %d\n", *b);
}
and then M-x c-ts-mode followed by navigating to each * and invoking M-x treesit-inspect-node-at-point in turn produces, respectively: (declaration declarator: (pointer_declarator "*"))
right: (binary_expression operator: "*")
arguments: (argument_list (pointer_expression operator: "*"))
1: https://www.emacswiki.org/emacs/Tree-sitter return (A)*(B);
which depends on A being a type or a variable.I would expect her to know C quite well, and that's probably an understatement.