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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tree_sitter_fsharp-0.3.3-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.3-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.3-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.3-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.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: tree_sitter_fsharp-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 e4eb7530961a8d0f899c045bea6650b24e2fa4f3ab0174bcc388d95aadcace88
MD5 b7ca68a74625fdd50ab6a3c640c2293f
BLAKE2b-256 ac40be6605b8337b06e938d6593edffe95ccc5d7b5855a3bbf9c7647119fc7e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b2d9b7fde4a9a4847c6a85c66a99c66a55e2054bd80f3b405413f6eeb2118b02
MD5 1367183e22a2a8c2afbe09fbe12d5c25
BLAKE2b-256 48f8efa639480ed66943b7522f63e319147b0d2c3036b27c2f46cf6a3940095a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1e1ba04ac90379c7b4ce520565863320d0f28b7b87b54760a041dde33ea501d0
MD5 5f949e69786f59f678507249fbf479b7
BLAKE2b-256 0891ef9fb3df4ebc0d4bf3c453c78dff842a2e56330881370ccce048e312efe7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4a1ec2f33f3d5cadf3a13d728a220485ee1c8768458e30a3a457024895b7a2b9
MD5 f454a7ac85e5d1e865ded6c37b312112
BLAKE2b-256 183c6f943999ea662c09a5585f7547755f605131af6a35bef544a89b5cd31d1f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 5977614081a7f69f0d921f47f4f5a6642da83f5200347512baf46ade9770b2c7
MD5 c2afb2f17228bbf140b62c4f8810eb62
BLAKE2b-256 47b2f87e6e96ae3a3d350e032dc995fdfa11861803caf3479992e9f94e3a3290

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c9c9f9abecd780ce2ecb460235e127cbbd39a09c7473a044c661b9184f17aa2a
MD5 62d39d47332c2662c6cbac5e2186d3b2
BLAKE2b-256 504c534a6bebb8cd23950f7a437227d40fe3d5a493ffbdf91aaba7fc8c12bc8f

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.3-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.3-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 9c02774e6622636e0abe2c3361a7b5325ce230a0d5791382ae5ee1bf25927ffc
MD5 2ff7c7f3e4d98d5b6aca2219646a2c77
BLAKE2b-256 ab5a9203ae8eb4eb547adf5c8cb2de42822b47ce4beb02a4a533a98f4c4e6076

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 822c2674fa6e5651837e51d55509f38cb6da953334332eedeb655133cbedbc32
MD5 13762729f372931c02660fe6c3700015
BLAKE2b-256 07553beb7c0c1152b6a118c83ebb9a8eb613b453cf84e7f75a6b4c7f42978ca4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.3-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 6e12ad7b1f041056159bc30f71383bb33bb309a7a7179fe33a457becae431cc0
MD5 b31bb83ffa09008364c403cd812dc04f
BLAKE2b-256 7a8f6c2256853234fbdc78f59508794ffc069e2115a067111aad979e440aa541

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