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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_fsharp-0.3.4-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.4-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.4-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.4-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.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: tree_sitter_fsharp-0.3.4.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.4.tar.gz
Algorithm Hash digest
SHA256 7043869ef80e802ab90882de26379dbf2ce68297a3b0cb7ea204756c484b1c5c
MD5 287707c8e2fa156bd1f547afd755dc2b
BLAKE2b-256 48d3b56e349f7694e8af0e8f3824d541e15039b159e13c4115de19ce6e689398

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 2dd941080042027da4af8e1500555d665e656fab63503d7da61ef89abb5cbfd6
MD5 464c395c9e6b8cdfc7a9f1304353e6e1
BLAKE2b-256 693ed25d5ed946e368368104b3c38b12e6d0c7cdfaf5eb5bb574ecc6c4097e0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ec113c93588e1ea91ed085be06fe0c7f1b4f569e16b7fc3c29029aa22cf623b5
MD5 b03535a79f7c3b4e95787e8a186b054f
BLAKE2b-256 2b6443fd6cf5942b32c13dd3b97f5843f41d934d4875a4e88b787f8fdcb5058c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1ba07e382da30fc8365f54962ddd4d5c9465aa7702eb480e262fc35afadc74b1
MD5 f7e2f4ee926935dd1b40f54bef7af4f3
BLAKE2b-256 b5165bb33019a19fb95db048d98cf3ab4364a35d652529f285a89041eb37af15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a14ebc95f79034a0f421bc4be735b22a149539e7e0f261db77f08ac145233a4e
MD5 f3aa62ca4d7cd31a63f301262748c529
BLAKE2b-256 8a14825057842c629575c68fdafa7f7a201ee65a10ba2cf46bb9f8e20f43057a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f010a7a48a5922ec6afbb668040a447db97c902ae5b461d585fec2faed2f3a74
MD5 ea38c229b01ef60efec62d5387abfe4a
BLAKE2b-256 5d8c2c13122f610e6af4ed8c4c9ce0cdb35ef57e54e9c7801c3cffc65e5dbc5f

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.4-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.4-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 738fa8499bb0a8c08fe848086b9f8a17dae4ca507986807906d7091e887b6f15
MD5 534235e8c19bb2daa4d02fa68ff7c537
BLAKE2b-256 3076837336213e75a3af9115d5e910148a22d62b4859822b11541ca968bf02a6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cb4b1ead5fc1ca9998d99d7ae44585c7834ba68cd6704b7acdd790e15199e15f
MD5 fcc472e9f28f5545d6ebd0942b30ee79
BLAKE2b-256 9aae1c1310aa0bcbf20e7aef0e823e3751df874c7da6ddf25bd06ffea2b468d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.4-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1255eea955f467e90b329a177da93895555770f74a33e09a5da5149a29fc51cf
MD5 cc79f01f84e9b5165bc9100bd4c547d6
BLAKE2b-256 3071358bdb128d68ba84f236bc5d26dde54ad1bfbbeac75cb2b8486d50c81d26

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