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.8.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.8-cp310-abi3-win_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_fsharp-0.3.8-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.8-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.8-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.8-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.8-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.8-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.8.tar.gz.

File metadata

  • Download URL: tree_sitter_fsharp-0.3.8.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.8.tar.gz
Algorithm Hash digest
SHA256 16c6810caaa0214c45f8bbc31871fe3c4564f0abaa273aa27cdb7e9405fec786
MD5 2af055d17426847b821416b18bfe1842
BLAKE2b-256 b4eb3134912cb5d3293ef08861d414e7e7bbdb971fa498fca1a558377889e42b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1fc339ecb0a3e116c3bd204e218e333d1c0390176d97a8b971534520e025cf6d
MD5 178cd55c4dd3e4775c4792904e47aeaa
BLAKE2b-256 aae1a756aafb46bea5fdc5bb42760a34f72b9dde2578cb0c1bd7207d11775d1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9a8ced972e565d5d74bfa2160bc54cf46a771712d19e13ad5915d4fa140eab9e
MD5 1d498f86ce199f47ab195cabd2ee94b9
BLAKE2b-256 f71c9aebce16f20ec06c9e02dc7551fc9be963e9026822899e3e5ed96d0299de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 502e2c2fd3b1558420eec82dc34611c1b667f870fd8919388c0df45789b33e8a
MD5 754bec305ef66a260b040f58491a3c8e
BLAKE2b-256 93fb0d6eed42bcbf70605da6071729941c54f1dd406394ec3d4df299acdb4d2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 717a0e6a44bb2ddf4a70b1ba189bab1149ba3a972fb0cccab62c6d1d0000c77c
MD5 f1b43da5fd2c0ced6c86bf59d004a401
BLAKE2b-256 97a171a0577cda0773d845624d017cf1bfdb1e85dd84c9dec1fee217596f903f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e9cd34eed8fca6e56f0095a7d4d991d1693fb9f5583c0f34ebcd05d65e48e5cc
MD5 bb26239473a0ffc8a18374ee0e1c5c26
BLAKE2b-256 7af8e663d364c3ecf02ced3020f55492363e3f0a95057d3c8357b1cd92187e30

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.8-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.8-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 402b5324c89873a0cc0301d847bec977cd2159ad0c3940a9eec5b6e7b875b015
MD5 7c8fe3ab574afbaccf2e46b9dd0c84ae
BLAKE2b-256 e5ac5cb397f224a430ccafcc0ebc66ace56fc35612250f1d4be1ba58f4ab4eb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79f900dd3e9fee309c4c8a47402d4ff1765a26fc4544167b828563c98d68d740
MD5 0cbb97fb973724aa5df6937bc97df072
BLAKE2b-256 b78dcbd08358b9b32b7d0431ee11392a303274c5cf82934e28af478f6f59ce32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.8-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 369118f7852595b9a75daf90349813c41990086e218ee07ddf546852f8653211
MD5 ac79d8cb296e04fc453afa0205bdf323
BLAKE2b-256 9f11e5e8919f8d3733262c9b5222c6e9e6968001377e3bec4c16e4d8e7132e43

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