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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_fsharp-0.3.2-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.2-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.2-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.2-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.2-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.2-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.2.tar.gz.

File metadata

  • Download URL: tree_sitter_fsharp-0.3.2.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

Hashes for tree_sitter_fsharp-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c2d733085640c0d002218dfb78625c318175b0297e550a7711d1a8c402c0b571
MD5 d2207cec53696ff87052de3407a3bfa7
BLAKE2b-256 c4fddbca18d86cb3afd41f416130d5c61287630f9d4e656aefbe729d193777a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 9c1b5ea031042b109f7a99a5abfe1e27a74acebd068c416dc933ef90f9a9d38f
MD5 450366b9324333c0560baa983120e078
BLAKE2b-256 1e62a1ffc9cf5098e621643ae4774139cdd6dd42d2490aa816db739c8df39932

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 36402680f41b435606871d143d94c459f96dcc5b5b479554a6387a595b85a525
MD5 031912a9cbac219744c37b98f24e20e1
BLAKE2b-256 70ff2d483da331ed0254db5aa0d3f9ebf1a56b36363f2dbef50cc19e9a04cfb8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ddcdbafd2defc48158df3b9c9219389cffcab419b14b5068faeddfd85785804e
MD5 a6db58a72d6e19ddce2b1a689f0c4bc5
BLAKE2b-256 2091d2f1547738ba8257793a4aabc06b459e37f15be6b0b2c19f505359808dce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 c8bae8c70ec648d12c77b75148d53b127fb135081eeba574aeb7415b15d271e4
MD5 e90f89b8cf2363f3426d3ab79a40a737
BLAKE2b-256 9d9448ad0ecf130b718b7e260486f237b31dbe3192b9c851069cd6227f7eb5c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d12b55bb83baebc1383c42ee24661ec6026f11c428e8dec6e4eb89e437f406f1
MD5 8072b147222e41942937f91ed4e8a535
BLAKE2b-256 2db53d99935377aa808419655dfe62dede5da3ae2c968e350aed66a9b0e13364

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.2-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.2-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 b5a5d5aeb4a74880b131dd38718ccc3d9066168c208dee9f81b761eff042dbdd
MD5 91c5ac337ae7c0cefebd09aa0c7d833d
BLAKE2b-256 5caf0bff662f774ccbe85a9d549411fbb02aae8a2480aca3acf4f6663601ffcd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4a61f795021973b67f5896f2e517cbe61c6910c58b686cdef05bbe94e7c139c
MD5 05cf3db24162b89ad5d4b943f09e59fe
BLAKE2b-256 3dfa5f94d10f92ede61ca70d0c288d641421bcd2e3a7d58712731a0866f439a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.2-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f297127343efaded171ce9a1e46c628edd3ebad9151ad0667225e6e06091cefd
MD5 449ace55589150451b5bd537552c91fa
BLAKE2b-256 8d9260ef6edf430b4e42f9ea776267e1872e43019f6b2e5ecce3b55ed52df8d9

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