Skip to content

Commit 21f1545

Browse files
authored
feat: Add OCaml interface support (#251)
* feat: Add Ocaml interface support * rm message * fix hl
1 parent 9c40ce4 commit 21f1545

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,9 @@
394394
branch = master
395395
update = none
396396
ignore = dirty
397+
[submodule "repos/ocaml-interface"]
398+
path = repos/ocaml-interface
399+
url = https://github.com/tree-sitter/tree-sitter-ocaml
400+
branch = master
401+
update = none
402+
ignore = dirty

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Add `OCaml` interface support
45

56
## 0.12.51 - 2023-10-02
67
- Add `Mermaid` support
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
; Modules
2+
;--------
3+
4+
[(module_name) (module_type_name)] @module
5+
6+
; Types
7+
;------
8+
9+
(
10+
(type_constructor) @type.builtin
11+
(#match? @type.builtin "^(int|char|bytes|string|float|bool|unit|exn|array|list|option|int32|int64|nativeint|format6|lazy_t)$")
12+
)
13+
14+
[(class_name) (class_type_name) (type_constructor)] @type
15+
16+
[(constructor_name) (tag)] @constructor
17+
18+
; Functions
19+
;----------
20+
21+
(let_binding
22+
pattern: (value_name) @function
23+
(parameter))
24+
25+
(let_binding
26+
pattern: (value_name) @function
27+
body: [(fun_expression) (function_expression)])
28+
29+
(value_specification (value_name) @function)
30+
31+
(external (value_name) @function)
32+
33+
(method_name) @function.method
34+
35+
; Application
36+
;------------
37+
38+
(
39+
(value_name) @function.builtin
40+
(#match? @function.builtin "^(raise(_notrace)?|failwith|invalid_arg)$")
41+
)
42+
43+
(infix_expression
44+
left: (value_path (value_name) @function)
45+
operator: (concat_operator) @operator
46+
(#eq? @operator "@@"))
47+
48+
(infix_expression
49+
operator: (rel_operator) @operator
50+
right: (value_path (value_name) @function)
51+
(#eq? @operator "|>"))
52+
53+
(application_expression
54+
function: (value_path (value_name) @function))
55+
56+
; Variables
57+
;----------
58+
59+
[(value_name) (type_variable)] @variable
60+
61+
(value_pattern) @variable.parameter
62+
63+
; Properties
64+
;-----------
65+
66+
[(label_name) (field_name) (instance_variable_name)] @property
67+
68+
; Constants
69+
;----------
70+
71+
(boolean) @constant
72+
73+
[(number) (signed_number)] @number
74+
75+
[(string) (character)] @string
76+
77+
(quoted_string "{" @string "}" @string) @string
78+
79+
(escape_sequence) @escape
80+
81+
(conversion_specification) @string.special
82+
83+
; Operators
84+
;----------
85+
86+
(match_expression (match_operator) @keyword)
87+
88+
(value_definition [(let_operator) (let_and_operator)] @keyword)
89+
90+
[
91+
(prefix_operator)
92+
(sign_operator)
93+
(pow_operator)
94+
(mult_operator)
95+
(add_operator)
96+
(concat_operator)
97+
(rel_operator)
98+
(and_operator)
99+
(or_operator)
100+
(assign_operator)
101+
(hash_operator)
102+
(indexing_operator)
103+
(let_operator)
104+
(let_and_operator)
105+
(match_operator)
106+
] @operator
107+
108+
["*" "#" "::" "<-"] @operator
109+
110+
; Keywords
111+
;---------
112+
113+
[
114+
"and" "as" "assert" "begin" "class" "constraint" "do" "done" "downto" "else"
115+
"end" "exception" "external" "for" "fun" "function" "functor" "if" "in"
116+
"include" "inherit" "initializer" "lazy" "let" "match" "method" "module"
117+
"mutable" "new" "nonrec" "object" "of" "open" "private" "rec" "sig" "struct"
118+
"then" "to" "try" "type" "val" "virtual" "when" "while" "with"
119+
] @keyword
120+
121+
; Punctuation
122+
;------------
123+
124+
(attribute ["[@" "]"] @punctuation.special)
125+
(item_attribute ["[@@" "]"] @punctuation.special)
126+
(floating_attribute ["[@@@" "]"] @punctuation.special)
127+
(extension ["[%" "]"] @punctuation.special)
128+
(item_extension ["[%%" "]"] @punctuation.special)
129+
(quoted_extension ["{%" "}"] @punctuation.special)
130+
(quoted_item_extension ["{%%" "}"] @punctuation.special)
131+
132+
"%" @punctuation.special
133+
134+
["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket
135+
136+
(object_type ["<" ">"] @punctuation.bracket)
137+
138+
[
139+
"," "." ";" ":" "=" "|" "~" "?" "+" "-" "!" ">" "&"
140+
"->" ";;" ":>" "+=" ":=" ".."
141+
] @punctuation.delimiter
142+
143+
; Attributes
144+
;-----------
145+
146+
(attribute_id) @tag
147+
148+
; Comments
149+
;---------
150+
151+
[(comment) (line_number_directive) (directive) (shebang)] @comment

repos/ocaml-interface

Submodule ocaml-interface added at 694c577

tree-sitter-langs-build.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ git checkout."
160160
;; XXX
161161
('typescript '("typescript" ("tsx" . tsx)))
162162
('ocaml '("ocaml" ("interface" . ocaml-interface)))
163+
('ocaml-interface '("interface" ("interface" . ocaml-interface)))
163164
('xml '("tree-sitter-xml" ("tree-sitter-dtd" . dtd)))
164165
(_ '("")))))))
165166

0 commit comments

Comments
 (0)