Crates.io | tree-sitter-fsharp |
lib.rs | tree-sitter-fsharp |
version | 0.1.0 |
source | src |
created_at | 2024-09-05 13:11:43.849678 |
updated_at | 2024-09-11 19:46:20.708353 |
description | fsharp grammar for the tree-sitter parsing library |
homepage | |
repository | https://github.com/ionide/tree-sitter-fsharp |
max_upload_size | |
id | 1364589 |
size | 45,291,695 |
tree-sitter grammar for F# (still WIP) Based on the 4.1 F# language specification (Mostly, Appendix A) and the F# compiler parser
First, run npm install
to install the tree-sitter cli
.
Next, the grammar can be build using npm run build
, or used to parse a file with npm run parse $file
This project defined two parser:
fsharp
grammar.In addition to the grammar.js
files each parser depends on a common external scanner found at ./common/scanner.h.
The external scanner is responsible for parsing newlines and comments and keeps track of indentation to open and close scopes.
each grammar starts with the file
node at the beginning of the rules.
tree-sitter-fsharp isn't supported out-of-the box by nvim-treesitter. However, nvim-treesitter has instructions for how to manually add unsupported parsers.
For tree-sitter-fsharp, this involves three steps:
:TSInstall fsharp
inside Neovim.$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',
}
The package.json
defines some helpful targets for developing the grammar:
npm run build
rebuilds all parser.npm test
runs all tests for both parsers.npm run parse $file
run the fsharp
parser on $file
and outputs the parse tree.npm run debug $file
run the fsharp
parser on $file
and prints debug information.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!