aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Ruiz Safont <unduthegun@gmail.com>2020-09-11 10:21:39 +0100
committerThomas Vigouroux <tomvig38@gmail.com>2020-09-11 12:10:31 +0200
commitddc200768ed0237da6b74cd6e586fce489212e63 (patch)
tree853a960253f747ceac8f87586dcb98567114630d
parentci: fix wrong queries (diff)
downloadnvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.tar
nvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.tar.gz
nvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.tar.bz2
nvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.tar.lz
nvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.tar.xz
nvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.tar.zst
nvim-treesitter-ddc200768ed0237da6b74cd6e586fce489212e63.zip
feat(queries): pull ocaml queries from upstream
-rw-r--r--queries/ocaml/highlights.scm236
-rw-r--r--queries/ocaml/locals.scm26
-rw-r--r--queries/ocaml/tags.scm99
3 files changed, 244 insertions, 117 deletions
diff --git a/queries/ocaml/highlights.scm b/queries/ocaml/highlights.scm
index 69c28a3eb..8033c817c 100644
--- a/queries/ocaml/highlights.scm
+++ b/queries/ocaml/highlights.scm
@@ -1,146 +1,148 @@
-(module_name) @structure
+; Modules
+;--------
-[
- (module_type_name)
- (type_constructor)
- (type_variable)
- (constructor_name)
- (tag)
-] @type
-(type_binding (type_constructor) @type)
+[(module_name) (module_type_name)] @constructor
+
+; Types
+;------
+
+(
+ (type_constructor) @type.builtin
+ (#match? @type.builtin "^(int|char|bytes|string|float|bool|unit|exn|array|list|option|int32|int64|nativeint|format6|lazy_t)$")
+)
-(exception_definition (constructor_declaration (constructor_name) @exception))
-(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))
+[(class_name) (class_type_name) (type_constructor)] @type
-(attribute_id) @property
-(field_name) @field
+[(constructor_name) (tag)] @tag
+
+; Functions
+;----------
(let_binding
- (value_name) @function
+ pattern: (value_pattern) @function
(parameter))
+
(let_binding
- (value_name) @function
- (function_expression))
+ pattern: (value_pattern) @function
+ body: [(fun_expression) (function_expression)])
+
+(value_specification (value_name) @function)
+
+(external (value_pattern) @function)
+
+(method_name) @function.method
+
+; Variables
+;----------
+
+[(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)$")
+)
-(application_expression . (value_path (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))))
+; Properties
+;-----------
+[(label_name) (field_name) (instance_variable_name)] @property
-(let_binding (parameter (label (label_name) @parameter)))
-(let_binding (parameter (label_name) @parameter))
-(let_binding (parameter (value_name) @parameter))
-(let_binding (parameter (typed_pattern (value_name) @parameter)))
-(function_type (typed_label (label_name) @parameter))
+; Constants
+;----------
+
+(boolean) @constant
-;; Literals
-(unit) @constant
-(boolean) @boolean
(number) @number
-(character) @character
-(comment) @comment
+[(string) (character)] @string
+
+(quoted_string "{" @string "}" @string) @string
+
+(escape_sequence) @escape
+
+(conversion_specification) @string.special
-[(string) (quoted_string) (conversion_specification)] @string
-(escape_sequence) @string.escape
+; Operators
+;----------
-(infix_operator) @operator
+(match_expression (match_operator) @keyword)
+
+(value_definition [(let_operator) (and_operator)] @keyword)
[
+ (prefix_operator)
+ (infix_operator)
+ (indexing_operator)
(let_operator)
(and_operator)
- "let"
- "rec"
- "nonrec"
- "of"
- "in"
- "type"
- "val"
- "and"
- "struct"
- "sig"
- "functor"
- "external"
- "module"
- "match"
- "with"
- "when"
- "begin"
- "end"
- "fun"
- "function"
- "assert"
- "lazy"
- "as"
- "method"
- "new"
- "object"
- "inherit"
- "mutable"
- "virtual"
- "private"
- "constraint"
- "initializer"
- "class"
-] @keyword
+ (match_operator)
+] @operator
+
+(prefix_operator "!" @operator)
+
+(infix_operator ["&" "+" "-" "=" ">" "|" "%"] @operator)
-["exception" "try"] @exception
+["*" "#" "::" "<-"] @operator
-["open" "include"] @include
+; Keywords
+;---------
-["if" "then" "else"] @conditional
+[
+ "and" "as" "assert" "begin" "class" "constraint" "do" "done" "downto" "else"
+ "end" "exception" "external" "for" "fun" "function" "functor" "if" "in"
+ "include" "inherit" "initializer" "lazy" "let" "match" "method" "module"
+ "mutable" "new" "nonrec" "object" "of" "open" "private" "rec" "sig" "struct"
+ "then" "to" "try" "type" "val" "virtual" "when" "while" "with"
+] @keyword
+
+; Punctuation
+;------------
+
+(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)
-["for" "to" "downto" "while" "do" "done"] @repeat
+"%" @punctuation.special
["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket
+(object_type ["<" ">"] @punctuation.bracket)
+
[
- ","
- "."
- ";"
- "#"
- ":"
- "="
- "|"
- "->"
- "::"
- "~"
- "?"
- "|"
- "+"
- "-"
- "*"
- "'"
- ";;"
- ":>"
+ "," "." ";" ":" "=" "|" "~" "?" "+" "-" "!" ">" "&"
+ "->" ";;" ":>" "+=" ":=" ".."
] @punctuation.delimiter
-(ERROR) @error
+; Attributes
+;-----------
+
+(attribute_id) @attribute
+
+; Comments
+;---------
+
+[(comment) (line_number_directive) (directive) (shebang)] @comment
diff --git a/queries/ocaml/locals.scm b/queries/ocaml/locals.scm
new file mode 100644
index 000000000..9ddaf4871
--- /dev/null
+++ b/queries/ocaml/locals.scm
@@ -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
diff --git a/queries/ocaml/tags.scm b/queries/ocaml/tags.scm
new file mode 100644
index 000000000..e572315ca
--- /dev/null
+++ b/queries/ocaml/tags.scm
@@ -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