Hello,
Is anyone aware of a Rust parser, or at least Rust AST written in OCaml ?
Thanks for any anwser
Giltho
Hello,
Is anyone aware of a Rust parser, or at least Rust AST written in OCaml ?
Thanks for any anwser
Giltho
Early Rust versions were written in OCaml. You can start from that, even though Rust syntax changed a lot. See this question on Reddit https://www.reddit.com/r/rust/comments/18b808/is_the_original_ocaml_compiler_still_available/
Another option, I forgot to tell about - the Tree Sitter, it generates highly efficient C runtime without dependencies, and the only parser generator that can produce incremental parsers. There is a Rust grammar for tree sitter already, but no OCaml bindings yet. You can see the example how Haskell bindings or Python bindings were done, and implement in a similar way. With this you would be able to parse Rust on the fly, as it is being typed in editor. There will be three advantages of this approach:
There are actually ocaml bindings: https://github.com/onivim/reason-tree-sitter
It depends exactly what you mean by “incremental” (what kind of changes you are robust again), but it’s fairly easy to use Menhir in an incremental way, in the sense that the prefix of the token stream that is identical to the previous run (or a previous memoized run) is not re-parsed. We described this in the Merlin paper (pages 9-11).
From their site - the design of Tree-sitter was greatly influenced by the following research papers:
@Khady Reason is not OCaml though, would be nice to have something without JavaScript inside.
It uses the reason syntax but not bucklescript unless I missed something. So this is native and not using any Javascript.
Just to clarify something–you can’t write bindings to a C library from BuckleScript (i.e. ReasonML JavaScript target). The only way is to use the ReasonML native OCaml target. So as @Khady said–the binding is using Reason syntax but native OCaml target.
For future readers: the repository has moved to https://github.com/onivim/oni2/tree/master/src/reason-tree-sitter. Currently it seems to be using its own fork of tree-sitter, as noted by the installation steps.
It’s not a fork, just vendoring and added a package.json
to makes life easier with esy