tree-sitter-fsharp
tree-sitter grammar for F# (still WIP) Based on the 4.1 F# language specification (Mostly, Appendix A) and the F# compiler parser
Getting started
First, run npm install to install the tree-sitter CLI as a local devDependency (it lands at node_modules/.bin/tree-sitter, not on your global $PATH).
Run the CLI with npx tree-sitter <command> — this resolves the local binary automatically. To regenerate both parsers use npm run generate.
To parse a file: npx tree-sitter parse <file> (see the Development section for more).
Project structure
This project defines two parsers:
- ./fsharp/grammar.js — grammar for
.fs/.fsx(source files). - ./fsharp_signature/grammar.js — grammar for
.fsi(signature files). This is not a standalone grammar: it starts withgrammar(require("../fsharp/grammar"), { ... })and overrides/adds a few rules on top of the base. Any change tofsharp/grammar.jsalso changes the derived signature grammar, so both parsers must be regenerated together (npm run generate).
Both parsers share the external scanner at ./common/scanner.h. The per-parser src/scanner.c files are thin shims that #include the header — real scanner logic (newlines, comments, indent/dedent bookkeeping) lives in the header. Each grammar starts with the file node.
The generated src/grammar.json and src/parser.c files are checked into git and validated by CI. Do not hand-edit them; merge conflicts are resolved by re-running npm run generate. See AGENTS.md for the full development workflow.
Adding to neovim
tree-sitter-fsharp is supported through the usual installation methods of nvim-treesitter.
Installing the lastest grammar from this repo involves the following three steps:
- Update your Neovim config for nvim-treesitter to refer to tree-sitter-fsharp.
- Run
:TSInstall fsharpinside Neovim. - Copy the files from ./queries/ to the neovim config directory at
$XDG_CONFIG_HOME/nvim/queries/fsharp/- see the Adding queries section of the nvim-treesitter README.
The config you need is this (you can use a local path for url if you prefer):
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
parser_config.fsharp = {
install_info = {
url = 'https://github.com/ionide/tree-sitter-fsharp',
branch = 'main',
files = { 'src/scanner.c', 'src/parser.c' },
location = "fsharp"
},
requires_generate_from_grammar = false,
filetype = 'fsharp',
}
Development
The package.json defines some helpful targets for developing the grammar:
- Run commands from the repository root so tree-sitter picks up both grammars from
tree-sitter.json. npm run generaterebuilds both parsers.npx tree-sitter testruns all tests for both parsers.npx tree-sitter parse $fileruns thefsharpparser on$fileand outputs the parse tree.npx tree-sitter parse -d $fileruns thefsharpparser on$fileand prints debug information.- For
.fsifiles, usenpx tree-sitter parse -p fsharp_signature $filebecausetree-sitter parsedoes not reliably select the signature parser automatically.
How to contribute
Clone the project and start playing around with it.
If you find a code example which fails to parse, please reduce it to a minimal example and added to the corpus (fsharp/test/corpus/*.txt) as a test case.
For an introduction to developing tree-sitter parsers the official documentation is a good reference point.
PRs fleshing out the grammar or fixing bugs are welcome!
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tree_sitter_fsharp-0.3.5.tar.gz.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c742edd0d90d043558011c0ad7598f94292d861bfff41ecb1093f70613ac3dc
|
|
| MD5 |
51dab3ce78d3dfe9f3ece41fbe09ebda
|
|
| BLAKE2b-256 |
f858ee2a5066dadbe739dbbb54e10345c902946dfeb8ea2c93ea670f4cb44dba
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-win_arm64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-win_arm64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10+, Windows ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfeb4986177d67bb2fcde464875ff5e932954167c4ce691c862144bfe2dacf7c
|
|
| MD5 |
43e37d1639378d46a7412ef6945926b9
|
|
| BLAKE2b-256 |
9a55e324d19eabba49adef6403086662a2e77c2b6541ccc0acb84975ceee0d9e
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18f26433f0e60a6decde1ed88a6c3f847b34d9686538a5cfe61952f5f8e8dc2d
|
|
| MD5 |
da34414c2956b80b5dff90cb01f33034
|
|
| BLAKE2b-256 |
57557c8b483afa11738442ce94954221f2350c8e525a8a9497181f3077ab8438
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17aacdaad27f0649c2023d074a115eae51ccd5a86aff0ec0623abfa816ef10b1
|
|
| MD5 |
f2d46cc612a96e60f0e704ead98b5848
|
|
| BLAKE2b-256 |
65f10f8b7f49b1e212346e44fadb30b6acceebe7d1c217fc1c14a5538fbfe673
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
129b806d01fb4533e814168353a9ffd4cd8c0ba6f134864db6c16b8d958e27fa
|
|
| MD5 |
818e714e5391b4de09ae4d04fcc2f1b1
|
|
| BLAKE2b-256 |
edf4ca5ea619edddb2f1db752563e37ed5ac85f29d1c1791c6c164c48ee3563a
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f810c709e6107fd045575dcdc58db43b6cff8a2064a9fe1c431f61fb7f693fa0
|
|
| MD5 |
a9f5f8dd192581da164cef7b1156477d
|
|
| BLAKE2b-256 |
338a7e00bc175bb651b3c36cfe1c6e844383473b6abb974b7d41c9363befc019
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10+, manylinux: glibc 2.28+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4eeb039a84f1a17e665c35936a2b59a9d08788d86f0bc519ffd1e1994ef99533
|
|
| MD5 |
ce388db97227135cba65072bf4b2887b
|
|
| BLAKE2b-256 |
9c9e7f3cbd8215779e17940e1448c70df35e87982c0e7ad725bf8e28b3a4ee40
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42579f1c7db92bb427b4d0d30702b32c6eb44ab61968fe1298b51a3412d23331
|
|
| MD5 |
d69b49399a81c95f746be6e538b376d8
|
|
| BLAKE2b-256 |
f31f4ac971f3459d2b0d9c22da078d46733311727794ce4469e4715fd333567b
|
File details
Details for the file tree_sitter_fsharp-0.3.5-cp310-abi3-macosx_10_9_x86_64.whl.
File metadata
- Download URL: tree_sitter_fsharp-0.3.5-cp310-abi3-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.3 MB
- Tags: CPython 3.10+, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8aab8f85f51ab13428aeaab4f4132c5f8fdd399288120fc5a068848a5d846bf3
|
|
| MD5 |
733b95d92e80ffc7ee70caa9192ef42e
|
|
| BLAKE2b-256 |
dde5c197693c1348709a2e18aa8cfe694da6595949be2ac261b411d7e9d81710
|