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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_fsharp-0.3.10-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.10-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.10-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.10-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.10-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.10-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.10.tar.gz.

File metadata

  • Download URL: tree_sitter_fsharp-0.3.10.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.10.tar.gz
Algorithm Hash digest
SHA256 480f79dc3314f8a6ce4643de6b69155f63c8f478eedf3ee165f44e48def3699c
MD5 b9f2d6db51f2cec7412dc8dca2ab84fc
BLAKE2b-256 5e0baf58d17854b3d664968ff0aaf8447866e5253aee5ccbd5a73104639d725d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 feb8d850ac0f502b6c34d1a76fddca2fadaebdd26ee656af8551afda27e5402a
MD5 d8424f7f672a185f26036d45c13e53d5
BLAKE2b-256 caccffe2f437d635c2a04f64e05ccf8688a8940f136614fa5c083b22581b3906

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 62255c4c14802be7430d31dd5caf4c84c31c3ef8cd806ab89ed8cccc4e25d264
MD5 053d68d5bc2a018fb9e8fedacd335c76
BLAKE2b-256 0f5afaaa6b6780fffd96308305744d557214bd59e404cd408e9a80f10f1a815b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2af0f70a87bdf0bedcac37f72c040d36c65b74bbb404037b714cac0aac0615ca
MD5 cc91333d23f58bf79e0af604e34784ac
BLAKE2b-256 53495368a66f6b1c850dff453f14603ffe0d1d11ecc8f2eddf56eefb0c40cf2a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 df900f76ffa78192a0af566a03146c747655524264035d5ffd92656a8fd8eef9
MD5 16c683c3bdec5b8115db48e44bfe45e2
BLAKE2b-256 897869dd45af1ce3fba5e6af382d6b4d2e022489583e314de0a998b7cda62329

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 391a726f7f2d4e4b7d15cb1a897a7c40d448619ff8f8ee512ffc160b28f23268
MD5 df306bb56dc695e00e8e4a3237928b1c
BLAKE2b-256 9c58fef5b94fb29be265251d616c2b35cc4b56129ec564e0a933d6f598a608e5

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.10-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.10-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 c9747020844490e6b8ed521a90988d4cd69223903000fa42f675051369a014b3
MD5 c4a42ff24aa56d433dbe078cab088e09
BLAKE2b-256 9f98105ef25c45bbd9253c17edd24cd0adf243e44e319e6a35b019791a955a23

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 559c0afdaa0e79ff51113a63bed33b79ce94a404a3f166f97faf5699ac21a14a
MD5 e6fbe29af20447a5d39af0b6fdea7249
BLAKE2b-256 b86ec0ba5dbd0a779f76b5e5e133c0099811bd082a9022af76ef0801b93f04b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.10-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d28a40ce6da87ce267b1321135e29e027b1ca8946c9afe9ffb2479dae2b30eb8
MD5 1caef458350312f8543764e68e492909
BLAKE2b-256 898b10a42ea07ab36cb9df5947a0fa82cd38b3a88bdff4c9cca631ee559936f9

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