aboutsummaryrefslogtreecommitdiffstats
path: root/runtime/queries/enforce
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-12 09:54:30 -0600
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit692b051b09935653befdb8f7ba8afdb640adf17b (patch)
tree167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/enforce
parentfeat(c-family): inherit injections (diff)
downloadnvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/enforce')
-rw-r--r--runtime/queries/enforce/folds.scm10
-rw-r--r--runtime/queries/enforce/highlights.scm190
-rw-r--r--runtime/queries/enforce/indents.scm30
-rw-r--r--runtime/queries/enforce/injections.scm13
-rw-r--r--runtime/queries/enforce/locals.scm40
5 files changed, 283 insertions, 0 deletions
diff --git a/runtime/queries/enforce/folds.scm b/runtime/queries/enforce/folds.scm
new file mode 100644
index 000000000..dd2b8622a
--- /dev/null
+++ b/runtime/queries/enforce/folds.scm
@@ -0,0 +1,10 @@
+[
+ (block)
+ (switch)
+ (formal_parameters)
+ (actual_parameters)
+ (decl_class)
+ (decl_enum)
+ (comment_block)
+ (doc_block)
+] @fold
diff --git a/runtime/queries/enforce/highlights.scm b/runtime/queries/enforce/highlights.scm
new file mode 100644
index 000000000..aa8fb9b3e
--- /dev/null
+++ b/runtime/queries/enforce/highlights.scm
@@ -0,0 +1,190 @@
+[
+ (comment_line)
+ (comment_block)
+] @comment @spell
+
+[
+ (doc_line)
+ (doc_block)
+] @comment.documentation @spell
+
+(literal_bool) @boolean
+
+(literal_int) @number
+
+(literal_float) @number.float
+
+(literal_string) @string
+
+(escape_sequence) @string.escape
+
+(identifier) @variable
+
+(formal_parameter
+ name: (identifier) @variable.parameter)
+
+((identifier) @constant
+ (#lua-match? @constant "^[A-Z_][A-Z%d_]+$"))
+
+; Preprocessor directives
+[
+ (include)
+ (define)
+ (ifdef)
+ (ifndef)
+ (else)
+ (endif)
+] @keyword.directive
+
+(preproc_const) @constant.macro
+
+; Constant fields
+(decl_field
+ ((field_modifier) @_modifier
+ (#eq? @_modifier "const"))
+ type: (_)
+ name: (identifier) @constant)
+
+(enum_member
+ name: (identifier) @constant)
+
+[
+ "+"
+ "-"
+ "*"
+ "/"
+ "%"
+ "^"
+ "++"
+ "--"
+ "="
+ "+="
+ "-="
+ "*="
+ "/="
+ "&="
+ "^="
+ "|="
+ "<<="
+ ">>="
+ "<"
+ "<="
+ ">="
+ ">"
+ "=="
+ "!="
+ "!"
+ "&&"
+ "||"
+ ">>"
+ "<<"
+ "&"
+ "|"
+ "^"
+ "~"
+] @operator
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+; TODO: <> in decl_class
+(types
+ [
+ "<"
+ ">"
+ ] @punctuation.bracket)
+
+[
+ ","
+ "."
+ ":"
+ ";"
+] @punctuation.delimiter
+
+[
+ "default"
+ "extends"
+] @keyword
+
+[
+ "new"
+ "delete"
+] @keyword.operator
+
+"return" @keyword.return
+
+[
+ "if"
+ "else"
+ "switch"
+ "case"
+] @keyword.conditional
+
+[
+ "while"
+ "for"
+ "foreach"
+ "continue"
+ "break"
+] @keyword.repeat
+
+[
+ "enum"
+ "class"
+ "typedef"
+] @keyword.type
+
+[
+ (variable_modifier)
+ (method_modifier)
+ (class_modifier)
+ (field_modifier)
+ (formal_parameter_modifier)
+] @keyword.modifier
+
+"ref" @type
+
+(decl_class
+ typename: (identifier) @type)
+
+(decl_class
+ superclass: (superclass
+ typename: (identifier) @type))
+
+(decl_enum
+ typename: (identifier) @type)
+
+(type_identifier
+ (identifier) @type)
+
+[
+ "auto"
+ (type_primitive)
+] @type.builtin
+
+[
+ (super)
+ (this)
+] @variable.builtin
+
+(literal_null) @constant.builtin
+
+(decl_method
+ name: (identifier) @function.method)
+
+(invokation
+ invoked: (identifier) @function.method.call)
+
+; Constructor and deconstructor (function with same name of the class)
+(decl_class
+ typename: (identifier) @_classname
+ body: (class_body
+ (decl_method
+ name: (identifier) @constructor
+ (#eq? @constructor @_classname))))
diff --git a/runtime/queries/enforce/indents.scm b/runtime/queries/enforce/indents.scm
new file mode 100644
index 000000000..b1dc79b2e
--- /dev/null
+++ b/runtime/queries/enforce/indents.scm
@@ -0,0 +1,30 @@
+[
+ (block)
+ (class_body)
+ (enum_body)
+ (switch_body)
+ (array_creation)
+ (formal_parameters)
+ (actual_parameters)
+] @indent.begin
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "}"
+] @indent.branch
+
+[
+ ")"
+ "]"
+ "}"
+] @indent.end
+
+(comment_line) @indent.ignore
+
+[
+ (ERROR)
+ (comment_block)
+] @indent.auto
diff --git a/runtime/queries/enforce/injections.scm b/runtime/queries/enforce/injections.scm
new file mode 100644
index 000000000..9231a4429
--- /dev/null
+++ b/runtime/queries/enforce/injections.scm
@@ -0,0 +1,13 @@
+([
+ (comment_block)
+ (comment_line)
+] @injection.content
+ (#set! injection.language "comment"))
+
+([
+ (doc_block)
+ (doc_line)
+] @injection.content
+ (#set! injection.language "doxygen"))
+
+; TODO: string and print (numbered) format injection
diff --git a/runtime/queries/enforce/locals.scm b/runtime/queries/enforce/locals.scm
new file mode 100644
index 000000000..9f62f9d96
--- /dev/null
+++ b/runtime/queries/enforce/locals.scm
@@ -0,0 +1,40 @@
+; Scopes
+(compilation_unit) @local.scope
+
+(decl_class
+ body: (_) @local.scope)
+
+(decl_enum
+ body: (_) @local.scope)
+
+(decl_method) @local.scope
+
+(block) @local.scope
+
+(if) @local.scope
+
+(for) @local.scope
+
+(foreach) @local.scope
+
+(while) @local.scope
+
+; Definitions
+(decl_class
+ typename: (identifier) @local.definition.type)
+
+(decl_enum
+ typename: (identifier) @local.definition.enum)
+
+(decl_method
+ name: (identifier) @local.definition.method)
+
+(decl_variable
+ (_)*
+ (identifier) @local.definition.var)
+
+; References
+(identifier) @local.reference
+
+(type_identifier
+ (identifier) @local.reference)