mirror of
https://github.com/chenasraf/nvim-treesitter.git
synced 2026-05-18 01:39:00 +00:00
feat(enforce): add parser and queries (#7626)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -173,6 +173,9 @@
|
||||
"embedded_template": {
|
||||
"revision": "8495d106154741e6d35d37064f864758ece75de6"
|
||||
},
|
||||
"enforce": {
|
||||
"revision": "9db7a49f3d73222c05b75dcfa8892f5e93542d1e"
|
||||
},
|
||||
"erlang": {
|
||||
"revision": "90f1fcb7a9c9fff2442c00d087368d5bc2c94407"
|
||||
},
|
||||
|
||||
@@ -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",
|
||||
|
||||
10
queries/enforce/folds.scm
Normal file
10
queries/enforce/folds.scm
Normal file
@@ -0,0 +1,10 @@
|
||||
[
|
||||
(block)
|
||||
(switch)
|
||||
(formal_parameters)
|
||||
(actual_parameters)
|
||||
(decl_class)
|
||||
(decl_enum)
|
||||
(comment_block)
|
||||
(doc_block)
|
||||
] @fold
|
||||
190
queries/enforce/highlights.scm
Normal file
190
queries/enforce/highlights.scm
Normal file
@@ -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))))
|
||||
30
queries/enforce/indents.scm
Normal file
30
queries/enforce/indents.scm
Normal file
@@ -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
|
||||
13
queries/enforce/injections.scm
Normal file
13
queries/enforce/injections.scm
Normal file
@@ -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
|
||||
40
queries/enforce/locals.scm
Normal file
40
queries/enforce/locals.scm
Normal file
@@ -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)
|
||||
Reference in New Issue
Block a user