mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-14 09:20:04 -04:00
feat(queries): pull ocaml queries from upstream
This commit is contained in:
parent
b90e520ccd
commit
ddc200768e
3 changed files with 244 additions and 117 deletions
|
|
@ -1,146 +1,148 @@
|
||||||
(module_name) @structure
|
; Modules
|
||||||
|
;--------
|
||||||
|
|
||||||
[
|
[(module_name) (module_type_name)] @constructor
|
||||||
(module_type_name)
|
|
||||||
(type_constructor)
|
|
||||||
(type_variable)
|
|
||||||
(constructor_name)
|
|
||||||
(tag)
|
|
||||||
] @type
|
|
||||||
(type_binding (type_constructor) @type)
|
|
||||||
|
|
||||||
(exception_definition (constructor_declaration (constructor_name) @exception))
|
; Types
|
||||||
(application_expression (value_path (value_name) @_raise)
|
;------
|
||||||
(#eq? @_raise "raise")
|
|
||||||
(constructor_path) @exception)
|
|
||||||
(application_expression (value_path (value_name) @_raise)
|
|
||||||
(#eq? @_raise "raise")
|
|
||||||
(parenthesized_expression
|
|
||||||
(application_expression (constructor_path) @exception)))
|
|
||||||
(infix_expression (value_path (value_name) @_raise)
|
|
||||||
(#eq? @_raise "raise")
|
|
||||||
(application_expression (constructor_path) @exception))
|
|
||||||
|
|
||||||
(attribute_id) @property
|
(
|
||||||
(field_name) @field
|
(type_constructor) @type.builtin
|
||||||
|
(#match? @type.builtin "^(int|char|bytes|string|float|bool|unit|exn|array|list|option|int32|int64|nativeint|format6|lazy_t)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
[(class_name) (class_type_name) (type_constructor)] @type
|
||||||
|
|
||||||
|
[(constructor_name) (tag)] @tag
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
;----------
|
||||||
|
|
||||||
(let_binding
|
(let_binding
|
||||||
(value_name) @function
|
pattern: (value_pattern) @function
|
||||||
(parameter))
|
(parameter))
|
||||||
|
|
||||||
(let_binding
|
(let_binding
|
||||||
(value_name) @function
|
pattern: (value_pattern) @function
|
||||||
(function_expression))
|
body: [(fun_expression) (function_expression)])
|
||||||
|
|
||||||
(application_expression . (value_path (value_name) @function))
|
(value_specification (value_name) @function)
|
||||||
(application_expression . (value_path (value_path (value_name) @function)))
|
|
||||||
(application_expression . (value_path (value_path (value_path (value_name) @function))))
|
|
||||||
(value_specification (value_name) @function (function_type))
|
|
||||||
(infix_expression (value_path (value_name) @function)
|
|
||||||
(infix_operator) @operator
|
|
||||||
(#eq? @operator "@@"))
|
|
||||||
(infix_expression (value_path (value_path (value_name) @function))
|
|
||||||
(infix_operator) @operator
|
|
||||||
(#eq? @operator "@@"))
|
|
||||||
(infix_expression (value_path (value_path (value_path (value_name) @function)))
|
|
||||||
(infix_operator) @operator
|
|
||||||
(#eq? @operator "@@"))
|
|
||||||
(infix_expression (infix_operator) @operator
|
|
||||||
(#eq? @operator "|>")
|
|
||||||
(value_path (value_name) @function))
|
|
||||||
(infix_expression (infix_operator) @operator
|
|
||||||
(#eq? @operator "|>")
|
|
||||||
(value_path (value_path (value_name) @function)))
|
|
||||||
(infix_expression (infix_operator) @operator
|
|
||||||
(#eq? @operator "|>")
|
|
||||||
(value_path (value_path (value_path (value_name) @function))))
|
|
||||||
|
|
||||||
|
(external (value_pattern) @function)
|
||||||
|
|
||||||
(let_binding (parameter (label (label_name) @parameter)))
|
(method_name) @function.method
|
||||||
(let_binding (parameter (label_name) @parameter))
|
|
||||||
(let_binding (parameter (value_name) @parameter))
|
; Variables
|
||||||
(let_binding (parameter (typed_pattern (value_name) @parameter)))
|
;----------
|
||||||
(function_type (typed_label (label_name) @parameter))
|
|
||||||
|
[(value_name) (type_variable)] @variable
|
||||||
|
|
||||||
|
(let_binding pattern: (value_pattern) @variable)
|
||||||
|
|
||||||
|
(value_pattern) @variable.parameter
|
||||||
|
|
||||||
|
; Application
|
||||||
|
;------------
|
||||||
|
|
||||||
|
(infix_expression
|
||||||
|
left: (value_path (value_name) @function)
|
||||||
|
(infix_operator) @operator
|
||||||
|
(#eq? @operator "@@"))
|
||||||
|
|
||||||
|
(infix_expression
|
||||||
|
(infix_operator) @operator
|
||||||
|
right: (value_path (value_name) @function)
|
||||||
|
(#eq? @operator "|>"))
|
||||||
|
|
||||||
|
(application_expression
|
||||||
|
function: (value_path (value_name)) @function)
|
||||||
|
|
||||||
|
(
|
||||||
|
(value_name) @function.builtin
|
||||||
|
(#match? @function.builtin "^(raise(_notrace)?|failwith|invalid_arg)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
; Properties
|
||||||
|
;-----------
|
||||||
|
|
||||||
|
[(label_name) (field_name) (instance_variable_name)] @property
|
||||||
|
|
||||||
|
; Constants
|
||||||
|
;----------
|
||||||
|
|
||||||
|
(boolean) @constant
|
||||||
|
|
||||||
;; Literals
|
|
||||||
(unit) @constant
|
|
||||||
(boolean) @boolean
|
|
||||||
(number) @number
|
(number) @number
|
||||||
(character) @character
|
|
||||||
|
|
||||||
(comment) @comment
|
[(string) (character)] @string
|
||||||
|
|
||||||
[(string) (quoted_string) (conversion_specification)] @string
|
(quoted_string "{" @string "}" @string) @string
|
||||||
(escape_sequence) @string.escape
|
|
||||||
|
|
||||||
(infix_operator) @operator
|
(escape_sequence) @escape
|
||||||
|
|
||||||
|
(conversion_specification) @string.special
|
||||||
|
|
||||||
|
; Operators
|
||||||
|
;----------
|
||||||
|
|
||||||
|
(match_expression (match_operator) @keyword)
|
||||||
|
|
||||||
|
(value_definition [(let_operator) (and_operator)] @keyword)
|
||||||
|
|
||||||
[
|
[
|
||||||
|
(prefix_operator)
|
||||||
|
(infix_operator)
|
||||||
|
(indexing_operator)
|
||||||
(let_operator)
|
(let_operator)
|
||||||
(and_operator)
|
(and_operator)
|
||||||
"let"
|
(match_operator)
|
||||||
"rec"
|
] @operator
|
||||||
"nonrec"
|
|
||||||
"of"
|
(prefix_operator "!" @operator)
|
||||||
"in"
|
|
||||||
"type"
|
(infix_operator ["&" "+" "-" "=" ">" "|" "%"] @operator)
|
||||||
"val"
|
|
||||||
"and"
|
["*" "#" "::" "<-"] @operator
|
||||||
"struct"
|
|
||||||
"sig"
|
; Keywords
|
||||||
"functor"
|
;---------
|
||||||
"external"
|
|
||||||
"module"
|
[
|
||||||
"match"
|
"and" "as" "assert" "begin" "class" "constraint" "do" "done" "downto" "else"
|
||||||
"with"
|
"end" "exception" "external" "for" "fun" "function" "functor" "if" "in"
|
||||||
"when"
|
"include" "inherit" "initializer" "lazy" "let" "match" "method" "module"
|
||||||
"begin"
|
"mutable" "new" "nonrec" "object" "of" "open" "private" "rec" "sig" "struct"
|
||||||
"end"
|
"then" "to" "try" "type" "val" "virtual" "when" "while" "with"
|
||||||
"fun"
|
|
||||||
"function"
|
|
||||||
"assert"
|
|
||||||
"lazy"
|
|
||||||
"as"
|
|
||||||
"method"
|
|
||||||
"new"
|
|
||||||
"object"
|
|
||||||
"inherit"
|
|
||||||
"mutable"
|
|
||||||
"virtual"
|
|
||||||
"private"
|
|
||||||
"constraint"
|
|
||||||
"initializer"
|
|
||||||
"class"
|
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
["exception" "try"] @exception
|
; Punctuation
|
||||||
|
;------------
|
||||||
|
|
||||||
["open" "include"] @include
|
(attribute ["[@" "]"] @punctuation.special)
|
||||||
|
(item_attribute ["[@@" "]"] @punctuation.special)
|
||||||
|
(floating_attribute ["[@@@" "]"] @punctuation.special)
|
||||||
|
(extension ["[%" "]"] @punctuation.special)
|
||||||
|
(item_extension ["[%%" "]"] @punctuation.special)
|
||||||
|
(quoted_extension ["{%" "}"] @punctuation.special)
|
||||||
|
(quoted_item_extension ["{%%" "}"] @punctuation.special)
|
||||||
|
|
||||||
["if" "then" "else"] @conditional
|
"%" @punctuation.special
|
||||||
|
|
||||||
["for" "to" "downto" "while" "do" "done"] @repeat
|
|
||||||
|
|
||||||
["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket
|
["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket
|
||||||
|
|
||||||
|
(object_type ["<" ">"] @punctuation.bracket)
|
||||||
|
|
||||||
[
|
[
|
||||||
","
|
"," "." ";" ":" "=" "|" "~" "?" "+" "-" "!" ">" "&"
|
||||||
"."
|
"->" ";;" ":>" "+=" ":=" ".."
|
||||||
";"
|
|
||||||
"#"
|
|
||||||
":"
|
|
||||||
"="
|
|
||||||
"|"
|
|
||||||
"->"
|
|
||||||
"::"
|
|
||||||
"~"
|
|
||||||
"?"
|
|
||||||
"|"
|
|
||||||
"+"
|
|
||||||
"-"
|
|
||||||
"*"
|
|
||||||
"'"
|
|
||||||
";;"
|
|
||||||
":>"
|
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
(ERROR) @error
|
; Attributes
|
||||||
|
;-----------
|
||||||
|
|
||||||
|
(attribute_id) @attribute
|
||||||
|
|
||||||
|
; Comments
|
||||||
|
;---------
|
||||||
|
|
||||||
|
[(comment) (line_number_directive) (directive) (shebang)] @comment
|
||||||
|
|
|
||||||
26
queries/ocaml/locals.scm
Normal file
26
queries/ocaml/locals.scm
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
; Scopes
|
||||||
|
;-------
|
||||||
|
|
||||||
|
(let_binding) @local.scope
|
||||||
|
|
||||||
|
(class_binding) @local.scope
|
||||||
|
|
||||||
|
(class_function) @local.scope
|
||||||
|
|
||||||
|
(method_definition) @local.scope
|
||||||
|
|
||||||
|
(fun_expression) @local.scope
|
||||||
|
|
||||||
|
(match_case) @local.scope
|
||||||
|
|
||||||
|
(for_expression) @local.scope
|
||||||
|
|
||||||
|
; Definitions
|
||||||
|
;------------
|
||||||
|
|
||||||
|
(value_pattern) @local.definition
|
||||||
|
|
||||||
|
; References
|
||||||
|
;------------
|
||||||
|
|
||||||
|
(value_name) @local.reference
|
||||||
99
queries/ocaml/tags.scm
Normal file
99
queries/ocaml/tags.scm
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
; Modules
|
||||||
|
;--------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(module_definition (module_binding (module_name) @name) @definition.module)
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(module_path (module_name) @name) @reference.module
|
||||||
|
|
||||||
|
; Modules types
|
||||||
|
;--------------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(module_type_definition (module_type_name) @name) @definition.interface
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(module_type_path (module_type_name) @name) @reference.implementation
|
||||||
|
|
||||||
|
; Functions
|
||||||
|
;----------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(value_definition
|
||||||
|
[
|
||||||
|
(let_binding
|
||||||
|
pattern: (value_pattern) @name
|
||||||
|
(parameter))
|
||||||
|
(let_binding
|
||||||
|
pattern: (value_pattern) @name
|
||||||
|
body: [(fun_expression) (function_expression)])
|
||||||
|
] @definition.function
|
||||||
|
)
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(external (value_pattern) @name) @definition.function
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(application_expression
|
||||||
|
function: (value_path (value_name) @name)) @reference.call
|
||||||
|
|
||||||
|
(infix_expression
|
||||||
|
left: (value_path (value_name) @name)
|
||||||
|
(infix_operator) @reference.call
|
||||||
|
(#eq? @reference.call "@@"))
|
||||||
|
|
||||||
|
(infix_expression
|
||||||
|
(infix_operator) @reference.call
|
||||||
|
right: (value_path (value_name) @name)
|
||||||
|
(#eq? @reference.call "|>"))
|
||||||
|
|
||||||
|
; Operator
|
||||||
|
;---------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(value_definition
|
||||||
|
(let_binding
|
||||||
|
pattern: (parenthesized_operator (_) @name)) @definition.function)
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
[(prefix_operator) (infix_operator) (indexing_operator) (let_operator) (and_operator) (match_operator)] @name @reference.call
|
||||||
|
|
||||||
|
; Classes
|
||||||
|
;--------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
[
|
||||||
|
(class_definition (class_binding (class_name) @name) @definition.class)
|
||||||
|
(class_type_definition (class_type_binding (class_type_name) @name) @definition.class)
|
||||||
|
]
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
[
|
||||||
|
(class_path (class_name) @name)
|
||||||
|
(class_type_path (class_type_name) @name)
|
||||||
|
] @reference.class
|
||||||
|
|
||||||
|
; Methods
|
||||||
|
;--------
|
||||||
|
|
||||||
|
(
|
||||||
|
(comment)? @doc .
|
||||||
|
(method_definition (method_name) @name) @definition.method
|
||||||
|
(#strip! @doc "^\\(\\*\\*?\\s*|\\s\\*\\)$")
|
||||||
|
)
|
||||||
|
|
||||||
|
(method_invocation (method_name) @name) @reference.call
|
||||||
Loading…
Add table
Add a link
Reference in a new issue