Skip to content

Commit

Permalink
Merge pull request #494 from tweag/nb/ocaml/bump_grammar
Browse files Browse the repository at this point in the history
[OCaml] Bump tree-sitter grammar version
  • Loading branch information
Erin van der Veen authored Jun 12, 2023
2 parents 61d076c + 07cb3b2 commit cfab93d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ tree-sitter-bash = { git = "https://github.com/tree-sitter/tree-sitter-bash" }
tree-sitter-facade = { git = "https://github.com/tweag/tree-sitter-facade" }
tree-sitter-json = "0.19"
tree-sitter-nickel = { git = "https://github.com/nickel-lang/tree-sitter-nickel", rev = "b1a4718601ebd29a62bf3a7fd1069a99ccf48093" }
tree-sitter-ocaml = { git = "https://github.com/tree-sitter/tree-sitter-ocaml" }
tree-sitter-ocaml = "0.20.2"
tree-sitter-query = { git = "https://github.com/nvim-treesitter/tree-sitter-query" }
tree-sitter-rust = "0.20.3"
tree-sitter-toml = "0.20.0"
Expand Down
71 changes: 39 additions & 32 deletions languages/ocaml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"and" @allow_blank_line_before
)
(value_definition
(and_operator) @allow_blank_line_before
(let_and_operator) @allow_blank_line_before
)

; Append line breaks. If there is a comment following, we don't add anything,
Expand Down Expand Up @@ -155,7 +155,15 @@
"if"
"in"
"include"
(infix_operator)
; Infix operators
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(and_operator)
(or_operator)
(assign_operator)
"inherit"
"initializer"
(item_attribute)
Expand Down Expand Up @@ -186,7 +194,6 @@
"*"
"="
"|"
"||"
"->"
"<-"
"{"
Expand All @@ -212,7 +219,15 @@
"downto"
"else"
"in"
(infix_operator) ; This one can, but we want a space before anyway.
; Infix operators can come after an open parenthesis, but we want a space before anyway
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(and_operator)
(or_operator)
(assign_operator)
"nonrec"
"of"
"rec"
Expand All @@ -234,7 +249,7 @@
; during their definition, in which case no space must be appended.
; space must be appended otherwise
(
(and_operator) @append_space
(let_and_operator) @append_space
.
")"* @do_nothing
)
Expand Down Expand Up @@ -394,11 +409,6 @@
.
"=" @prepend_space
)
(
"("* @do_nothing
.
"||" @prepend_space
)
(
"("* @do_nothing
.
Expand Down Expand Up @@ -800,7 +810,7 @@
)

(value_definition
(and_operator) @prepend_spaced_softline
(let_and_operator) @prepend_spaced_softline
)

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

; As above, infix expressions are nested grammar elements, so we must identify the
; top-level one: it is the one that is not preceded by an infix operator.
; We only consider the common logic operators, as not to mess with arithmetic expressions
; We only consider logic operators, as not to mess with arithmetic expressions
(
(infix_operator
[
"||"
"&&"
]
)? @do_nothing
[
(and_operator)
(or_operator)
]? @do_nothing
.
(infix_expression) @begin_scope @end_scope
(#scope_id! "infix_expression")
)
(infix_expression
(infix_operator
[
"||"
"&&"
]
) @prepend_spaced_scoped_softline
[
(and_operator)
(or_operator)
] @prepend_spaced_scoped_softline
(#scope_id! "infix_expression")
)

; Put softline and indented blocks after infix operators
; that have no particular treatment (e.g. "@@")
; Put softline and indented blocks after all other infix operators
(infix_expression
(infix_operator
[
"||"
"&&"
]? @do_nothing
) @append_spaced_softline @append_indent_start
[
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(assign_operator)
] @append_spaced_softline @append_indent_start
.
(_) @append_indent_end
)
Expand Down
Binary file modified web-playground/public/scripts/tree-sitter-ocaml.wasm
Binary file not shown.
Binary file modified web-playground/public/scripts/tree-sitter-ocaml_interface.wasm
Binary file not shown.

0 comments on commit cfab93d

Please sign in to comment.