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

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

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

File metadata

  • Download URL: tree_sitter_fsharp-0.3.7.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.7.tar.gz
Algorithm Hash digest
SHA256 22c403042e0cad917c8af6ae4ab8e6dc9aa6cdafd20d905e08285475493d2111
MD5 9b75668e39d8a53f55a1de1c0a9a5db8
BLAKE2b-256 4de145a5d010f9e7fbbee5589fb550c89fb6201ed40fe768e9c3e83ed97d769b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 b99199f90eb17d9880531de3143ab10771b80fff3b2a3d0700cb6f962a654ef3
MD5 1aed437d9a15f5e20381f6209d00fb65
BLAKE2b-256 e535c7fb98b34b85b7e0b95b0d7aa8f151c88f68677290b679b58b93504bbf11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ddf7f0daa1536af6f3ce58a2360d73cb58bf4c9274a9eca4c19850078d862e90
MD5 27ea9e3009cb47f2a9be3f514cb8f85c
BLAKE2b-256 f0c18d5d7253cf5495e2a07f4450ff0ba4e016b9bcb5537cb6cfdf0c595775bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 feb890a9cf93440c89c16839a9b96f52f3b2eee55cdfa1ce201c893e72386882
MD5 6fef52e212a920d23b141a54cc85d47f
BLAKE2b-256 4903610614a00dad50fe1ae0e22f7e68fa257419c924a357da2376191fb415cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d6c299b54e94b25092d97463da3023e71ca12825f8a74b58f015168fcbfd7599
MD5 5d35de70fbcb76600697f3c1ae046140
BLAKE2b-256 f37bb3066026b436be961eea15494203c798e2957c264c76b26aa5c9c7ab66ec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ab6420fe9e0cd98119c21ee3d2373912cbca9fe3f749b33b4a2945f6967cfc3d
MD5 37a4a73bdb076f57aa9114561a72326a
BLAKE2b-256 7a0d220f79ef31fdaa9ca877f8a73f72dadba630448535407feb5292a2b9cd8c

See more details on using hashes here.

File details

Details for the file tree_sitter_fsharp-0.3.7-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.7-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5bea7c9a15886d2653af4e1eb452e489e1b39921334a59675ddea3e259b4d0b1
MD5 de0f5468eecc907ef19ed8d806778644
BLAKE2b-256 0c3f053436d01880c4f8d08f42e5ecdc09b0bc4d0b1862e731549c606e7319ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 441d2efedd0eb8baabcfbcef94a9d9fb96169709e5eb4c3d1cba18d5b7228644
MD5 5e551cb78f798b5814ff9e420f9462de
BLAKE2b-256 87485e0d9f7b0b7b9f03cedbe9e2700a5b8829da5a0053cecd90f88eaf852964

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_fsharp-0.3.7-cp310-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f33929bf5529574d9c12ca150542f312f80101032d87b2c0121e607750a9194a
MD5 4977eb854d933869b7c12587cc8ff6be
BLAKE2b-256 f032473b3de17cd75d99747276269d9b554aa08717ba52eda9f47ee652de1a13

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