tree-sitter-fsharp
F# grammars for the tree-sitter parsing library, packaged as a Rust crate.
The crate ships two parsers:
| Constant | Grammar | File types |
|---|---|---|
LANGUAGE_FSHARP |
implementation files | .fs, .fsx |
LANGUAGE_SIGNATURE |
signature files | .fsi |
Installation
The parsers are compiled from the bundled C sources by build.rs, so a C compiler is
required. The crate itself depends only on tree-sitter-language 0.1 and does not pull in
a runtime, so you choose the tree-sitter version; the crate is tested against 0.26.
Usage
let code = r#"
module M =
let x = 0
"#;
let mut parser = new;
parser
.set_language
.expect;
let tree = parser.parse.unwrap;
assert!;
Signature files need the other grammar — it is a separate parser, not a mode of the first:
parser
.set_language
.expect;
let tree = parser.parse.unwrap;
Queries and node types
Query sources and the static node type descriptions are exposed as &'static str
constants:
HIGHLIGHTS_QUERY,INJECTIONS_QUERY,LOCALS_QUERY,TAGS_QUERYFSHARP_NODE_TYPES,SIGNATURE_NODE_TYPES— the contents of the respectivenode-types.jsonfiles
Contributing and grammar development
Grammar sources, the test corpus and the development workflow live in the repository: see the main README and AGENTS.md. Bug reports for mis-parsed F# code are welcome — reduce the snippet to a minimal example and open an issue or PR.
License
MIT — see LICENSE.