aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsimonvic <simonvic.dev@gmail.com>2025-02-08 10:38:13 +0100
committerGitHub <noreply@github.com>2025-02-08 10:38:13 +0100
commite8ccc339a318ffa88bd40a134410b06fdf584a54 (patch)
tree4d3951f9f79e22f1938def0b6689dc90d0153a2f
parentfeat(hyprlang): bash injection for bindings with descriptions (diff)
downloadnvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.tar
nvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.tar.gz
nvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.tar.bz2
nvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.tar.lz
nvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.tar.xz
nvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.tar.zst
nvim-treesitter-e8ccc339a318ffa88bd40a134410b06fdf584a54.zip
feat(enforce): add parser and queries (#7626)
-rw-r--r--README.md1
-rw-r--r--lockfile.json3
-rw-r--r--lua/nvim-treesitter/parsers.lua8
-rw-r--r--queries/enforce/folds.scm10
-rw-r--r--queries/enforce/highlights.scm190
-rw-r--r--queries/enforce/indents.scm30
-rw-r--r--queries/enforce/injections.scm13
-rw-r--r--queries/enforce/locals.scm40
8 files changed, 295 insertions, 0 deletions
diff --git a/README.md b/README.md
index e8a9d3404..d50451596 100644
--- a/README.md
+++ b/README.md
@@ -231,6 +231,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [elsa](https://github.com/glapa-grossklag/tree-sitter-elsa) (maintained by @glapa-grossklag, @amaanq)
- [x] [elvish](https://github.com/elves/tree-sitter-elvish) (maintained by @elves)
- [ ] [embedded_template](https://github.com/tree-sitter/tree-sitter-embedded-template)
+- [x] [enforce](https://github.com/simonvic/tree-sitter-enforce) (maintained by @simonvic)
- [x] [erlang](https://github.com/WhatsApp/tree-sitter-erlang) (maintained by @filmor)
- [x] [facility](https://github.com/FacilityApi/tree-sitter-facility) (maintained by @bryankenote)
- [x] [faust](https://github.com/khiner/tree-sitter-faust) (maintained by @khiner)
diff --git a/lockfile.json b/lockfile.json
index 8c1de4e28..cb2729700 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -173,6 +173,9 @@
"embedded_template": {
"revision": "8495d106154741e6d35d37064f864758ece75de6"
},
+ "enforce": {
+ "revision": "9db7a49f3d73222c05b75dcfa8892f5e93542d1e"
+ },
"erlang": {
"revision": "90f1fcb7a9c9fff2442c00d087368d5bc2c94407"
},
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 986f2a972..2af97904b 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -549,6 +549,14 @@ list.embedded_template = {
filetype = "eruby",
}
+list.enforce = {
+ install_info = {
+ url = "https://github.com/simonvic/tree-sitter-enforce",
+ files = { "src/parser.c" },
+ },
+ maintainers = { "@simonvic" },
+}
+
list.erlang = {
install_info = {
url = "https://github.com/WhatsApp/tree-sitter-erlang",
diff --git a/queries/enforce/folds.scm b/queries/enforce/folds.scm
new file mode 100644
index 000000000..dd2b8622a
--- /dev/null
+++ b/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/queries/enforce/highlights.scm b/queries/enforce/highlights.scm
new file mode 100644
index 000000000..aa8fb9b3e
--- /dev/null
+++ b/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/queries/enforce/indents.scm b/queries/enforce/indents.scm
new file mode 100644
index 000000000..b1dc79b2e
--- /dev/null
+++ b/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/queries/enforce/injections.scm b/queries/enforce/injections.scm
new file mode 100644
index 000000000..9231a4429
--- /dev/null
+++ b/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/queries/enforce/locals.scm b/queries/enforce/locals.scm
new file mode 100644
index 000000000..9f62f9d96
--- /dev/null
+++ b/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)