Skip to content

Commit cfab93d

Browse files
author
Erin van der Veen
authored
Merge pull request #494 from tweag/nb/ocaml/bump_grammar
[OCaml] Bump tree-sitter grammar version
2 parents 61d076c + 07cb3b2 commit cfab93d

File tree

5 files changed

+43
-35
lines changed

5 files changed

+43
-35
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash" }
3838
tree-sitter-facade = { git = "https://github.com/tweag/tree-sitter-facade" }
3939
tree-sitter-json = "0.19"
4040
tree-sitter-nickel = { git = "https://github.com/nickel-lang/tree-sitter-nickel", rev = "b1a4718601ebd29a62bf3a7fd1069a99ccf48093" }
41-
tree-sitter-ocaml = { git = "https://github.com/tree-sitter/tree-sitter-ocaml" }
41+
tree-sitter-ocaml = "0.20.2"
4242
tree-sitter-query = { git = "https://github.com/nvim-treesitter/tree-sitter-query" }
4343
tree-sitter-rust = "0.20.3"
4444
tree-sitter-toml = "0.20.0"

languages/ocaml.scm

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"and" @allow_blank_line_before
6666
)
6767
(value_definition
68-
(and_operator) @allow_blank_line_before
68+
(let_and_operator) @allow_blank_line_before
6969
)
7070

7171
; Append line breaks. If there is a comment following, we don't add anything,
@@ -155,7 +155,15 @@
155155
"if"
156156
"in"
157157
"include"
158-
(infix_operator)
158+
; Infix operators
159+
(pow_operator)
160+
(mult_operator)
161+
(add_operator)
162+
(concat_operator)
163+
(rel_operator)
164+
(and_operator)
165+
(or_operator)
166+
(assign_operator)
159167
"inherit"
160168
"initializer"
161169
(item_attribute)
@@ -186,7 +194,6 @@
186194
"*"
187195
"="
188196
"|"
189-
"||"
190197
"->"
191198
"<-"
192199
"{"
@@ -212,7 +219,15 @@
212219
"downto"
213220
"else"
214221
"in"
215-
(infix_operator) ; This one can, but we want a space before anyway.
222+
; Infix operators can come after an open parenthesis, but we want a space before anyway
223+
(pow_operator)
224+
(mult_operator)
225+
(add_operator)
226+
(concat_operator)
227+
(rel_operator)
228+
(and_operator)
229+
(or_operator)
230+
(assign_operator)
216231
"nonrec"
217232
"of"
218233
"rec"
@@ -234,7 +249,7 @@
234249
; during their definition, in which case no space must be appended.
235250
; space must be appended otherwise
236251
(
237-
(and_operator) @append_space
252+
(let_and_operator) @append_space
238253
.
239254
")"* @do_nothing
240255
)
@@ -394,11 +409,6 @@
394409
.
395410
"=" @prepend_space
396411
)
397-
(
398-
"("* @do_nothing
399-
.
400-
"||" @prepend_space
401-
)
402412
(
403413
"("* @do_nothing
404414
.
@@ -800,7 +810,7 @@
800810
)
801811

802812
(value_definition
803-
(and_operator) @prepend_spaced_softline
813+
(let_and_operator) @prepend_spaced_softline
804814
)
805815

806816
; There is a large class of terms which should be separated from "=" by a soft line break.
@@ -1374,37 +1384,34 @@
13741384

13751385
; As above, infix expressions are nested grammar elements, so we must identify the
13761386
; top-level one: it is the one that is not preceded by an infix operator.
1377-
; We only consider the common logic operators, as not to mess with arithmetic expressions
1387+
; We only consider logic operators, as not to mess with arithmetic expressions
13781388
(
1379-
(infix_operator
1380-
[
1381-
"||"
1382-
"&&"
1383-
]
1384-
)? @do_nothing
1389+
[
1390+
(and_operator)
1391+
(or_operator)
1392+
]? @do_nothing
13851393
.
13861394
(infix_expression) @begin_scope @end_scope
13871395
(#scope_id! "infix_expression")
13881396
)
13891397
(infix_expression
1390-
(infix_operator
1391-
[
1392-
"||"
1393-
"&&"
1394-
]
1395-
) @prepend_spaced_scoped_softline
1398+
[
1399+
(and_operator)
1400+
(or_operator)
1401+
] @prepend_spaced_scoped_softline
13961402
(#scope_id! "infix_expression")
13971403
)
13981404

1399-
; Put softline and indented blocks after infix operators
1400-
; that have no particular treatment (e.g. "@@")
1405+
; Put softline and indented blocks after all other infix operators
14011406
(infix_expression
1402-
(infix_operator
1403-
[
1404-
"||"
1405-
"&&"
1406-
]? @do_nothing
1407-
) @append_spaced_softline @append_indent_start
1407+
[
1408+
(pow_operator)
1409+
(mult_operator)
1410+
(add_operator)
1411+
(concat_operator)
1412+
(rel_operator)
1413+
(assign_operator)
1414+
] @append_spaced_softline @append_indent_start
14081415
.
14091416
(_) @append_indent_end
14101417
)
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)