highlights(c/cpp): highlight case labels as constants

This commit is contained in:
Stephan Seitz 2021-12-20 14:50:59 +01:00 committed by Stephan Seitz
parent 1d3111ccb1
commit e4675bc410
4 changed files with 50 additions and 0 deletions

View file

@ -139,6 +139,8 @@
(#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
(enumerator
name: (identifier) @constant)
(case_statement
value: (identifier) @constant)
;; Preproc def / undef
(preproc_def

View file

@ -38,6 +38,8 @@
(#lua-match? @type "^[A-Z]"))
((namespace_identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
(case_statement
value: (qualified_identifier (identifier) @constant))
(namespace_definition
name: (identifier) @namespace)

View file

@ -0,0 +1,21 @@
enum Foo{
a,
// ^ @constant
aa,
// ^ @constant
C,
};
void foo(enum Foo f){
switch ( f ) {
case a:
// ^ @constant
break;
case aa:
// ^ @constant
break;
case C:
break;
default:
}
}

View file

@ -0,0 +1,25 @@
enum class Foo{
a,
// ^ @constant
aa,
// ^ @constant
C,
// ^ @constant
};
void foo(Foo f){
switch ( f ) {
case Foo::a:
// ^ @type
// ^ @namespace
// ^ @constant
break;
case Foo::aa:
// ^ @constant
break;
case Foo::C:
// ^ @constant
break;
default:
}
}