Skip to main content

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 with grammar(require("../fsharp/grammar"), { ... }) and overrides/adds a few rules on top of the base. Any change to fsharp/grammar.js also 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:

  1. Update your Neovim config for nvim-treesitter to refer to tree-sitter-fsharp.
  2. Run :TSInstall fsharp inside Neovim.
  3. 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 generate rebuilds both parsers.
  • npx tree-sitter test runs all tests for both parsers.
  • npx tree-sitter parse $file runs the fsharp parser on $file and outputs the parse tree.
  • npx tree-sitter parse -d $file runs the fsharp parser on $file and prints debug information.
  • For .fsi files, use npx tree-sitter parse -p fsharp_signature $file because tree-sitter parse does 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

tree_sitter_fsharp-0.3.6.tar.gz (4.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_fsharp-0.3.6-cp310-abi3-win_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10+Windows ARM64

tree_sitter_fsharp-0.3.6-cp310-abi3-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10+Windows x86-64

tree_sitter_fsharp-0.3.6-cp310-abi3-musllinux_1_2_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tree_sitter_fsharp-0.3.6-cp310-abi3-musllinux_1_2_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tree_sitter_fsharp-0.3.6-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

tree_sitter_fsharp-0.3.6-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

tree_sitter_fsharp-0.3.6-cp310-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tree_sitter_fsharp-0.3.6-cp310-abi3-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_fsharp-0.3.6.tar.gz.

File metadata

  • Download URL: tree_sitter_fsharp-0.3.6.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tree_sitter_fsharp-0.3.6.tar.gz
Algorithm Hash digest
SHA256 d2fdaa763d8452e51d1fccbe1bc385d0ea79dda250dbf3fda9f1f6dcac926004
MD5 910e92d2c1ac32887edf577a39548fb0
BLAKE2b-256 1e0765c07be461d09c93b2a21fa507328191cfbe6b57b998e0f66c1ff53fa990

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 fdfc5197235f927eb4029e67e87896e6ca562c66c784c603a97f265667c0cb91
MD5 7d68855689139256b7f440bc46650571
BLAKE2b-256 ff0282b15470ff99928197560190d190bc5deead8e590f1444c3e42eee4b1543

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e2e2d7d9be6ca168a5383c9478ad390f34018ed4fc139645a92c561128763d6b
MD5 e279ffe2ffc6f48af43d3b1cb3599bd8
BLAKE2b-256 6d50cab04c92f50126ee1968c7bf65691989f9b2c3e2569035ca11e06823a231

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5635f44929decf1967d22cd307896a85b2d13ae6b4c829364e04e03a0e833303
MD5 5b532abbbc09578af732f4c789cfc947
BLAKE2b-256 ad730862c9b275b73ef357692a713286945208a376779dff8ce46a7bb6e0b104

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 585eadc3ee522009fda953b75fe172d3a72d35064f4b77d4b91398bb6e4b0624
MD5 eaf3d0237773f11ac68fa14369ed34b6
BLAKE2b-256 a64273e8c4e95a3e21d9876111cd53b7d19dacd4804de4b7ca4f919519700999

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 309a3acfb0e97d67ac949f97fe376af9dad70611887188bf163b22ba319fc488
MD5 27bb0811a6c46ab1fc1bab58f53ea4d5
BLAKE2b-256 c225404906c4e387a861c09260842099903a78e4bf1d85f6dc34d2314b65dd66

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 9a8c64898dcba394f0e2c4aec9a89b62baa977bcfeeda75ef8772a589b0bff24
MD5 779aae5a26b5b81c200442722a524e80
BLAKE2b-256 461bd1deb4f669c047624b25170e271ee4d3316cb4a20510dd4a696af26cb46f

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aaed24e14a5fc95f4d7a929038402bb08c7ef4e3e2d04ec2a64c3cf42f0860d6
MD5 140b7ce0d84157c53ef9badeb8923df8
BLAKE2b-256 f3a01365e5fcc0680a4782c63ddaf7c486c4c12203e598034f414cb3063699c7

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.6-cp310-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.6-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 fce8fe0ede14e89a6ec80060ea9edabd6871cd098a078d37bcb2a2ef247d5113
MD5 61cbb67c3695f8d811c65c224a5769fc
BLAKE2b-256 d82d898e0f1d7b6c9fc69ab51994566c606116bed9cd7cfca49af9ff9a3f13a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page