Skip to content

Commit

Permalink
Merge pull request #522 from tweag/519-catastrophic-performances-on-o…
Browse files Browse the repository at this point in the history
…caml-files

Resolve #519 catastrophic performances on ocaml files
  • Loading branch information
Erin van der Veen authored Jun 20, 2023
2 parents bcaedcc + 34af80e commit f236f8b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
5 changes: 2 additions & 3 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 @@ -40,7 +40,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 = "0.20.2"
tree-sitter-ocaml = { git = "https://github.com/tree-sitter/tree-sitter-ocaml" }
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: 32 additions & 39 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
(let_and_operator) @allow_blank_line_before
(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,15 +155,7 @@
"if"
"in"
"include"
; Infix operators
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(and_operator)
(or_operator)
(assign_operator)
(infix_operator)
"inherit"
"initializer"
(item_attribute)
Expand Down Expand Up @@ -194,6 +186,7 @@
"*"
"="
"|"
"||"
"->"
"<-"
"{"
Expand All @@ -219,15 +212,7 @@
"downto"
"else"
"in"
; 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)
(infix_operator) ; This one can, but we want a space before anyway.
"nonrec"
"of"
"rec"
Expand All @@ -249,7 +234,7 @@
; during their definition, in which case no space must be appended.
; space must be appended otherwise
(
(let_and_operator) @append_space
(and_operator) @append_space
.
")"* @do_nothing
)
Expand Down Expand Up @@ -409,6 +394,11 @@
.
"=" @prepend_space
)
(
"("* @do_nothing
.
"||" @prepend_space
)
(
"("* @do_nothing
.
Expand Down Expand Up @@ -810,7 +800,7 @@
)

(value_definition
(let_and_operator) @prepend_spaced_softline
(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 @@ -1384,34 +1374,37 @@

; 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 logic operators, as not to mess with arithmetic expressions
; We only consider the common logic operators, as not to mess with arithmetic expressions
(
[
(and_operator)
(or_operator)
]? @do_nothing
(infix_operator
[
"||"
"&&"
]
)? @do_nothing
.
(infix_expression) @begin_scope @end_scope
(#scope_id! "infix_expression")
)
(infix_expression
[
(and_operator)
(or_operator)
] @prepend_spaced_scoped_softline
(infix_operator
[
"||"
"&&"
]
) @prepend_spaced_scoped_softline
(#scope_id! "infix_expression")
)

; Put softline and indented blocks after all other infix operators
; Put softline and indented blocks after infix operators
; that have no particular treatment (e.g. "@@")
(infix_expression
[
(pow_operator)
(mult_operator)
(add_operator)
(concat_operator)
(rel_operator)
(assign_operator)
] @append_spaced_softline @append_indent_start
(infix_operator
[
"||"
"&&"
]? @do_nothing
) @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 f236f8b

Please sign in to comment.