difftastic/vendored_parsers/tree-sitter-f-sharp
Wilfred Hughes ac5af62606 Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
..
.github Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
bindings Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
examples Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
queries Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
src Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
test Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
.editorconfig Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
.eslintrc.js Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
.gitattributes Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
.gitignore Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
.npmignore Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
Cargo.toml Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
LICENSE Add 'vendored_parsers/tree-sitter-f-sharp/' from commit 'd7e15c6d88c2b41766409c4e258caaf14733ed01' 2024-01-28 11:58:26 +07:00
Makefile Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
Package.swift Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
README.md Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
binding.gyp Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
grammar.js Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
package-lock.json Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
package.json Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
pyproject.toml Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00
setup.py Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp 2024-05-14 10:08:50 +07:00

README.md

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. Next, the grammar can be build using npm run build, or used to parse a file with npm run parse $file

Project structure

The parser consists of two parts:

  • src/scanner.c is responsible for parsing newlines and comments and keeps track of indentation to open and close scopes.
  • grammar.js the main tree-sitter grammar. The indent tokens from the external scanner is access though the indent and dedent tokens.

The grammar starts with the file node at the begging of the rules.

Adding to neovim

From the local copy:

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.fsharp = {
  install_info = {
    url = "path/to/tree-sitter-fsharp",
    files = {"src/scanner.c", "src/parser.c" }
  },
  filetype = "fsharp",
}

From GitHub repository:

local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.fsharp = {
  install_info = {
    url = "https://github.com/Nsidorenco/tree-sitter-fsharp",
    branch = "main",
    files = {"src/scanner.c", "src/parser.c" },
  },
  filetype = "fsharp",
}

Then run :TSInstall fsharp inside neovim.

Status

The grammar currently has support for most language features, but might have rough edges. Some parts, like the type annotations are still very bare-bones.

The grammar supports indentation-based scoping but does not fully support offside indentation and opening new indentation levels on record/list construction.

The precedence rules for the different grammar nodes (and particularly expressions) are not set properly yet, which means that the parser size is much larger than needed.

Missing

  • Computational expressions
  • Type annotations
  • Annotations
  • Offside tokens inside indentation scope
  • Testing
  • Set properly precedence rules

Testing

Testing corpus

To run all tests stores in corpus/ run

$ npm test

Test parsing a specific file

$ npm run debug $file

How to contribute

Clone the repo and start playing around with it. If you find a code example which fails to parse, please reduce it to a minimal example, such that it can be added to the corpus as a test case.

PRs fleshing out the grammar or fixing bugs are very welcome!