Merge commit 'b5dbafd164af7113e208de9b36068046f5ce8678' into f_sharp

pull/713/head^2
Wilfred Hughes 2024-05-14 09:56:23 +07:00
commit ac5af62606
61 changed files with 361227 additions and 602324 deletions

@ -156,7 +156,7 @@ fn main() {
TreeSitterParser {
name: "tree-sitter-f-sharp",
src_dir: "vendored_parsers/tree-sitter-f-sharp-src",
extra_files: vec!["scanner.cc"],
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-gleam",

@ -0,0 +1,43 @@
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2
[*.fs]
indent_style = space
indent_size = 2
[*.js]
indent_style = space
indent_size = 2
[*.rs]
indent_style = space
indent_size = 4
[*.{c,cc,h}]
indent_style = space
indent_size = 2
[*.{py,pyi}]
indent_style = space
indent_size = 4
[*.swift]
indent_style = space
indent_size = 4
[*.go]
indent_style = tab
indent_size = 8
[Makefile]
indent_style = tab
indent_size = 8

@ -0,0 +1,20 @@
module.exports = {
'env': {
'commonjs': true,
'es2021': true,
},
'extends': 'google',
'overrides': [
],
'parserOptions': {
'ecmaVersion': 'latest',
'sourceType': 'module',
},
'rules': {
'indent': ['error', 2, {'SwitchCase': 1}],
'max-len': [
'error',
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true},
],
},
};

@ -0,0 +1,11 @@
* text eol=lf
src/*.json linguist-generated
src/parser.c linguist-generated
src/tree_sitter/* linguist-generated
bindings/** linguist-vendored
binding.gyp linguist-vendored
setup.py linguist-vendored
Makefile linguist-vendored
Package.swift linguist-vendored

@ -1,21 +1,50 @@
name: Build/test
name: CI
on:
pull_request:
push:
branches:
- "develop"
- "main"
branches: ["main"]
paths:
- grammar.js
- src/**
- test/**
- bindings/**
- binding.gyp
pull_request:
concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true
jobs:
test:
runs-on: ${{ matrix.os }}
name: Test parser
runs-on: ${{matrix.os}}
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
os: [ubuntu-latest, windows-latest, macos-14]
steps:
- uses: actions/checkout@v4
- uses: tree-sitter/setup-action/cli@v1
- uses: tree-sitter/parser-test-action@v2
with:
generate: ${{runner.os == 'Linux'}}
fuzz:
name: Fuzz parser
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout repository
uses: actions/checkout@v4
with:
node-version: 16
- run: npm install
- run: npm test
fetch-depth: 2
- name: Check for scanner changes
id: scanner-changes
run: |-
if git diff --quiet HEAD^ -- src/scanner.c; then
printf 'changed=false\n' >> "$GITHUB_OUTPUT"
else
printf 'changed=true\n' >> "$GITHUB_OUTPUT"
fi
- name: Fuzz parser
uses: tree-sitter/fuzz-action@v4
if: steps.scanner-changes.outputs.changed == 'true'

@ -1,8 +1,36 @@
Cargo.lock
package-lock.json
node_modules
build
*.log
examples/*
*.o
# Rust artifacts
/Cargo.lock
/target/
# Node artifacts
/build/
/node_modules/
# Swift artifacts
/.build/
# Python artifacts
/dist/
*.egg-info
*.whl
# Zig artifacts
/zig-cache/
/zig-out/
# C artifacts
*.a
*.so
*.so.*
*.dylib
*.dll
*.pc
# Example dirs
/examples/*/
# Grammar volatiles
dsl.d.ts
*.wasm
*.obj
*.o

@ -0,0 +1,17 @@
bindings/c
bindings/go
bindings/python
bindings/rust
bindings/swift
Cargo.toml
Makefile
examples
pyproject.toml
setup.py
test
.editorconfig
.github
.gitignore
.gitattributes
.gitmodules
.npmignore

@ -5,7 +5,7 @@ version = "0.0.1"
keywords = ["incremental", "parsing", "fsharp"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/nsidorenco/tree-sitter-fsharp"
edition = "2018"
edition = "2021"
license = "MIT"
build = "bindings/rust/build.rs"
@ -20,7 +20,7 @@ include = [
path = "bindings/rust/lib.rs"
[dependencies]
tree-sitter = "~0.20"
tree-sitter = ">=0.21.0"
[build-dependencies]
cc = "1.0"
cc = "1.0.89"

@ -0,0 +1,110 @@
VERSION := 0.0.1
LANGUAGE_NAME := tree-sitter-fsharp
# repository
SRC_DIR := src
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)
ifeq ($(PARSER_URL),)
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
PARSER_URL := $(subst :,/,$(PARSER_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
endif
endif
TS ?= tree-sitter
# ABI versioning
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))
# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig
# object files
OBJS := $(patsubst %.c,%.o,$(wildcard $(SRC_DIR)/*.c))
# flags
ARFLAGS := rcs
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC
# OS-specific bits
ifeq ($(OS),Windows_NT)
$(error "Windows is not supported")
else ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
else
SOEXT = so
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
LINKSHARED := $(LINKSHARED)-shared -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
endif
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
endif
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif
all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc
lib$(LANGUAGE_NAME).a: $(OBJS)
$(AR) $(ARFLAGS) $@ $^
lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ifneq ($(STRIP),)
$(STRIP) $@
endif
$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
sed -e 's|@URL@|$(PARSER_URL)|' \
-e 's|@VERSION@|$(VERSION)|' \
-e 's|@LIBDIR@|$(LIBDIR)|' \
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
-e 's|@REQUIRES@|$(REQUIRES)|' \
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' $< > $@
$(SRC_DIR)/parser.c: grammar.js
$(TS) generate --no-bindings
install: all
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)
uninstall:
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
clean:
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)
test:
$(TS) test
.PHONY: all install uninstall clean test

@ -0,0 +1,48 @@
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "TreeSitterFsharp",
platforms: [.macOS(.v10_13), .iOS(.v11)],
products: [
.library(name: "TreeSitterFsharp", targets: ["TreeSitterFsharp"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterFsharp",
path: ".",
exclude: [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/c",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"prebuilds",
"grammar.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
"examples",
".editorconfig",
".github",
".gitignore",
".gitattributes",
".gitmodules",
],
sources: [
"src/parser.c",
// NOTE: if your language has an external scanner, add it here.
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
],
cLanguageStandard: .c11
)

@ -10,8 +10,8 @@ Next, the grammar can be build using `npm run build`, or used to parse a file wi
### Project structure
The parser consists of two parts:
- `src/scanner.cc` 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 `$.virtual_open_section` and `virtual_end_section` tokens.
- `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.
@ -22,7 +22,7 @@ local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.fsharp = {
install_info = {
url = "path/to/tree-sitter-fsharp",
files = {"src/scanner.cc", "src/parser.c" }
files = {"src/scanner.c", "src/parser.c" }
},
filetype = "fsharp",
}
@ -33,16 +33,14 @@ local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
parser_config.fsharp = {
install_info = {
url = "https://github.com/Nsidorenco/tree-sitter-fsharp",
branch = "develop",
files = {"src/scanner.cc", "src/parser.c" },
generate_requires_npm = true,
requires_generate_from_grammar = true
branch = "main",
files = {"src/scanner.c", "src/parser.c" },
},
filetype = "fsharp",
}
```
Then run `:TSInstallFromGrammar fsharp` inside Nvim.
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.

@ -2,26 +2,19 @@
"targets": [
{
"target_name": "tree_sitter_fsharp_binding",
"dependencies": [
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
"src",
],
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
"src/scanner.cc",
"src/scanner.c",
],
"cflags_c": [
"-std=c99",
],
'actions': [
{
'action_name': 'generate parser',
'inputs': ['grammar.js'],
'outputs': ['src'],
'action': ['tree-sitter', 'generate'],
'message': 'generated parser'
}
"-std=c11",
],
}
]

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_FSHARP_H_
#define TREE_SITTER_FSHARP_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
const TSLanguage *tree_sitter_fsharp(void);
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_FSHARP_H_

@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@
Name: tree-sitter-fsharp
Description: Fsharp grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-fsharp
Cflags: -I${includedir}

@ -0,0 +1,13 @@
package tree_sitter_fsharp
// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
// // NOTE: if your language has an external scanner, add it here.
import "C"
import "unsafe"
// Get the tree-sitter Language for this grammar.
func Language() unsafe.Pointer {
return unsafe.Pointer(C.tree_sitter_fsharp())
}

@ -0,0 +1,15 @@
package tree_sitter_fsharp_test
import (
"testing"
tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-fsharp"
)
func TestCanLoadGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(tree_sitter_fsharp.Language())
if language == nil {
t.Errorf("Error loading Fsharp grammar")
}
}

@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-fsharp
go 1.22
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8

@ -1,28 +1,20 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
#include <napi.h>
using namespace v8;
typedef struct TSLanguage TSLanguage;
extern "C" TSLanguage * tree_sitter_fsharp();
extern "C" TSLanguage *tree_sitter_fsharp();
namespace {
// "tree-sitter", "language" hashed with BLAKE2
const napi_type_tag LANGUAGE_TYPE_TAG = {
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
};
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_fsharp());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("fsharp").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports["name"] = Napi::String::New(env, "fsharp");
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_fsharp());
language.TypeTag(&LANGUAGE_TYPE_TAG);
exports["language"] = language;
return exports;
}
NODE_MODULE(tree_sitter_fsharp_binding, Init)
} // namespace
NODE_API_MODULE(tree_sitter_fsharp_binding, Init)

@ -0,0 +1,28 @@
type BaseNode = {
type: string;
named: boolean;
};
type ChildNode = {
multiple: boolean;
required: boolean;
types: BaseNode[];
};
type NodeInfo =
| (BaseNode & {
subtypes: BaseNode[];
})
| (BaseNode & {
fields: { [name: string]: ChildNode };
children: ChildNode[];
});
type Language = {
name: string;
language: unknown;
nodeTypeInfo: NodeInfo[];
};
declare const language: Language;
export = language;

@ -1,18 +1,6 @@
try {
module.exports = require("../../build/Release/tree_sitter_fsharp_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_fsharp_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
const root = require("path").join(__dirname, "..", "..");
module.exports = require("node-gyp-build")(root);
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");

@ -0,0 +1,5 @@
"Fsharp grammar for tree-sitter"
from ._binding import language
__all__ = ["language"]

@ -0,0 +1,27 @@
#include <Python.h>
typedef struct TSLanguage TSLanguage;
TSLanguage *tree_sitter_fsharp(void);
static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_fsharp());
}
static PyMethodDef methods[] = {
{"language", _binding_language, METH_NOARGS,
"Get the tree-sitter language for this grammar."},
{NULL, NULL, 0, NULL}
};
static struct PyModuleDef module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_binding",
.m_doc = NULL,
.m_size = -1,
.m_methods = methods
};
PyMODINIT_FUNC PyInit__binding(void) {
return PyModule_Create(&module);
}

@ -2,39 +2,18 @@ fn main() {
let src_dir = std::path::Path::new("src");
let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
c_config.std("c11").include(src_dir);
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C,
// then include this block of code:
// NOTE: if your language uses an external scanner, uncomment this block:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
// If your language uses an external scanner written in C++,
// then include this block of code:
/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.compile("tree-sitter-fsharp");
}

@ -1,13 +1,15 @@
//! This crate provides fsharp language support for the [tree-sitter][] parsing library.
//! This crate provides Fsharp language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let code = r#"
//! "#;
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_fsharp::language()).expect("Error loading fsharp grammar");
//! parser.set_language(&tree_sitter_fsharp::language()).expect("Error loading Fsharp grammar");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
@ -31,14 +33,14 @@ pub fn language() -> Language {
/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
// Uncomment these to include any queries that this grammar contains
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
#[cfg(test)]
mod tests {
@ -46,7 +48,7 @@ mod tests {
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading fsharp language");
.set_language(&super::language())
.expect("Error loading Fsharp grammar");
}
}

@ -0,0 +1,16 @@
#ifndef TREE_SITTER_FSHARP_H_
#define TREE_SITTER_FSHARP_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
const TSLanguage *tree_sitter_fsharp(void);
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_FSHARP_H_

@ -0,0 +1,14 @@
namespace test
module Json =
[<Literal>]
let MyPayload =
"""
{
"prop1": []
"prop2": {
"prop3": true,
"prop4": 1,
},
}
"""

@ -0,0 +1,4 @@
type A = {
B: int[]
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,27 +1,57 @@
{
"name": "tree-sitter-fsharp",
"version": "1.0.0",
"version": "0.0.1",
"description": "",
"repository": "https://github.com/tree-sitter/tree-sitter-fsharp",
"license": "MIT",
"author": "Nikolaj Sidorenco",
"main": "bindings/node",
"scripts": {
"build": "tree-sitter generate",
"test": "tree-sitter generate && tree-sitter test",
"parse": "tree-sitter generate && tree-sitter parse",
"debug": "tree-sitter generate && tree-sitter parse -d"
"types": "bindings/node",
"files": [
"grammar.js",
"binding.gyp",
"bindings/node/*",
"queries/*",
"src/**"
],
"devDependencies": {
"eslint": "^9.2.0",
"eslint-config-google": "^0.14.0",
"prebuildify": "^6.0.1",
"tree-sitter-cli": "^0.22.6"
},
"author": "Nikolaj Sidorenco",
"license": "MIT",
"dependencies": {
"nan": "^2.16.0"
"peerDependencies": {
"tree-sitter": "^0.21.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.6"
"peerDependenciesMeta": {
"tree_sitter": {
"optional": true
}
},
"scripts": {
"build": "tree-sitter generate --no-bindings",
"lint": "eslint grammar.js",
"parse": "tree-sitter parse",
"debug": "tree-sitter parse -d",
"test": "tree-sitter test",
"install": "node-gyp-build",
"prebuildify": "prebuildify --napi --strip"
},
"tree-sitter": [
{
"scope": "source.fsharp",
"file-types": [ "fs", "fsx"]
"file-types": [
"fs",
"fsx"
],
"injection-regex": "fs",
"highlights": "queries/highlights.scm",
"injections": "queries/injections.scm",
"tags": "queries/tags.scm"
}
]
],
"dependencies": {
"node-addon-api": "^8.0.0",
"node-gyp-build": "^4.8.1"
}
}

@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "tree-sitter-fsharp"
description = "Fsharp grammar for tree-sitter"
version = "0.0.1"
keywords = ["incremental", "parsing", "tree-sitter", "fsharp"]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Topic :: Software Development :: Compilers",
"Topic :: Text Processing :: Linguistic",
"Typing :: Typed"
]
requires-python = ">=3.8"
license.text = "MIT"
readme = "README.md"
[project.urls]
Homepage = "https://github.com/tree-sitter/tree-sitter-fsharp"
[project.optional-dependencies]
core = ["tree-sitter~=0.21"]
[tool.cibuildwheel]
build = "cp38-*"
build-frontend = "build"

@ -4,13 +4,116 @@
[
(line_comment)
(block_comment)
(block_comment_content)
] @comment
] @comment @spell
(xml_doc) @comment.documentation @spell
((identifier) @variable
(#set! "priority" 90))
((identifier_pattern (long_identifier (identifier) @character.special))
(#match? @character.special "^\_.*")
(#set! "priority" 90))
(const) @constant
;; ----------------------------------------------------------------------------
;; Punctuation
(wildcard_pattern) @character.special
(type_definition (_ (type_name (identifier) @type.definition)))
(type) @type
(member_signature
.
(identifier) @function.member
(curried_spec
(arguments_spec
"*"* @operator
(argument_spec
(argument_name_spec
"?"* @character.special
name: (_) @variable.parameter)
(_) @type))))
[
(union_type_case)
(rules
(rule
(identifier_pattern
(long_identifier)
.
(long_identifier) @variable)))
] @type
(fsi_directive_decl . (string) @module)
(import_decl . (_) @module)
(named_module
name: (_) @module)
(namespace
name: (_) @module)
(module_defn
.
(_) @module)
(field_initializer
field: (_) @property)
(record_fields
(record_field
.
(identifier) @property))
(dot_expression
base: (_) @variable
field: (_) @variable.member)
(value_declaration_left . (_) @variable)
(function_declaration_left
. (_) @function
[
(argument_patterns)
(argument_patterns (long_identifier (identifier)))
] @variable.parameter)
(member_defn
(method_or_prop_defn
(property_or_ident
instance: (identifier) @variable.parameter.builtin
method: (identifier) @variable.member)
args: _ @variable.parameter))
(application_expression) @function.call
(compiler_directive_decl
.
(_) @keyword.directive.define) @keyword.directive
[
(string)
(triple_quoted_string)
] @spell @string
[
(int)
(int16)
(int32)
(int64)
] @number
[
(float)
(decimal)
] @number.float
(bool) @boolean
(attribute) @attribute
[
"("
")"
@ -20,31 +123,35 @@
"]"
"[|"
"|]"
"{|"
"|}"
"[<"
">]"
] @punctuation.bracket
(format_string_eval
[
"{"
"}"
] @punctuation.special)
[
","
","
";"
] @punctuation.delimiter
[
"|"
"|"
"="
">"
"<"
"-"
"~"
"->"
(infix_op)
(prefix_op)
(symbolic_op)
] @operator
(attribute) @attribute
[
"if"
"then"
@ -58,139 +165,99 @@
"&&"
"||"
"then"
] @keyword.control.conditional
] @keyword.conditional
[
"and"
"or"
"not"
"upcast"
"downcast"
] @keyword.operator
[
"return"
"return!"
] @keyword.control.return
"yield"
"yield!"
] @keyword.return
[
"for"
"while"
] @keyword.control.return
"downto"
"to"
] @keyword.repeat
[
"open"
"#r"
"#load"
] @keyword.control.import
] @keyword.import
[
"abstract"
"delegate"
"static"
"inline"
"internal"
"mutable"
"override"
"private"
"public"
"rec"
] @keyword.storage.modifier
"global"
(access_modifier)
] @keyword.modifier
[
"enum"
"let"
"let!"
"use"
"use!"
"member"
"module"
"namespace"
] @keyword.function
[
"enum"
"type"
] @keyword.storage
"inherit"
"interface"
] @keyword.type
[
"try"
"with"
"finally"
] @keyword.exception
[
"as"
"assert"
"begin"
"end"
"done"
"default"
"in"
"do"
"do!"
"done"
"downcast"
"downto"
"end"
"event"
"field"
"finally"
"fun"
"function"
"get"
"global"
"inherit"
"interface"
"set"
"lazy"
"new"
"not"
"null"
"of"
"param"
"property"
"set"
"struct"
"try"
"upcast"
"use"
"use!"
"val"
"with"
"yield"
"yield!"
"module"
"namespace"
] @keyword
[
"true"
"false"
"unit"
] @constant.builtin
[
(type)
(const)
] @constant
[
(union_type_case)
(rules (rule (identifier_pattern)))
] @type.enum
(fsi_directive_decl (string) @namespace)
[
(import_decl (long_identifier))
(named_module (long_identifier))
(namespace (long_identifier))
(named_module
name: (long_identifier) )
(namespace
name: (long_identifier) )
] @namespace
(dot_expression
base: (long_identifier_or_op) @variable.other.member
field: (long_identifier_or_op) @function)
[
;;(value_declaration_left (identifier_pattern) )
(function_declaration_left (identifier) )
(call_expression (long_identifier_or_op (long_identifier)))
;;(application_expression (long_identifier_or_op (long_identifier)))
] @function
[
(string)
(triple_quoted_string)
] @string
[
(int)
(int16)
(int32)
(int64)
(float)
(decimal)
] @constant.numeric
(long_identifier
(identifier)* @module
.
(identifier))

@ -0,0 +1,49 @@
[
(value_declaration)
(module_defn)
(paren_expression)
(brace_expression)
(anon_record_expression)
(list_expression)
(array_expression)
(while_expression)
(if_expression)
(elif_expression)
(rule)
] @indent.begin
((rules) @indent.begin
(#set! indent.start_at_same_line))
((application_expression) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(paren_expression
")" @indent.branch)
(brace_expression
"}" @indent.branch)
(anon_record_expression
"|}" @indent.branch)
(list_expression
"]" @indent.branch)
(array_expression
"|]" @indent.branch)
(ERROR
.
[
"module"
"do"
]) @indent.begin
[
(string)
(line_comment)
(block_comment)
(xml_doc)
] @indent.auto

@ -0,0 +1,8 @@
([
(line_comment)
(block_comment_content)
] @injection.content
(#set! injection.language "comment"))
((xml_doc (xml_doc_content) @injection.content)
(#set! injection.language "xml"))

@ -0,0 +1,33 @@
(identifier) @local.reference
[
(namespace)
(named_module)
(function_or_value_defn)
] @local.scope
(value_declaration_left
.
[
(_ (identifier) @local.definition.var)
(_ (_ (identifier) @local.definition.var))
(_ (_ (_ (identifier) @local.definition.var)))
(_ (_ (_ (_ (identifier) @local.definition.var))))
(_ (_ (_ (_ (_ (identifier) @local.definition.var)))))
(_ (_ (_ (_ (_ (_ (identifier) @local.definition.var))))))
])
(function_declaration_left
.
((_) @local.definition.function
(#set! "definition.function.scope" "parent"))
((argument_patterns
[
(_ (identifier) @local.definition.parameter)
(_ (_ (identifier) @local.definition.parameter))
(_ (_ (_ (identifier) @local.definition.parameter)))
(_ (_ (_ (_ (identifier) @local.definition.parameter))))
(_ (_ (_ (_ (_ (identifier) @local.definition.parameter)))))
(_ (_ (_ (_ (_ (_ (identifier) @local.definition.parameter))))))
])
))

@ -0,0 +1,57 @@
from os.path import isdir, join
from platform import system
from setuptools import Extension, find_packages, setup
from setuptools.command.build import build
from wheel.bdist_wheel import bdist_wheel
class Build(build):
def run(self):
if isdir("queries"):
dest = join(self.build_lib, "tree_sitter_fsharp", "queries")
self.copy_tree("queries", dest)
super().run()
class BdistWheel(bdist_wheel):
def get_tag(self):
python, abi, platform = super().get_tag()
if python.startswith("cp"):
python, abi = "cp38", "abi3"
return python, abi, platform
setup(
packages=find_packages("bindings/python"),
package_dir={"": "bindings/python"},
package_data={
"tree_sitter_fsharp": ["*.pyi", "py.typed"],
"tree_sitter_fsharp.queries": ["*.scm"],
},
ext_package="tree_sitter_fsharp",
ext_modules=[
Extension(
name="_binding",
sources=[
"bindings/python/tree_sitter_fsharp/binding.c",
"src/parser.c",
# NOTE: if your language uses an external scanner, add it here.
],
extra_compile_args=(
["-std=c11"] if system() != 'Windows' else []
),
define_macros=[
("Py_LIMITED_API", "0x03080000"),
("PY_SSIZE_T_CLEAN", None)
],
include_dirs=["src"],
py_limited_api=True,
)
],
cmdclass={
"build": Build,
"bdist_wheel": BdistWheel
},
zip_safe=False
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,346 @@
#include "tree_sitter/alloc.h"
#include "tree_sitter/array.h"
#include "tree_sitter/parser.h"
enum TokenType {
NEWLINE,
INDENT,
DEDENT,
THEN,
ELSE,
ELIF,
TRIPLE_QUOTE_CONTENT,
BLOCK_COMMENT_CONTENT,
LINE_COMMENT,
ERROR_SENTINEL
};
typedef struct {
Array(uint16_t) indents;
} Scanner;
static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
static inline bool scan_block_comment(TSLexer *lexer) {
lexer->mark_end(lexer);
if (lexer->lookahead != '(')
return false;
advance(lexer);
if (lexer->lookahead != '*')
return false;
advance(lexer);
while (true) {
switch (lexer->lookahead) {
case '(':
scan_block_comment(lexer);
break;
case '*':
advance(lexer);
if (lexer->lookahead == ')') {
advance(lexer);
return true;
}
break;
case '\0':
return true;
default:
advance(lexer);
}
}
}
static inline bool is_infix_op_start(TSLexer *lexer) {
switch (lexer->lookahead) {
case '+':
case '-':
case '%':
case '&':
case '=':
case '?':
case '<':
case '>':
case '^':
return true;
case '/':
skip(lexer);
return lexer->lookahead != '/';
case '.':
skip(lexer);
return lexer->lookahead != '.';
case '!':
skip(lexer);
return lexer->lookahead == '=';
case ':':
skip(lexer);
return lexer->lookahead == '=' || lexer->lookahead == ':';
case 'o':
skip(lexer);
return lexer->lookahead == 'r';
case '@':
case '$':
skip(lexer);
return lexer->lookahead != '"';
default:
return false;
}
}
static inline bool is_bracket_end(TSLexer *lexer) {
switch (lexer->lookahead) {
case ')':
case ']':
case '}':
return true;
default:
return false;
}
}
bool tree_sitter_fsharp_external_scanner_scan(void *payload, TSLexer *lexer,
const bool *valid_symbols) {
Scanner *scanner = (Scanner *)payload;
bool error_recovery_mode = valid_symbols[ERROR_SENTINEL];
if (valid_symbols[TRIPLE_QUOTE_CONTENT] && !error_recovery_mode) {
lexer->mark_end(lexer);
while (true) {
if (lexer->lookahead == '\0') {
break;
}
if (lexer->lookahead != '"') {
advance(lexer);
} else {
lexer->mark_end(lexer);
skip(lexer);
if (lexer->lookahead == '"') {
skip(lexer);
if (lexer->lookahead == '"') {
skip(lexer);
break;
}
}
lexer->mark_end(lexer);
}
}
lexer->result_symbol = TRIPLE_QUOTE_CONTENT;
return true;
}
lexer->mark_end(lexer);
bool found_end_of_line = false;
bool found_start_of_infix_op = false;
bool found_bracket_end = false;
uint32_t indent_length = lexer->get_column(lexer);
for (;;) {
if (lexer->lookahead == '\n') {
found_end_of_line = true;
indent_length = 0;
skip(lexer);
} else if (lexer->lookahead == ' ') {
indent_length++;
skip(lexer);
} else if (lexer->lookahead == '\r' || lexer->lookahead == '\f') {
indent_length = 0;
skip(lexer);
} else if (lexer->lookahead == '\t') {
indent_length += 8;
skip(lexer);
} else if (lexer->eof(lexer)) {
found_end_of_line = true;
break;
} else {
break;
}
}
// printf("lexer->lookahead = %c\n", lexer->lookahead);
// printf("valid_symbols[INDENT] = %d\n", valid_symbols[INDENT]);
// printf("valid_symbols[DEDENT] = %d\n", valid_symbols[DEDENT]);
if (valid_symbols[NEWLINE] && lexer->lookahead == ';') {
advance(lexer);
lexer->mark_end(lexer);
lexer->result_symbol = NEWLINE;
return true;
}
if (valid_symbols[THEN] && lexer->lookahead == 't') {
advance(lexer);
if (lexer->lookahead == 'h') {
advance(lexer);
if (lexer->lookahead == 'e') {
advance(lexer);
if (lexer->lookahead == 'n') {
advance(lexer);
lexer->mark_end(lexer);
lexer->result_symbol = THEN;
return true;
}
}
}
return false;
} else if (lexer->lookahead == 'e' &&
(valid_symbols[ELSE] || valid_symbols[ELIF])) {
advance(lexer);
if (lexer->lookahead == 'l') {
advance(lexer);
if (lexer->lookahead == 's' && valid_symbols[ELSE]) {
advance(lexer);
if (lexer->lookahead == 'e') {
advance(lexer);
lexer->mark_end(lexer);
lexer->result_symbol = ELSE;
array_pop(&scanner->indents);
return true;
}
} else if (lexer->lookahead == 'i' && valid_symbols[ELIF]) {
advance(lexer);
if (lexer->lookahead == 'f') {
advance(lexer);
lexer->mark_end(lexer);
lexer->result_symbol = ELIF;
array_pop(&scanner->indents);
return true;
}
}
}
return false;
} else if (is_infix_op_start(lexer)) {
found_start_of_infix_op = true;
} else if (lexer->lookahead == '|') {
skip(lexer);
switch (lexer->lookahead) {
case ']':
case '}':
found_bracket_end = true;
break;
case ' ':
break;
default:
found_start_of_infix_op = true;
break;
}
} else if (is_bracket_end(lexer)) {
found_bracket_end = true;
}
if (error_recovery_mode && scanner->indents.size > 0) {
array_pop(&scanner->indents);
lexer->result_symbol = DEDENT;
return true;
}
if (valid_symbols[INDENT] && !found_start_of_infix_op && !found_bracket_end &&
!error_recovery_mode) {
array_push(&scanner->indents, indent_length);
lexer->result_symbol = INDENT;
return true;
}
if (scanner->indents.size > 0) {
uint16_t current_indent_length = *array_back(&scanner->indents);
if (found_bracket_end && valid_symbols[DEDENT]) {
array_pop(&scanner->indents);
lexer->result_symbol = DEDENT;
return true;
}
if (found_end_of_line) {
if (indent_length == current_indent_length && indent_length > 0 &&
!found_start_of_infix_op && !found_bracket_end) {
if (valid_symbols[NEWLINE] && !error_recovery_mode) {
lexer->result_symbol = NEWLINE;
return true;
}
}
if (indent_length < current_indent_length && !found_bracket_end) {
array_pop(&scanner->indents);
lexer->result_symbol = DEDENT;
return true;
}
}
}
if (valid_symbols[BLOCK_COMMENT_CONTENT] && !error_recovery_mode) {
lexer->mark_end(lexer);
while (true) {
if (lexer->lookahead == '\0') {
break;
}
if (lexer->lookahead != '(' && lexer->lookahead != '*') {
advance(lexer);
} else if (lexer->lookahead == '*') {
lexer->mark_end(lexer);
advance(lexer);
if (lexer->lookahead == ')') {
break;
}
} else if (scan_block_comment(lexer)) {
lexer->mark_end(lexer);
advance(lexer);
if (lexer->lookahead == '*') {
break;
}
}
}
lexer->result_symbol = BLOCK_COMMENT_CONTENT;
return true;
}
return false;
}
unsigned tree_sitter_fsharp_external_scanner_serialize(void *payload,
char *buffer) {
Scanner *scanner = (Scanner *)payload;
size_t size = 0;
uint32_t iter = 1;
for (; iter < scanner->indents.size &&
size < TREE_SITTER_SERIALIZATION_BUFFER_SIZE;
++iter) {
buffer[size++] = (char)*array_get(&scanner->indents, iter);
}
return size;
}
void tree_sitter_fsharp_external_scanner_deserialize(void *payload,
const char *buffer,
unsigned length) {
Scanner *scanner = (Scanner *)payload;
array_delete(&scanner->indents);
array_push(&scanner->indents, 0);
if (length > 0) {
size_t size = 0;
for (; size < length; size++) {
array_push(&scanner->indents, (unsigned char)buffer[size]);
}
}
}
void *tree_sitter_fsharp_external_scanner_create() {
Scanner *scanner = ts_calloc(1, sizeof(Scanner));
array_init(&scanner->indents);
tree_sitter_fsharp_external_scanner_deserialize(scanner, NULL, 0);
return scanner;
}
void tree_sitter_fsharp_external_scanner_destroy(void *payload) {
Scanner *scanner = (Scanner *)payload;
array_delete(&scanner->indents);
ts_free(scanner);
}

@ -1,372 +0,0 @@
#include <tree_sitter/parser.h>
#include <vector>
#include <utility>
#include <cwctype>
#include <cstring>
#include <cassert>
#include <stdio.h>
#include <string>
#include <algorithm>
namespace {
using std::vector;
using std::string;
enum TokenType {
VIRTUAL_OPEN_SECTION,
VIRTUAL_END_SECTION,
VIRTUAL_END_ALIGNED,
BLOCK_COMMENT_CONTENT,
};
bool in_error_recovery(const bool *valid_symbols) {
return
(valid_symbols[VIRTUAL_OPEN_SECTION] &&
valid_symbols[VIRTUAL_END_SECTION] &&
valid_symbols[VIRTUAL_END_ALIGNED]);
}
struct Scanner {
Scanner() { }
unsigned serialize(char *buffer) {
size_t i = 0;
size_t runback_count = runback.size();
if (runback_count > UINT8_MAX)
runback_count = UINT8_MAX;
buffer[i++] = runback_count;
if (runback_count > 0)
{
memcpy(&buffer[i], runback.data(), runback_count);
}
i += runback_count;
size_t indent_length_length = sizeof(indent_length);
buffer[i++] = indent_length_length;
if (indent_length_length > 0)
{
memcpy(&buffer[i], &indent_length, indent_length_length);
}
i += indent_length_length;
vector<uint32_t>::iterator
iter = indent_length_stack.begin() + 1,
end = indent_length_stack.end();
for (; iter != end && i < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; ++iter)
{
buffer[i++] = *iter;
}
return i;
}
void deserialize(const char *buffer, unsigned length) {
runback.clear();
indent_length_stack.clear();
indent_length_stack.push_back(0);
if (length > 0)
{
size_t i = 0;
size_t runback_count = (uint8_t)buffer[i++];
runback.resize(runback_count);
if (runback_count > 0)
{
memcpy(runback.data(), &buffer[i], runback_count);
}
i += runback_count;
size_t indent_length_length = buffer[i++];
if (indent_length_length > 0)
{
memcpy(&indent_length, &buffer[i], indent_length_length);
}
i += indent_length_length;
for (; i < length; i++)
{
indent_length_stack.push_back(buffer[i]);
}
}
}
void advance(TSLexer *lexer) {
lexer->advance(lexer, false);
}
void skip(TSLexer *lexer) {
lexer->advance(lexer, true);
}
bool isWS(TSLexer *lexer) {
return lexer->lookahead == ' ' || lexer->lookahead == '\r' || lexer->lookahead == '\n';
}
bool scan_block_comment(TSLexer *lexer) {
lexer->mark_end(lexer);
if (lexer->lookahead != '(')
return false;
advance(lexer);
if (lexer->lookahead != '*')
return false;
advance(lexer);
while (true) {
switch (lexer->lookahead) {
case '(':
scan_block_comment(lexer);
break;
case '*':
advance(lexer);
if (lexer->lookahead == ')') {
advance(lexer);
return true;
}
break;
case '\0':
return true;
default:
advance(lexer);
}
}
}
void advance_to_line_end(TSLexer *lexer) {
while (true) {
if (lexer->lookahead == '\n') {
break;
} else if (lexer->eof(lexer)) {
break;
} else {
advance(lexer);
}
}
}
bool scan(TSLexer *lexer, const bool *valid_symbols) {
if (in_error_recovery(valid_symbols))
return false;
// First handle eventual runback tokens, we saved on a previous scan op
if (!runback.empty() && runback.back() == 0 && valid_symbols[VIRTUAL_END_ALIGNED])
{
runback.pop_back();
lexer->result_symbol = VIRTUAL_END_ALIGNED;
return true;
}
if (!runback.empty() && runback.back() == 1 && valid_symbols[VIRTUAL_END_SECTION])
{
runback.pop_back();
lexer->result_symbol = VIRTUAL_END_SECTION;
return true;
}
runback.clear();
// Check if we have newlines and how much indentation
bool has_newline = false;
bool can_call_mark_end = true;
lexer->mark_end(lexer);
while (true) {
if (lexer->lookahead == ' ') {
skip(lexer);
}
else if (lexer->lookahead == '\n') {
skip(lexer);
has_newline = true;
while (true)
{
if (lexer->lookahead == ' ')
{
skip(lexer);
}
else
{
indent_length = lexer->get_column(lexer);
break;
}
}
}
else if (lexer->lookahead == '\r') {
skip(lexer);
}
else if (valid_symbols[VIRTUAL_END_ALIGNED] && lexer->lookahead == ';') {
advance(lexer);
lexer->mark_end(lexer);
lexer->result_symbol = VIRTUAL_END_ALIGNED;
return true;
}
else if (valid_symbols[VIRTUAL_END_SECTION] && lexer->lookahead == ')') {
lexer->result_symbol = VIRTUAL_END_SECTION;
indent_length_stack.pop_back();
return true;
}
else if (valid_symbols[VIRTUAL_END_SECTION] && lexer->lookahead == ']') {
lexer->result_symbol = VIRTUAL_END_SECTION;
indent_length_stack.pop_back();
return true;
}
else if (valid_symbols[VIRTUAL_END_SECTION] && lexer->lookahead == '}') {
lexer->result_symbol = VIRTUAL_END_SECTION;
indent_length_stack.pop_back();
return true;
}
else if (valid_symbols[VIRTUAL_END_SECTION] && lexer->lookahead == '|') {
skip(lexer);
if (lexer->lookahead == '}' || lexer->lookahead == ']') {
lexer->result_symbol = VIRTUAL_END_SECTION;
indent_length_stack.pop_back();
return true;
}
}
else if (lexer->eof(lexer)) {
if (valid_symbols[VIRTUAL_END_SECTION])
{
lexer->result_symbol = VIRTUAL_END_SECTION;
return true;
}
if (valid_symbols[VIRTUAL_END_ALIGNED])
{
lexer->result_symbol = VIRTUAL_END_ALIGNED;
return true;
}
break;
}
else { break; }
}
bool closing = lexer->lookahead == ']' || lexer->lookahead == ')' || lexer->lookahead == '}';
// Open section if the grammar lets us but only push to indent stack if we go further down in the stack
if (valid_symbols[VIRTUAL_OPEN_SECTION] && !lexer->eof(lexer)) {
indent_length_stack.push_back(lexer->get_column(lexer));
if (closing) {
return false;
}
if (lexer->lookahead == '|') {
skip(lexer);
if (lexer->lookahead == '}' || lexer->lookahead == ']') {
return false;
}
}
lexer->result_symbol = VIRTUAL_OPEN_SECTION;
return true;
}
else if (valid_symbols[BLOCK_COMMENT_CONTENT]) {
if (!can_call_mark_end) { return false; }
lexer->mark_end(lexer);
while (true) {
if (lexer->lookahead == '\0') { break; }
if (lexer->lookahead != '(' && lexer->lookahead != '*') {
advance(lexer);
}
else if (lexer->lookahead == '*') {
lexer->mark_end(lexer);
advance(lexer);
if (lexer->lookahead == ')')
{
break;
}
}
else if (scan_block_comment(lexer))
{
lexer->mark_end(lexer);
advance(lexer);
if (lexer->lookahead == '*')
{
break;
}
}
}
lexer->result_symbol = BLOCK_COMMENT_CONTENT;
return true;
}
else if (has_newline) {
// We had a newline now it's time to check if we need to add multiple tokens to get back up to the right level
runback.clear();
while (indent_length <= indent_length_stack.back()) {
if (indent_length == indent_length_stack.back()) {
// Don't insert VIRTUAL_END_DECL when there is a line comment incoming
if (lexer->lookahead == '/') {
skip(lexer);
if (lexer->lookahead == '/') { break; }
}
// Don't insert VIRTUAL_END_DECL when there is a block comment incoming
if (lexer->lookahead == '(') {
skip(lexer);
if (lexer->lookahead == '*') { break; }
}
runback.push_back(0);
break;
}
else if (indent_length < indent_length_stack.back()) {
indent_length_stack.pop_back();
runback.push_back(1);
}
}
// Our list is the wrong way around, reverse it
std::reverse(runback.begin(), runback.end());
// Handle the first runback token if we have them, if there are more they will be handled on the next scan operation
if (!runback.empty() && runback.back() == 0 && valid_symbols[VIRTUAL_END_ALIGNED]) {
runback.pop_back();
lexer->result_symbol = VIRTUAL_END_ALIGNED;
return true;
}
if (!runback.empty() && runback.back() == 1 && valid_symbols[VIRTUAL_END_SECTION]) {
runback.pop_back();
lexer->result_symbol = VIRTUAL_END_SECTION;
return true;
}
else if (lexer->eof(lexer) && valid_symbols[VIRTUAL_END_SECTION]) {
lexer->result_symbol = VIRTUAL_END_SECTION;
return true;
}
}
return false;
}
uint32_t indent_length;
vector<uint32_t> indent_length_stack;
vector<uint8_t> runback;
};
} // namespace end
extern "C" {
void *tree_sitter_fsharp_external_scanner_create() {
return new Scanner();
}
bool tree_sitter_fsharp_external_scanner_scan(void *payload, TSLexer *lexer,
const bool *valid_symbols) {
Scanner *scanner = static_cast<Scanner *>(payload);
return scanner->scan(lexer, valid_symbols);
}
unsigned tree_sitter_fsharp_external_scanner_serialize(void *payload, char *buffer) {
Scanner *scanner = static_cast<Scanner *>(payload);
return scanner->serialize(buffer);
}
void tree_sitter_fsharp_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
Scanner *scanner = static_cast<Scanner *>(payload);
scanner->deserialize(buffer, length);
}
void tree_sitter_fsharp_external_scanner_destroy(void *payload) {
Scanner *scanner = static_cast<Scanner *>(payload);
delete scanner;
}
}

@ -0,0 +1,54 @@
#ifndef TREE_SITTER_ALLOC_H_
#define TREE_SITTER_ALLOC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
// Allow clients to override allocation functions
#ifdef TREE_SITTER_REUSE_ALLOCATOR
extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *);
#ifndef ts_malloc
#define ts_malloc ts_current_malloc
#endif
#ifndef ts_calloc
#define ts_calloc ts_current_calloc
#endif
#ifndef ts_realloc
#define ts_realloc ts_current_realloc
#endif
#ifndef ts_free
#define ts_free ts_current_free
#endif
#else
#ifndef ts_malloc
#define ts_malloc malloc
#endif
#ifndef ts_calloc
#define ts_calloc calloc
#endif
#ifndef ts_realloc
#define ts_realloc realloc
#endif
#ifndef ts_free
#define ts_free free
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_ALLOC_H_

@ -0,0 +1,290 @@
#ifndef TREE_SITTER_ARRAY_H_
#define TREE_SITTER_ARRAY_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "./alloc.h"
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#pragma warning(disable : 4101)
#elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#endif
#define Array(T) \
struct { \
T *contents; \
uint32_t size; \
uint32_t capacity; \
}
/// Initialize an array.
#define array_init(self) \
((self)->size = 0, (self)->capacity = 0, (self)->contents = NULL)
/// Create an empty array.
#define array_new() \
{ NULL, 0, 0 }
/// Get a pointer to the element at a given `index` in the array.
#define array_get(self, _index) \
(assert((uint32_t)(_index) < (self)->size), &(self)->contents[_index])
/// Get a pointer to the first element in the array.
#define array_front(self) array_get(self, 0)
/// Get a pointer to the last element in the array.
#define array_back(self) array_get(self, (self)->size - 1)
/// Clear the array, setting its size to zero. Note that this does not free any
/// memory allocated for the array's contents.
#define array_clear(self) ((self)->size = 0)
/// Reserve `new_capacity` elements of space in the array. If `new_capacity` is
/// less than the array's current capacity, this function has no effect.
#define array_reserve(self, new_capacity) \
_array__reserve((Array *)(self), array_elem_size(self), new_capacity)
/// Free any memory allocated for this array. Note that this does not free any
/// memory allocated for the array's contents.
#define array_delete(self) _array__delete((Array *)(self))
/// Push a new `element` onto the end of the array.
#define array_push(self, element) \
(_array__grow((Array *)(self), 1, array_elem_size(self)), \
(self)->contents[(self)->size++] = (element))
/// Increase the array's size by `count` elements.
/// New elements are zero-initialized.
#define array_grow_by(self, count) \
do { \
if ((count) == 0) break; \
_array__grow((Array *)(self), count, array_elem_size(self)); \
memset((self)->contents + (self)->size, 0, (count) * array_elem_size(self)); \
(self)->size += (count); \
} while (0)
/// Append all elements from one array to the end of another.
#define array_push_all(self, other) \
array_extend((self), (other)->size, (other)->contents)
/// Append `count` elements to the end of the array, reading their values from the
/// `contents` pointer.
#define array_extend(self, count, contents) \
_array__splice( \
(Array *)(self), array_elem_size(self), (self)->size, \
0, count, contents \
)
/// Remove `old_count` elements from the array starting at the given `index`. At
/// the same index, insert `new_count` new elements, reading their values from the
/// `new_contents` pointer.
#define array_splice(self, _index, old_count, new_count, new_contents) \
_array__splice( \
(Array *)(self), array_elem_size(self), _index, \
old_count, new_count, new_contents \
)
/// Insert one `element` into the array at the given `index`.
#define array_insert(self, _index, element) \
_array__splice((Array *)(self), array_elem_size(self), _index, 0, 1, &(element))
/// Remove one element from the array at the given `index`.
#define array_erase(self, _index) \
_array__erase((Array *)(self), array_elem_size(self), _index)
/// Pop the last element off the array, returning the element by value.
#define array_pop(self) ((self)->contents[--(self)->size])
/// Assign the contents of one array to another, reallocating if necessary.
#define array_assign(self, other) \
_array__assign((Array *)(self), (const Array *)(other), array_elem_size(self))
/// Swap one array with another
#define array_swap(self, other) \
_array__swap((Array *)(self), (Array *)(other))
/// Get the size of the array contents
#define array_elem_size(self) (sizeof *(self)->contents)
/// Search a sorted array for a given `needle` value, using the given `compare`
/// callback to determine the order.
///
/// If an existing element is found to be equal to `needle`, then the `index`
/// out-parameter is set to the existing value's index, and the `exists`
/// out-parameter is set to true. Otherwise, `index` is set to an index where
/// `needle` should be inserted in order to preserve the sorting, and `exists`
/// is set to false.
#define array_search_sorted_with(self, compare, needle, _index, _exists) \
_array__search_sorted(self, 0, compare, , needle, _index, _exists)
/// Search a sorted array for a given `needle` value, using integer comparisons
/// of a given struct field (specified with a leading dot) to determine the order.
///
/// See also `array_search_sorted_with`.
#define array_search_sorted_by(self, field, needle, _index, _exists) \
_array__search_sorted(self, 0, _compare_int, field, needle, _index, _exists)
/// Insert a given `value` into a sorted array, using the given `compare`
/// callback to determine the order.
#define array_insert_sorted_with(self, compare, value) \
do { \
unsigned _index, _exists; \
array_search_sorted_with(self, compare, &(value), &_index, &_exists); \
if (!_exists) array_insert(self, _index, value); \
} while (0)
/// Insert a given `value` into a sorted array, using integer comparisons of
/// a given struct field (specified with a leading dot) to determine the order.
///
/// See also `array_search_sorted_by`.
#define array_insert_sorted_by(self, field, value) \
do { \
unsigned _index, _exists; \
array_search_sorted_by(self, field, (value) field, &_index, &_exists); \
if (!_exists) array_insert(self, _index, value); \
} while (0)
// Private
typedef Array(void) Array;
/// This is not what you're looking for, see `array_delete`.
static inline void _array__delete(Array *self) {
if (self->contents) {
ts_free(self->contents);
self->contents = NULL;
self->size = 0;
self->capacity = 0;
}
}
/// This is not what you're looking for, see `array_erase`.
static inline void _array__erase(Array *self, size_t element_size,
uint32_t index) {
assert(index < self->size);
char *contents = (char *)self->contents;
memmove(contents + index * element_size, contents + (index + 1) * element_size,
(self->size - index - 1) * element_size);
self->size--;
}
/// This is not what you're looking for, see `array_reserve`.
static inline void _array__reserve(Array *self, size_t element_size, uint32_t new_capacity) {
if (new_capacity > self->capacity) {
if (self->contents) {
self->contents = ts_realloc(self->contents, new_capacity * element_size);
} else {
self->contents = ts_malloc(new_capacity * element_size);
}
self->capacity = new_capacity;
}
}
/// This is not what you're looking for, see `array_assign`.
static inline void _array__assign(Array *self, const Array *other, size_t element_size) {
_array__reserve(self, element_size, other->size);
self->size = other->size;
memcpy(self->contents, other->contents, self->size * element_size);
}
/// This is not what you're looking for, see `array_swap`.
static inline void _array__swap(Array *self, Array *other) {
Array swap = *other;
*other = *self;
*self = swap;
}
/// This is not what you're looking for, see `array_push` or `array_grow_by`.
static inline void _array__grow(Array *self, uint32_t count, size_t element_size) {
uint32_t new_size = self->size + count;
if (new_size > self->capacity) {
uint32_t new_capacity = self->capacity * 2;
if (new_capacity < 8) new_capacity = 8;
if (new_capacity < new_size) new_capacity = new_size;
_array__reserve(self, element_size, new_capacity);
}
}
/// This is not what you're looking for, see `array_splice`.
static inline void _array__splice(Array *self, size_t element_size,
uint32_t index, uint32_t old_count,
uint32_t new_count, const void *elements) {
uint32_t new_size = self->size + new_count - old_count;
uint32_t old_end = index + old_count;
uint32_t new_end = index + new_count;
assert(old_end <= self->size);
_array__reserve(self, element_size, new_size);
char *contents = (char *)self->contents;
if (self->size > old_end) {
memmove(
contents + new_end * element_size,
contents + old_end * element_size,
(self->size - old_end) * element_size
);
}
if (new_count > 0) {
if (elements) {
memcpy(
(contents + index * element_size),
elements,
new_count * element_size
);
} else {
memset(
(contents + index * element_size),
0,
new_count * element_size
);
}
}
self->size += new_count - old_count;
}
/// A binary search routine, based on Rust's `std::slice::binary_search_by`.
/// This is not what you're looking for, see `array_search_sorted_with` or `array_search_sorted_by`.
#define _array__search_sorted(self, start, compare, suffix, needle, _index, _exists) \
do { \
*(_index) = start; \
*(_exists) = false; \
uint32_t size = (self)->size - *(_index); \
if (size == 0) break; \
int comparison; \
while (size > 1) { \
uint32_t half_size = size / 2; \
uint32_t mid_index = *(_index) + half_size; \
comparison = compare(&((self)->contents[mid_index] suffix), (needle)); \
if (comparison <= 0) *(_index) = mid_index; \
size -= half_size; \
} \
comparison = compare(&((self)->contents[*(_index)] suffix), (needle)); \
if (comparison == 0) *(_exists) = true; \
else if (comparison < 0) *(_index) += 1; \
} while (0)
/// Helper macro for the `_sorted_by` routines below. This takes the left (existing)
/// parameter by reference in order to work with the generic sorting function above.
#define _compare_int(a, b) ((int)*(a) - (int)(b))
#ifdef _MSC_VER
#pragma warning(default : 4101)
#elif defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_ARRAY_H_

@ -13,9 +13,8 @@ extern "C" {
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSStateId;
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
@ -130,9 +129,16 @@ struct TSLanguage {
* Lexer Macros
*/
#ifdef _MSC_VER
#define UNUSED __pragma(warning(suppress : 4101))
#else
#define UNUSED __attribute__((unused))
#endif
#define START_LEXER() \
bool result = false; \
bool skip = false; \
UNUSED \
bool eof = false; \
int32_t lookahead; \
goto start; \
@ -166,7 +172,7 @@ struct TSLanguage {
* Parse Table Macros
*/
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define SMALL_STATE(id) ((id) - LARGE_STATE_COUNT)
#define STATE(id) id
@ -176,7 +182,7 @@ struct TSLanguage {
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value \
.state = (state_value) \
} \
}}
@ -184,7 +190,7 @@ struct TSLanguage {
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value, \
.state = (state_value), \
.repetition = true \
} \
}}

@ -24,7 +24,8 @@ module test =
(identifier_pattern
(long_identifier
(identifier))))
(const (int))))))
(const
(int))))))
================================================================================
top-level module attributes repeated
@ -122,10 +123,170 @@ type A() =
(attribute_set
(attribute
(object_construction
(type (long_identifier (identifier)))
(type
(long_identifier
(identifier)))
(paren_expression
(const (string)))))))
(const
(string)))))))
(anon_type_defn
(type_name (identifier))
(type_name
(identifier))
(primary_constr_args)
(const (unit)))))
(const
(unit)))))
================================================================================
attribute on let binding
================================================================================
[<AutoOpen>]
module Constants =
[<Literal>]
let A = "A"
[<Literal>]
let B = "B"
module Impl =
let v = A + B
--------------------------------------------------------------------------------
(file
(module_defn
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(identifier)
(value_declaration
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(string))))
(value_declaration
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(string)))))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(long_identifier_or_op
(long_identifier
(identifier))))))))
================================================================================
attribute on let binding in namespace
================================================================================
namespace Com.Test
[<AutoOpen>]
module Constants =
[<Literal>]
let A = "A"
[<Literal>]
let B = "B"
module Impl =
let x = A + B
--------------------------------------------------------------------------------
(file
(namespace
(long_identifier
(identifier)
(identifier))
(module_defn
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(identifier)
(value_declaration
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(string))))
(value_declaration
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(string)))))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(long_identifier_or_op
(long_identifier
(identifier)))))))))

@ -69,7 +69,8 @@ let x = 1
--------------------------------------------------------------------------------
(file
(line_comment)
(xml_doc
(xml_doc_content))
(value_declaration
(function_or_value_defn
(value_declaration_left
@ -79,7 +80,7 @@ let x = 1
(const (int)))))
================================================================================
coment in simple string
comment in simple string
================================================================================
let x = "//comment in string"
@ -97,7 +98,7 @@ let x = "//comment in string"
(string)))))
================================================================================
coment in triple-quoted string
comment in triple-quoted string
================================================================================
let x = """
@ -117,7 +118,7 @@ let x = """
(triple_quoted_string)))))
================================================================================
coment in verbatim string
comment in verbatim string
================================================================================
let x = @"//comment in string"
@ -133,3 +134,116 @@ let x = @"//comment in string"
(identifier))))
(const
(verbatim_string)))))
================================================================================
xml docstring
================================================================================
/// <summary>
/// super important function
/// </summary>
let f x = x + 1
--------------------------------------------------------------------------------
(file
(xml_doc
(xml_doc_content))
(xml_doc
(xml_doc_content))
(xml_doc
(xml_doc_content))
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const
(int))))))
================================================================================
json payload in multi-line string
================================================================================
namespace test
module Json =
[<Literal>]
let MyPayload =
"""
{
"prop1": []
"prop2": {
"prop3": true,
"prop4": 1,
},
}
"""
--------------------------------------------------------------------------------
(file
(namespace
(long_identifier
(identifier))
(module_defn
(identifier)
(value_declaration
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(triple_quoted_string)))))))
================================================================================
json payload in multi-line format string
================================================================================
namespace test
module Json =
let myPayloadBuilder x =
$"""
{
"prop1": []
"prop2": {
"prop3": {x},
"prop4": 1,
},
}
"""
--------------------------------------------------------------------------------
(file
(namespace
(long_identifier
(identifier))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(const
(triple_quoted_string
(format_triple_quoted_string))))))))

@ -255,12 +255,13 @@ do
(file
(value_declaration
(do
(const
(nativeint
(int)))
(const
(nativeint
(xint))))))
(sequential_expression
(const
(nativeint
(int)))
(const
(nativeint
(xint)))))))
================================================================================
unativeint
@ -275,12 +276,13 @@ do
(file
(value_declaration
(do
(const
(unativeint
(int)))
(const
(unativeint
(xint))))))
(sequential_expression
(const
(unativeint
(int)))
(const
(unativeint
(xint)))))))
================================================================================
ieee32
@ -356,24 +358,29 @@ do
(file
(value_declaration
(do
(const
(bignum
(int)))
(const
(bignum
(int)))
(const
(bignum
(int)))
(const
(bignum
(int)))
(const
(bignum
(int)))
(const
(bignum
(int))))))
(sequential_expression
(const
(bignum
(int)))
(sequential_expression
(const
(bignum
(int)))
(sequential_expression
(const
(bignum
(int)))
(sequential_expression
(const
(bignum
(int)))
(sequential_expression
(const
(bignum
(int)))
(const
(bignum
(int)))))))))))
================================================================================
decimal
@ -392,21 +399,91 @@ do
(file
(value_declaration
(do
(sequential_expression
(const
(decimal
(float)))
(sequential_expression
(const
(decimal
(float)))
(sequential_expression
(const
(decimal
(int)))
(sequential_expression
(const
(decimal
(float)))
(sequential_expression
(const
(decimal
(float)))
(const
(decimal
(int)))))))))))
================================================================================
string with escaped quote
================================================================================
let str = "name: \"name\""
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(decimal
(float)))
(const
(decimal
(float)))
(const
(decimal
(int)))
(const
(decimal
(float)))
(string)))))
================================================================================
format string
================================================================================
let x =
$"int: {2 + 2}"
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(decimal
(float)))
(string
(format_string
(format_string_eval
(infix_expression
(const
(int))
(infix_op)
(const
(int))))))))))
================================================================================
triple quoted format string
================================================================================
let x =
$"""int: {2 + 2}"""
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(decimal
(int))))))
(triple_quoted_string
(format_triple_quoted_string))))))

File diff suppressed because it is too large Load Diff

@ -48,6 +48,7 @@ let private functionName x = 4
(value_declaration
(function_or_value_defn
(function_declaration_left
(access_modifier)
(identifier)
(argument_patterns
(long_identifier
@ -55,6 +56,64 @@ let private functionName x = 4
body: (const
(int)))))
================================================================================
private rec function
================================================================================
let rec private functionName x = 4
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(access_modifier)
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(const
(int)))))
================================================================================
mutual rec function
================================================================================
let rec private f1 x = f2 x
and f2 y = y + 1
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(access_modifier)
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const
(int))))))
================================================================================
basic private constant function inline
================================================================================
@ -67,6 +126,7 @@ let inline private functionName x = 4
(value_declaration
(function_or_value_defn
(function_declaration_left
(access_modifier)
(identifier)
(argument_patterns
(long_identifier
@ -82,7 +142,7 @@ let inline double<^a when ^a:(member Double: unit -> ^a)> (x: ^a) = x.Double()
--------------------------------------------------------------------------------
(file
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
@ -112,14 +172,11 @@ let inline double<^a when ^a:(member Double: unit -> ^a)> (x: ^a) = x.Double()
(type
(type_argument
(identifier))))))
(call_expression
(dot_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))))))
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
(identifier)))))))
================================================================================
basic function with srt constraint (new-style, with ')
@ -129,7 +186,7 @@ let inline double<'a when 'a:(member Double: unit -> 'a)> (x: 'a) = x.Double()
--------------------------------------------------------------------------------
(file
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
@ -159,11 +216,44 @@ let inline double<'a when 'a:(member Double: unit -> 'a)> (x: 'a) = x.Double()
(type
(type_argument
(identifier))))))
(call_expression
(dot_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))))))
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
(identifier)))))))
================================================================================
function decl should be preferred over value decl
================================================================================
namespace Test
module Program =
[<EntryPoint>]
let main args =
()
--------------------------------------------------------------------------------
(file
(namespace
(long_identifier
(identifier))
(module_defn
(identifier)
(value_declaration
(attributes
(attribute_set
(attribute
(object_construction
(type
(long_identifier
(identifier)))))))
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(const
(unit)))))))

@ -124,3 +124,130 @@ open X.Y
(long_identifier
(identifier)
(identifier)))))
================================================================================
multiple modules in namespace
================================================================================
namespace Test
module A =
let x = ()
module B =
let x = ()
--------------------------------------------------------------------------------
(file
(namespace
(long_identifier
(identifier))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(unit)))))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(unit)))))))
================================================================================
multiple modules in top-level module
================================================================================
module Test
module A =
let x = ()
module B =
let x = ()
--------------------------------------------------------------------------------
(file
(named_module
(long_identifier
(identifier))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(unit)))))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(unit)))))))
================================================================================
multiple modules in anonymous module
================================================================================
module A =
let x = ()
module B =
let x = ()
--------------------------------------------------------------------------------
(file
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(unit)))))
(module_defn
(identifier)
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(unit))))))
================================================================================
top-level expression in module
================================================================================
module A =
()
--------------------------------------------------------------------------------
(file
(module_defn
(identifier)
(const
(unit))))

@ -0,0 +1,72 @@
================================================================================
basic comparison
================================================================================
do
1 < 2
1 <= 2
2 > 1
2 <> 1
--------------------------------------------------------------------------------
(file
(value_declaration
(do
(sequential_expression
(infix_expression
(const (int))
(infix_op)
(const (int)))
(sequential_expression
(infix_expression
(const (int))
(infix_op)
(const (int)))
(sequential_expression
(infix_expression
(const (int))
(infix_op)
(const (int)))
(infix_expression
(const (int))
(infix_op)
(const (int)))))))))
================================================================================
prefix operator
================================================================================
do
!!"str"
~"str"
!*"str"
~~"str"
--------------------------------------------------------------------------------
(file
(value_declaration
(do
(sequential_expression
(prefixed_expression
(prefix_op)
(const
(string)))
(sequential_expression
(prefixed_expression
(prefix_op)
(const
(string)))
(sequential_expression
(prefixed_expression
(prefix_op)
(const
(string)))
(prefixed_expression
(prefix_op)
(prefixed_expression
(prefix_op)
(const
(string))))))))))

@ -0,0 +1,229 @@
================================================================================
function definition on same line should end scope
================================================================================
let f x = x + 1
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const (int))))))
================================================================================
function definition on new line should open scope
================================================================================
let f x =
x + 1
1
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(sequential_expression
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const (int)))
(const (int))))))
================================================================================
function definition aligned to first line should scope correctly
================================================================================
let f x = x + 1
1
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(sequential_expression
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const (int)))
(const (int))))))
================================================================================
call expression with underindentation
================================================================================
do
Serializer(
1,
2,
3
)
--------------------------------------------------------------------------------
(file
(value_declaration
(do
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(tuple_expression
(tuple_expression
(const (int))
(const (int)))
(const (int)))))))
================================================================================
declaration expression should contain all sequential expressions
================================================================================
let f x =
let y = x + 1
printfn y
printfn y
printfn y
printfn y
--------------------------------------------------------------------------------
(file
(value_declaration
(function_or_value_defn
(function_declaration_left
(identifier)
(argument_patterns
(long_identifier
(identifier))))
(declaration_expression
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(infix_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(infix_op)
(const
(int))))
(sequential_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))
(sequential_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))
(sequential_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier)))))))))))
================================================================================
for-loop in else branch
================================================================================
do
if b then
()
else
for x in xs do
()
()
--------------------------------------------------------------------------------
(file
(value_declaration
(do
(if_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(const
(unit))
(sequential_expression
(for_expression
(identifier_pattern
(long_identifier
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier)))
(const
(unit)))
(const
(unit)))))))
================================================================================
prefix associativity
================================================================================
do
return ctx.Ok message :> IAction
--------------------------------------------------------------------------------
(file
(value_declaration
(do
(prefixed_expression
(typecast_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
(identifier)))
(long_identifier_or_op
(long_identifier
(identifier))))
(type
(long_identifier
(identifier))))))))

@ -111,25 +111,45 @@ let x = 4
basic global namespace
================================================================================
namespace global test
namespace global
let x = 4
--------------------------------------------------------------------------------
(file
(namespace
(ERROR
(UNEXPECTED 'e')
(UNEXPECTED '\n'))
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(int))))))
(namespace
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(int))))))
================================================================================
basic recursive namespace
================================================================================
namespace rec test
let x = 4
--------------------------------------------------------------------------------
(file
(namespace
(long_identifier
(identifier))
(value_declaration
(function_or_value_defn
(value_declaration_left
(identifier_pattern
(long_identifier
(identifier))))
(const
(int))))))
================================================================================
basic long namespace

File diff suppressed because it is too large Load Diff

@ -0,0 +1,8 @@
let f x = x + 1
// <- keyword.function
// ^ function
// ^ variable.parameter
// ^ operator
// ^ variable
// ^ operator
// ^ number

@ -1,10 +1,9 @@
#r "nuget: FSharp.Compiler.Service, 43.7.300"
//<- keyword.control.import
// ^ namespace
//<- keyword.import
// ^ string
#r "/home/bin/MyApp.dll"
//<- keyword.control.import
// ^ namespace
//<- keyword.import
// ^ string
#load "Strings.fsx"
//<- keyword.control.import
// ^ namespace
//<- keyword.import
// ^ string

@ -0,0 +1,7 @@
let str = $"2 + 2 = {2 + 2}"
//<- keyword.function
// ^ variable
// ^ string
// ^ number
// ^ number
// ^ string

@ -0,0 +1,8 @@
type A() =
//<- keyword.type
// ^ type.definition
member this.F(x) = ()
//^ keyword.function
// ^ variable.parameter.builtin
// ^ variable.member
// ^ variable