a structural diff that understands syntax 🟥🟩
 
 
 
 
 
Go to file
Nikolaj Sidorenco 006922183e
fix: allow creating underindented scope
2024-04-20 14:20:46 +07:00
.github feat: add try-with-finally expressions 2024-04-05 17:47:52 +07:00
bindings regenerate bindings 2024-04-04 23:10:58 +07:00
examples fix: allow creating underindented scope 2024-04-20 14:20:46 +07:00
queries fix optional parameters 2024-04-08 21:37:19 +07:00
src fix: allow creating underindented scope 2024-04-20 14:20:46 +07:00
test fix: allow creating underindented scope 2024-04-20 14:20:46 +07:00
.editorconfig simplify external scanner 2024-03-29 16:45:18 +07:00
.eslintrc.js update tree-sitter cli 2024-03-28 23:30:44 +07:00
.gitattributes update attributes 2024-04-06 00:00:31 +07:00
.gitignore fix gitignore 2024-04-01 09:31:53 +07:00
.npmignore update tree-sitter cli 2024-03-28 23:30:44 +07:00
Cargo.toml update tree-sitter cli 2024-03-28 23:30:44 +07:00
LICENSE Create LICENSE 2023-02-09 09:53:34 +07:00
Makefile update tree-sitter cli 2024-03-28 23:30:44 +07:00
Package.swift update tree-sitter cli 2024-03-28 23:30:44 +07:00
README.md update readme 2024-04-08 19:18:18 +07:00
binding.gyp update tree-sitter cli 2024-03-28 23:30:44 +07:00
grammar.js fix: resolve conflict with rules vs seq expr 2024-04-20 13:56:06 +07:00
package-lock.json Bump tree-sitter-cli from 0.22.2 to 0.22.5 (#47) 2024-04-16 20:20:10 +07:00
package.json Bump tree-sitter-cli from 0.22.2 to 0.22.5 (#47) 2024-04-16 20:20:10 +07:00
pyproject.toml update tree-sitter cli 2024-03-28 23:30:44 +07:00
setup.py update tree-sitter cli 2024-03-28 23:30:44 +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!