tree-sitter / tree-sitter-ocaml

OCaml grammar for tree-sitter
MIT License
75 stars 23 forks source link

Why are expressions allowed at the top level? #104

Closed ddickstein closed 3 hours ago

ddickstein commented 4 hours ago

Why is expression_item allowed to appear directly at the top level / in a structure? I might not be thinking of an edge case but ordinarily expressions should appear under value definitions.

https://github.com/tree-sitter/tree-sitter-ocaml/blob/5f7a97e9757d8afe6c0b0b5dd8734cf59f35456e/grammars/ocaml/grammar.js#L104-L108

314eter commented 3 hours ago

OCaml allows top level expressions. It's not considered to be a good practice, but it's valid code, so tree-sitter-ocaml has to parse it.