~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
f997beed
—
pyrossh 1 year ago
fix parser
- libs/std/list.plum +3 -3
- test/add.plum +3 -3
- test/aoc_2020_1.plum +1 -1
- test/sample.plum +3 -3
- tooling/tree-sitter-plum/.github/workflows/fuzz.yml +1 -1
- tooling/tree-sitter-plum/Cargo.toml +9 -6
- tooling/tree-sitter-plum/Makefile +1 -1
- tooling/tree-sitter-plum/Package.swift +3 -3
- tooling/tree-sitter-plum/binding.gyp +3 -3
- tooling/tree-sitter-plum/bindings/c/tree-sitter-kestrel.h +0 -16
- tooling/tree-sitter-plum/bindings/c/tree-sitter-plum.h +16 -0
- tooling/tree-sitter-plum/bindings/c/{tree-sitter-kestrel.pc.in → tree-sitter-plum.pc.in} +3 -3
- tooling/tree-sitter-plum/bindings/go/binding.go +2 -2
- tooling/tree-sitter-plum/bindings/go/binding_test.go +4 -4
- tooling/tree-sitter-plum/bindings/go/go.mod +1 -1
- tooling/tree-sitter-plum/bindings/node/binding.cc +4 -4
- tooling/tree-sitter-plum/bindings/python/tree_sitter_kestrel/__init__.py +1 -1
- tooling/tree-sitter-plum/bindings/python/tree_sitter_kestrel/binding.c +2 -2
- tooling/tree-sitter-plum/bindings/python/tree_sitter_plum/__init__.py +5 -0
- tooling/tree-sitter-plum/bindings/python/tree_sitter_plum/__init__.pyi +1 -0
- tooling/tree-sitter-plum/bindings/python/tree_sitter_plum/binding.c +27 -0
- tooling/tree-sitter-plum/{test/corpus/tuple.txt → bindings/python/tree_sitter_plum/py.typed} +0 -0
- tooling/tree-sitter-plum/bindings/rust/build.rs +1 -1
- tooling/tree-sitter-plum/bindings/rust/lib.rs +5 -5
- tooling/tree-sitter-plum/bindings/swift/TreeSitterKestrel/kestrel.h +4 -4
- tooling/tree-sitter-plum/bindings/swift/TreeSitterPlum/plum.h +16 -0
- tooling/tree-sitter-plum/grammar.js +173 -138
- tooling/tree-sitter-plum/package.json +8 -8
- tooling/tree-sitter-plum/prebuilds/darwin-arm64/tree-sitter-kestrel.node +0 -0
- tooling/tree-sitter-plum/pyproject.toml +4 -4
- tooling/tree-sitter-plum/setup.py +19 -17
- tooling/tree-sitter-plum/src/grammar.json +0 -0
- tooling/tree-sitter-plum/src/node-types.json +0 -0
- tooling/tree-sitter-plum/src/parser.c +0 -0
- tooling/tree-sitter-plum/src/scanner.c +428 -24
- tooling/tree-sitter-plum/test/corpus/assert.txt +88 -0
- tooling/tree-sitter-plum/test/corpus/assign.txt +58 -201
- tooling/tree-sitter-plum/test/corpus/enum.txt +17 -0
- tooling/tree-sitter-plum/test/corpus/{fn.txt → function.txt} +91 -103
- tooling/tree-sitter-plum/test/corpus/if.txt +83 -138
- tooling/tree-sitter-plum/test/corpus/literals.txt +156 -0
- tooling/tree-sitter-plum/test/corpus/match.txt +7 -14
- tooling/tree-sitter-plum/test/corpus/object.txt +0 -66
- tooling/tree-sitter-plum/test/corpus/record.txt +0 -280
- tooling/tree-sitter-plum/test/corpus/trait.txt +0 -38
- tooling/tree-sitter-plum/test/corpus/type.txt +169 -0
libs/std/list.plum
CHANGED
|
@@ -15,8 +15,8 @@ List = {
|
|
|
15
15
|
size: Int
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
List(values: ...a) -> List(a) =
|
|
18
|
+
List\init(values: ...a) -> List(a) =
|
|
19
|
-
List().add(values)
|
|
19
|
+
List().add(values...)
|
|
20
20
|
|
|
21
21
|
# gets the element at i'th index of the list
|
|
22
22
|
List\get(i: Int) -> a =
|
|
@@ -61,7 +61,7 @@ List\remove(v: a) =
|
|
|
61
61
|
# removes all objects from this list
|
|
62
62
|
List\clear() =
|
|
63
63
|
l.tail?.prev?.next = Nil
|
|
64
|
-
|
|
64
|
+
# old tail node gets deallocated due to zero reference count
|
|
65
65
|
l.tail = list.tail?.prev
|
|
66
66
|
l.size -= 1
|
|
67
67
|
|
test/add.plum
CHANGED
|
@@ -73,10 +73,10 @@ main() -> Unit =
|
|
|
73
73
|
c = input.charAt(i)
|
|
74
74
|
if c >= '0' && c <= '9'
|
|
75
75
|
if first_digit == 0
|
|
76
|
-
first_digit = (c - '0')
|
|
76
|
+
first_digit = Int(c - '0')
|
|
77
|
-
last_digit = (c - '0')
|
|
77
|
+
last_digit = Int(c - '0')
|
|
78
78
|
else
|
|
79
|
-
last_digit = (c - '0')
|
|
79
|
+
last_digit = Int(c - '0')
|
|
80
80
|
continue
|
|
81
81
|
if c == '\n'
|
|
82
82
|
calibration_value = first_digit * 10 + last_digit
|
test/aoc_2020_1.plum
CHANGED
|
@@ -18,7 +18,7 @@ fn parseNumbers(input: Str) -> List<Int> =
|
|
|
18
18
|
c = input.charAt(i)
|
|
19
19
|
if c >= '0' && c <= '9'
|
|
20
20
|
current_number *= 10
|
|
21
|
-
current_number += (c - '0')
|
|
21
|
+
current_number += Int(c - '0')
|
|
22
22
|
if c == '\n'
|
|
23
23
|
numbers.push!<u32>(current_number)
|
|
24
24
|
current_number = 0
|
test/sample.plum
CHANGED
|
@@ -23,10 +23,10 @@ User()
|
|
|
23
23
|
.todo(Todo().title("Finish Toasty"))
|
|
24
24
|
.todo(Todo().title("Sleep"))
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
stoplightColor(something: Int) -> Color =
|
|
27
|
-
if something > 0
|
|
27
|
+
if something > 0
|
|
28
28
|
Red
|
|
29
|
-
else if something == 0
|
|
29
|
+
else if something == 0
|
|
30
30
|
Yellow
|
|
31
31
|
else
|
|
32
32
|
Green
|
tooling/tree-sitter-plum/.github/workflows/fuzz.yml
CHANGED
|
@@ -17,6 +17,6 @@ jobs:
|
|
|
17
17
|
- uses: actions/checkout@v4
|
|
18
18
|
- uses: vigoux/tree-sitter-fuzz-action@v1
|
|
19
19
|
with:
|
|
20
|
-
language:
|
|
20
|
+
language: plum
|
|
21
21
|
external-scanner: src/scanner.c
|
|
22
22
|
time: 60
|
tooling/tree-sitter-plum/Cargo.toml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "tree-sitter-
|
|
2
|
+
name = "tree-sitter-plum"
|
|
3
|
-
description = "
|
|
3
|
+
description = "plum grammar for tree-sitter"
|
|
4
|
-
version = "0.
|
|
4
|
+
version = "0.0.1"
|
|
5
5
|
authors = [
|
|
6
6
|
"pyrossh <pyros2097@gmail.com>",
|
|
7
7
|
]
|
|
8
8
|
license = "MIT"
|
|
9
9
|
readme = "bindings/rust/README.md"
|
|
10
|
-
keywords = ["incremental", "parsing", "
|
|
10
|
+
keywords = ["incremental", "parsing", "plum"]
|
|
11
11
|
categories = ["parsing", "text-editors"]
|
|
12
|
-
repository = "https://github.com/pyrossh/tree-sitter-
|
|
12
|
+
repository = "https://github.com/pyrossh/tree-sitter-plum"
|
|
13
13
|
edition = "2021"
|
|
14
14
|
autoexamples = false
|
|
15
15
|
|
|
@@ -20,7 +20,10 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
|
|
|
20
20
|
path = "bindings/rust/lib.rs"
|
|
21
21
|
|
|
22
22
|
[dependencies]
|
|
23
|
-
tree-sitter = "
|
|
23
|
+
tree-sitter-language = "0.1"
|
|
24
24
|
|
|
25
25
|
[build-dependencies]
|
|
26
26
|
cc = "~1.0"
|
|
27
|
+
|
|
28
|
+
[dev-dependencies]
|
|
29
|
+
tree-sitter = "0.24"
|
tooling/tree-sitter-plum/Makefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
VERSION := 0.0.1
|
|
2
2
|
|
|
3
|
-
LANGUAGE_NAME := tree-sitter-
|
|
3
|
+
LANGUAGE_NAME := tree-sitter-plum
|
|
4
4
|
|
|
5
5
|
# repository
|
|
6
6
|
SRC_DIR := src
|
tooling/tree-sitter-plum/Package.swift
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import PackageDescription
|
|
3
3
|
|
|
4
4
|
let package = Package(
|
|
5
|
-
name: "
|
|
5
|
+
name: "TreeSitterplum",
|
|
6
6
|
products: [
|
|
7
|
-
.library(name: "
|
|
7
|
+
.library(name: "TreeSitterplum", targets: ["TreeSitterplum"]),
|
|
8
8
|
],
|
|
9
9
|
dependencies: [],
|
|
10
10
|
targets: [
|
|
11
|
-
.target(name: "
|
|
11
|
+
.target(name: "TreeSitterplum",
|
|
12
12
|
path: ".",
|
|
13
13
|
exclude: [
|
|
14
14
|
"Cargo.toml",
|
tooling/tree-sitter-plum/binding.gyp
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"targets": [
|
|
3
3
|
{
|
|
4
|
-
"target_name": "
|
|
4
|
+
"target_name": "tree_sitter_plum_binding",
|
|
5
5
|
"dependencies": [
|
|
6
6
|
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
7
7
|
],
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
],
|
|
16
16
|
"cflags_c": [
|
|
17
17
|
"-std=c11",
|
|
18
|
-
]
|
|
18
|
+
],
|
|
19
19
|
}
|
|
20
20
|
]
|
|
21
|
-
}
|
|
21
|
+
}
|
tooling/tree-sitter-plum/bindings/c/tree-sitter-kestrel.h
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#ifndef TREE_SITTER_KESTREL_H_
|
|
2
|
-
#define TREE_SITTER_KESTREL_H_
|
|
3
|
-
|
|
4
|
-
typedef struct TSLanguage TSLanguage;
|
|
5
|
-
|
|
6
|
-
#ifdef __cplusplus
|
|
7
|
-
extern "C" {
|
|
8
|
-
#endif
|
|
9
|
-
|
|
10
|
-
const TSLanguage *tree_sitter_kestrel(void);
|
|
11
|
-
|
|
12
|
-
#ifdef __cplusplus
|
|
13
|
-
}
|
|
14
|
-
#endif
|
|
15
|
-
|
|
16
|
-
#endif // TREE_SITTER_KESTREL_H_
|
tooling/tree-sitter-plum/bindings/c/tree-sitter-plum.h
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef TREE_SITTER_PLUM_H_
|
|
2
|
+
#define TREE_SITTER_PLUM_H_
|
|
3
|
+
|
|
4
|
+
typedef struct TSLanguage TSLanguage;
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
const TSLanguage *tree_sitter_plum(void);
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
}
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#endif // TREE_SITTER_PLUM_H_
|
tooling/tree-sitter-plum/bindings/c/{tree-sitter-kestrel.pc.in → tree-sitter-plum.pc.in}
RENAMED
|
@@ -2,10 +2,10 @@ prefix=@PREFIX@
|
|
|
2
2
|
libdir=@LIBDIR@
|
|
3
3
|
includedir=@INCLUDEDIR@
|
|
4
4
|
|
|
5
|
-
Name: tree-sitter-
|
|
5
|
+
Name: tree-sitter-plum
|
|
6
|
-
Description:
|
|
6
|
+
Description: Plum grammar for tree-sitter
|
|
7
7
|
URL: @URL@
|
|
8
8
|
Version: @VERSION@
|
|
9
9
|
Requires: @REQUIRES@
|
|
10
|
-
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-
|
|
10
|
+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-plum
|
|
11
11
|
Cflags: -I${includedir}
|
tooling/tree-sitter-plum/bindings/go/binding.go
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
package
|
|
1
|
+
package tree_sitter_plum
|
|
2
2
|
|
|
3
3
|
// #cgo CFLAGS: -std=c11 -fPIC
|
|
4
4
|
// #include "../../src/parser.c"
|
|
@@ -9,5 +9,5 @@ import "unsafe"
|
|
|
9
9
|
|
|
10
10
|
// Get the tree-sitter Language for this grammar.
|
|
11
11
|
func Language() unsafe.Pointer {
|
|
12
|
-
return unsafe.Pointer(C.
|
|
12
|
+
return unsafe.Pointer(C.tree_sitter_plum())
|
|
13
13
|
}
|
tooling/tree-sitter-plum/bindings/go/binding_test.go
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
package
|
|
1
|
+
package tree_sitter_plum_test
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"testing"
|
|
5
5
|
|
|
6
6
|
tree_sitter "github.com/smacker/go-tree-sitter"
|
|
7
|
-
"github.com/tree-sitter/tree-sitter-
|
|
7
|
+
"github.com/tree-sitter/tree-sitter-plum"
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
func TestCanLoadGrammar(t *testing.T) {
|
|
11
|
-
language := tree_sitter.NewLanguage(
|
|
11
|
+
language := tree_sitter.NewLanguage(tree_sitter_plum.Language())
|
|
12
12
|
if language == nil {
|
|
13
|
-
t.Errorf("Error loading
|
|
13
|
+
t.Errorf("Error loading plum grammar")
|
|
14
14
|
}
|
|
15
15
|
}
|
tooling/tree-sitter-plum/bindings/go/go.mod
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
module github.com/tree-sitter/tree-sitter-
|
|
1
|
+
module github.com/tree-sitter/tree-sitter-plum
|
|
2
2
|
|
|
3
3
|
go 1.22
|
|
4
4
|
|
tooling/tree-sitter-plum/bindings/node/binding.cc
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
typedef struct TSLanguage TSLanguage;
|
|
4
4
|
|
|
5
|
-
extern "C" TSLanguage *
|
|
5
|
+
extern "C" TSLanguage *tree_sitter_plum();
|
|
6
6
|
|
|
7
7
|
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
8
|
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
@@ -10,11 +10,11 @@ const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
-
exports["name"] = Napi::String::New(env, "
|
|
13
|
+
exports["name"] = Napi::String::New(env, "plum");
|
|
14
|
-
auto language = Napi::External<TSLanguage>::New(env,
|
|
14
|
+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_plum());
|
|
15
15
|
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
|
16
16
|
exports["language"] = language;
|
|
17
17
|
return exports;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
NODE_API_MODULE(
|
|
20
|
+
NODE_API_MODULE(tree_sitter_plum_binding, Init)
|
tooling/tree-sitter-plum/bindings/python/tree_sitter_kestrel/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"
|
|
1
|
+
"plum grammar for tree-sitter"
|
|
2
2
|
|
|
3
3
|
from ._binding import language
|
|
4
4
|
|
tooling/tree-sitter-plum/bindings/python/tree_sitter_kestrel/binding.c
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
typedef struct TSLanguage TSLanguage;
|
|
4
4
|
|
|
5
|
-
TSLanguage *
|
|
5
|
+
TSLanguage *tree_sitter_plum(void);
|
|
6
6
|
|
|
7
7
|
static PyObject* _binding_language(PyObject *self, PyObject *args) {
|
|
8
|
-
return PyLong_FromVoidPtr(
|
|
8
|
+
return PyLong_FromVoidPtr(tree_sitter_plum());
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
static PyMethodDef methods[] = {
|
tooling/tree-sitter-plum/bindings/python/tree_sitter_plum/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"Plum grammar for tree-sitter"
|
|
2
|
+
|
|
3
|
+
from ._binding import language
|
|
4
|
+
|
|
5
|
+
__all__ = ["language"]
|
tooling/tree-sitter-plum/bindings/python/tree_sitter_plum/__init__.pyi
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
def language() -> int: ...
|
tooling/tree-sitter-plum/bindings/python/tree_sitter_plum/binding.c
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#include <Python.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
TSLanguage *tree_sitter_plum(void);
|
|
6
|
+
|
|
7
|
+
static PyObject* _binding_language(PyObject *self, PyObject *args) {
|
|
8
|
+
return PyLong_FromVoidPtr(tree_sitter_plum());
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static PyMethodDef methods[] = {
|
|
12
|
+
{"language", _binding_language, METH_NOARGS,
|
|
13
|
+
"Get the tree-sitter language for this grammar."},
|
|
14
|
+
{NULL, NULL, 0, NULL}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
static struct PyModuleDef module = {
|
|
18
|
+
.m_base = PyModuleDef_HEAD_INIT,
|
|
19
|
+
.m_name = "_binding",
|
|
20
|
+
.m_doc = NULL,
|
|
21
|
+
.m_size = -1,
|
|
22
|
+
.m_methods = methods
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
PyMODINIT_FUNC PyInit__binding(void) {
|
|
26
|
+
return PyModule_Create(&module);
|
|
27
|
+
}
|
tooling/tree-sitter-plum/{test/corpus/tuple.txt → bindings/python/tree_sitter_plum/py.typed}
RENAMED
|
File without changes
|
tooling/tree-sitter-plum/bindings/rust/build.rs
CHANGED
|
@@ -16,5 +16,5 @@ fn main() {
|
|
|
16
16
|
c_config.file(&scanner_path);
|
|
17
17
|
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
|
|
18
18
|
|
|
19
|
-
c_config.compile("tree-sitter-
|
|
19
|
+
c_config.compile("tree-sitter-plum");
|
|
20
20
|
}
|
tooling/tree-sitter-plum/bindings/rust/lib.rs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! This crate provides
|
|
1
|
+
//! This crate provides plum language support for the [tree-sitter][] parsing library.
|
|
2
2
|
//!
|
|
3
3
|
//! Typically, you will use the [language][language func] function to add this language to a
|
|
4
4
|
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
//! let code = r#"
|
|
8
8
|
//! "#;
|
|
9
9
|
//! let mut parser = tree_sitter::Parser::new();
|
|
10
|
-
//! parser.set_language(&
|
|
10
|
+
//! parser.set_language(&tree_sitter_plum::language()).expect("Error loading plum grammar");
|
|
11
11
|
//! let tree = parser.parse(code, None).unwrap();
|
|
12
12
|
//! assert!(!tree.root_node().has_error());
|
|
13
13
|
//! ```
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
use tree_sitter::Language;
|
|
21
21
|
|
|
22
22
|
extern "C" {
|
|
23
|
-
fn
|
|
23
|
+
fn tree_sitter_plum() -> Language;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/// Get the tree-sitter [Language][] for this grammar.
|
|
27
27
|
///
|
|
28
28
|
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
29
29
|
pub fn language() -> Language {
|
|
30
|
-
unsafe {
|
|
30
|
+
unsafe { tree_sitter_plum() }
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/// The content of the [`node-types.json`][] file for this grammar.
|
|
@@ -49,6 +49,6 @@ mod tests {
|
|
|
49
49
|
let mut parser = tree_sitter::Parser::new();
|
|
50
50
|
parser
|
|
51
51
|
.set_language(super::language())
|
|
52
|
-
.expect("Error loading
|
|
52
|
+
.expect("Error loading plum grammar");
|
|
53
53
|
}
|
|
54
54
|
}
|
tooling/tree-sitter-plum/bindings/swift/TreeSitterKestrel/kestrel.h
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#ifndef
|
|
1
|
+
#ifndef TREE_SITTER_plum_H_
|
|
2
|
-
#define
|
|
2
|
+
#define TREE_SITTER_plum_H_
|
|
3
3
|
|
|
4
4
|
typedef struct TSLanguage TSLanguage;
|
|
5
5
|
|
|
@@ -7,10 +7,10 @@ typedef struct TSLanguage TSLanguage;
|
|
|
7
7
|
extern "C" {
|
|
8
8
|
#endif
|
|
9
9
|
|
|
10
|
-
const TSLanguage *
|
|
10
|
+
const TSLanguage *tree_sitter_plum(void);
|
|
11
11
|
|
|
12
12
|
#ifdef __cplusplus
|
|
13
13
|
}
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
#endif //
|
|
16
|
+
#endif // TREE_SITTER_plum_H_
|
tooling/tree-sitter-plum/bindings/swift/TreeSitterPlum/plum.h
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef TREE_SITTER_PLUM_H_
|
|
2
|
+
#define TREE_SITTER_PLUM_H_
|
|
3
|
+
|
|
4
|
+
typedef struct TSLanguage TSLanguage;
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
const TSLanguage *tree_sitter_plum(void);
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
}
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#endif // TREE_SITTER_PLUM_H_
|
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
const PREC = {
|
|
2
2
|
conditional: -1,
|
|
3
|
-
LAMBDA_LITERAL: 0,
|
|
4
|
-
VAR_DECL: 3,
|
|
5
3
|
parenthesized_expression: 1,
|
|
6
4
|
range: 9,
|
|
7
5
|
or: 10,
|
|
@@ -18,29 +16,56 @@ const PREC = {
|
|
|
18
16
|
power: 21,
|
|
19
17
|
constructor: 22,
|
|
20
18
|
call: 23,
|
|
21
|
-
POSTFIX: 16,
|
|
22
|
-
PREFIX: 15,
|
|
23
19
|
};
|
|
24
20
|
|
|
21
|
+
// a == 2 ? b : c
|
|
22
|
+
// a ?: b
|
|
23
|
+
|
|
24
|
+
|
|
25
25
|
const DEC_DIGITS = token(sep1(/[0-9]+/, /_+/));
|
|
26
26
|
const HEX_DIGITS = token(sep1(/[0-9a-fA-F]+/, /_+/));
|
|
27
27
|
const BIN_DIGITS = token(sep1(/[01]/, /_+/));
|
|
28
28
|
const REAL_EXPONENT = token(seq(/[eE]/, optional(/[+-]/), DEC_DIGITS));
|
|
29
29
|
|
|
30
30
|
module.exports = grammar({
|
|
31
|
-
name: "
|
|
31
|
+
name: "plum",
|
|
32
|
+
extras: $ => [
|
|
33
|
+
$.comment,
|
|
32
|
-
|
|
34
|
+
/[\s\f\uFEFF\u2060\u200B]|\r?\n/,
|
|
35
|
+
// $.line_continuation,
|
|
36
|
+
],
|
|
33
|
-
externals:
|
|
37
|
+
externals: $ => [
|
|
38
|
+
$._newline,
|
|
39
|
+
$._indent,
|
|
40
|
+
$._dedent,
|
|
41
|
+
$.string_start,
|
|
42
|
+
$._string_content,
|
|
43
|
+
$.escape_interpolation,
|
|
44
|
+
$.string_end,
|
|
45
|
+
|
|
46
|
+
// Mark comments as external tokens so that the external scanner is always
|
|
47
|
+
// invoked, even if no external token is expected. This allows for better
|
|
48
|
+
// error recovery, because the external scanner can maintain the overall
|
|
49
|
+
// structure by returning dedent tokens whenever a dedent occurs, even
|
|
50
|
+
// if no dedent is expected.
|
|
51
|
+
$.comment,
|
|
52
|
+
|
|
53
|
+
// Allow the external scanner to check for the validity of closing brackets
|
|
54
|
+
// so that it can avoid returning dedent tokens between brackets.
|
|
55
|
+
']',
|
|
56
|
+
')',
|
|
57
|
+
'}',
|
|
58
|
+
'except',
|
|
59
|
+
],
|
|
34
60
|
conflicts: ($) => [
|
|
35
|
-
[$.closure, $.primary_expression],
|
|
36
61
|
],
|
|
37
|
-
|
|
62
|
+
inline: ($) => [$.generic_type, $.generic],
|
|
38
63
|
rules: {
|
|
39
64
|
source: ($) =>
|
|
40
65
|
seq(
|
|
41
66
|
optional(seq("module", $.module)),
|
|
42
67
|
repeat($.import),
|
|
43
|
-
repeat(choice($.
|
|
68
|
+
repeat(choice($.record, $.object, $.trait, $.enum, $.fn)),
|
|
44
69
|
),
|
|
45
70
|
|
|
46
71
|
module: ($) => $.identifier,
|
|
@@ -48,24 +73,26 @@ module.exports = grammar({
|
|
|
48
73
|
import: ($) => seq("import", $.url),
|
|
49
74
|
url: ($) => sep1(/[a-zA-Z_][a-zA-Z_0-9]*/, "/"),
|
|
50
75
|
|
|
51
|
-
generics: ($) => seq("
|
|
76
|
+
generics: ($) => seq("(", commaSep1($.generic_type), ")"),
|
|
52
77
|
generic_type: ($) =>
|
|
53
|
-
seq($.
|
|
78
|
+
seq($.generic, optional(seq(":", sep1($.type_identifier, "+")))),
|
|
54
79
|
type: ($) =>
|
|
80
|
+
choice(
|
|
55
|
-
|
|
81
|
+
seq(
|
|
56
|
-
|
|
82
|
+
$.type_identifier,
|
|
57
|
-
|
|
83
|
+
field("generics", optional(seq("(", commaSep1($.type), ")"))),
|
|
84
|
+
),
|
|
85
|
+
$.generic,
|
|
58
86
|
),
|
|
87
|
+
variadic_type: ($) => seq("...", $.type),
|
|
59
88
|
|
|
60
89
|
record: ($) =>
|
|
61
90
|
seq(
|
|
62
|
-
optional(repeat($.doc_comment)),
|
|
63
|
-
"record",
|
|
64
|
-
field("name", $.
|
|
91
|
+
field("name", $.type_identifier),
|
|
92
|
+
field("implements", optional(seq(":", sep1($.type_identifier, "+")))),
|
|
65
93
|
field("generics", optional($.generics)),
|
|
94
|
+
"=",
|
|
66
|
-
field("fields", seq("
|
|
95
|
+
field("fields", seq("{", $._newline, sep1($.record_field, $._newline), $._newline, "}")),
|
|
67
|
-
field("implements", optional(seq(":", commaSep1($.typename)))),
|
|
68
|
-
field("body", optional(seq("{", repeat($.fn), "}"))),
|
|
69
96
|
),
|
|
70
97
|
|
|
71
98
|
record_field: ($) =>
|
|
@@ -74,16 +101,15 @@ module.exports = grammar({
|
|
|
74
101
|
object: ($) =>
|
|
75
102
|
seq(
|
|
76
103
|
"object",
|
|
77
|
-
field("name", $.
|
|
104
|
+
field("name", $.type_identifier),
|
|
78
|
-
field("implements", optional(seq(":", commaSep1($.
|
|
105
|
+
field("implements", optional(seq(":", commaSep1($.type_identifier)))),
|
|
79
106
|
field("body", optional(seq("{", repeat($.fn), "}"))),
|
|
80
107
|
),
|
|
81
108
|
|
|
82
109
|
trait: ($) =>
|
|
83
110
|
seq(
|
|
84
|
-
optional(repeat($.doc_comment)),
|
|
85
111
|
"trait",
|
|
86
|
-
field("name", $.
|
|
112
|
+
field("name", $.type_identifier),
|
|
87
113
|
field("generics", optional($.generics)),
|
|
88
114
|
field("fields", seq("{", repeat($.trait_field), "}")),
|
|
89
115
|
),
|
|
@@ -101,49 +127,38 @@ module.exports = grammar({
|
|
|
101
127
|
seq(
|
|
102
128
|
field("name", $.identifier),
|
|
103
129
|
":",
|
|
104
|
-
field("type", $.type),
|
|
130
|
+
field("type", choice($.type, $.variadic_type)),
|
|
105
131
|
optional(seq("=", field("value", $.expression))),
|
|
106
132
|
),
|
|
107
133
|
|
|
108
134
|
return_type: ($) =>
|
|
109
|
-
seq($.
|
|
135
|
+
seq($.type_identifier, field("generics", optional($.generics))),
|
|
110
136
|
|
|
111
137
|
enum: ($) =>
|
|
112
138
|
seq(
|
|
113
|
-
optional(repeat($.doc_comment)),
|
|
114
|
-
"enum",
|
|
115
|
-
field("name", $.
|
|
139
|
+
field("name", $.type_identifier),
|
|
116
|
-
"
|
|
140
|
+
"=",
|
|
141
|
+
$._indent,
|
|
117
|
-
field("fields",
|
|
142
|
+
field("fields", sep1($.enum_field, $._newline)),
|
|
118
|
-
|
|
143
|
+
$._dedent,
|
|
119
144
|
),
|
|
120
145
|
|
|
121
146
|
enum_field: ($) =>
|
|
147
|
+
seq(
|
|
148
|
+
"|",
|
|
149
|
+
field("name", $.type_identifier),
|
|
122
|
-
|
|
150
|
+
field("parameters", optional(seq("(", commaSep1($.type_identifier), ")"))),
|
|
151
|
+
),
|
|
123
152
|
|
|
124
153
|
fn: ($) =>
|
|
125
154
|
seq(
|
|
126
|
-
optional($.doc_comment),
|
|
127
|
-
optional($.decorator),
|
|
128
|
-
field("
|
|
155
|
+
field("name", choice($.fn_identifier, $.method_identifier, $.static_identifier)),
|
|
129
|
-
"fn",
|
|
130
|
-
field("name", $.fnname),
|
|
131
|
-
field("generics", optional($.generics)),
|
|
132
156
|
field("params", seq("(", optional(commaSep1($.param)), ")")),
|
|
133
157
|
field("returns", optional(seq("->", $.return_type))),
|
|
134
|
-
field("body",
|
|
158
|
+
field("body", seq("=", $.body)),
|
|
135
159
|
),
|
|
136
160
|
|
|
137
|
-
decorator: ($) =>
|
|
138
|
-
seq(
|
|
139
|
-
"@",
|
|
140
|
-
field("function", $.reference),
|
|
141
|
-
field("arguments", $.argument_list),
|
|
142
|
-
),
|
|
143
|
-
|
|
144
|
-
fn_modifier: ($) => choice("operator", "static", "override"),
|
|
145
|
-
|
|
146
|
-
body: ($) => seq(
|
|
161
|
+
body: ($) => seq($._indent, repeat($._statement), $._dedent),
|
|
147
162
|
|
|
148
163
|
_statement: ($) =>
|
|
149
164
|
choice(
|
|
@@ -156,20 +171,24 @@ module.exports = grammar({
|
|
|
156
171
|
$.if,
|
|
157
172
|
$.match,
|
|
158
173
|
$.return,
|
|
174
|
+
$.todo,
|
|
175
|
+
$.primary_expression
|
|
159
176
|
),
|
|
160
177
|
|
|
161
178
|
assign: ($) =>
|
|
179
|
+
prec.right(
|
|
162
|
-
|
|
180
|
+
seq(
|
|
163
|
-
choice("val", "var"),
|
|
164
|
-
|
|
181
|
+
field("left", commaSep1($.identifier)),
|
|
165
|
-
|
|
182
|
+
"=",
|
|
166
|
-
|
|
183
|
+
field("right", $.expression),
|
|
184
|
+
),
|
|
167
185
|
),
|
|
168
186
|
|
|
169
|
-
assert: ($) => seq("assert",
|
|
187
|
+
assert: ($) => seq("assert", $.expression),
|
|
170
|
-
return: ($) => seq("return", optional($.expression)),
|
|
188
|
+
return: ($) => prec.left(seq("return", optional($.expression))),
|
|
171
189
|
break: (_) => prec.left("break"),
|
|
172
190
|
continue: (_) => prec.left("continue"),
|
|
191
|
+
todo: (_) => prec.left("todo"),
|
|
173
192
|
|
|
174
193
|
if: ($) =>
|
|
175
194
|
seq(
|
|
@@ -188,9 +207,15 @@ module.exports = grammar({
|
|
|
188
207
|
reference: ($) =>
|
|
189
208
|
prec(
|
|
190
209
|
PREC.call,
|
|
191
|
-
seq(choice($.identifier, $.
|
|
210
|
+
seq(choice($.identifier, $.type_identifier), optional(seq(".", $.identifier))),
|
|
192
211
|
),
|
|
193
212
|
|
|
213
|
+
method_identifier: ($) =>
|
|
214
|
+
seq($.type_identifier, "\\", $.fn_identifier),
|
|
215
|
+
|
|
216
|
+
static_identifier: ($) =>
|
|
217
|
+
seq($.type_identifier, "::", $.fn_identifier),
|
|
218
|
+
|
|
194
219
|
for: ($) =>
|
|
195
220
|
seq(
|
|
196
221
|
"for",
|
|
@@ -201,21 +226,22 @@ module.exports = grammar({
|
|
|
201
226
|
),
|
|
202
227
|
|
|
203
228
|
while: ($) =>
|
|
204
|
-
seq("while",
|
|
229
|
+
seq("while", field("condition", $.expression), field("body", $.body)),
|
|
205
230
|
|
|
206
231
|
dotted_name: ($) => prec(1, sep1($.identifier, ".")),
|
|
207
232
|
|
|
208
233
|
// Match cases
|
|
209
234
|
match: ($) =>
|
|
235
|
+
prec.left(
|
|
210
|
-
|
|
236
|
+
seq(
|
|
211
|
-
|
|
237
|
+
"match",
|
|
212
|
-
|
|
238
|
+
commaSep1(field("subject", $.expression)), // remove comma use tuples (a, b) and match against tuples
|
|
213
|
-
|
|
239
|
+
"is",
|
|
214
|
-
|
|
240
|
+
repeat(field("case", $.case)),
|
|
215
|
-
|
|
241
|
+
),
|
|
216
242
|
),
|
|
217
243
|
|
|
218
|
-
case: ($) => seq(commaSep1($.case_pattern), "
|
|
244
|
+
case: ($) => seq(commaSep1($.case_pattern), "=>", field("body", $.body)),
|
|
219
245
|
|
|
220
246
|
case_pattern: ($) =>
|
|
221
247
|
prec(
|
|
@@ -243,32 +269,29 @@ module.exports = grammar({
|
|
|
243
269
|
$.comparison_operator,
|
|
244
270
|
$.not_operator,
|
|
245
271
|
$.boolean_operator,
|
|
246
|
-
$.closure,
|
|
272
|
+
// $.closure,
|
|
247
273
|
$.primary_expression,
|
|
248
274
|
$.ternary_expression,
|
|
249
275
|
),
|
|
250
276
|
|
|
251
|
-
// a == 2 ? b : c
|
|
252
|
-
// a ?: b
|
|
253
|
-
|
|
254
277
|
primary_expression: ($) =>
|
|
255
278
|
choice(
|
|
256
279
|
$.binary_operator,
|
|
257
|
-
$.
|
|
280
|
+
$.this,
|
|
258
281
|
$.identifier,
|
|
259
|
-
$.
|
|
282
|
+
$.type_identifier,
|
|
260
283
|
$.string,
|
|
261
284
|
$.integer,
|
|
262
285
|
$.float,
|
|
263
286
|
$.unary_operator,
|
|
264
|
-
// $.reference,
|
|
265
287
|
$.attribute,
|
|
266
|
-
$.
|
|
288
|
+
$.fn_call,
|
|
289
|
+
$.type_call,
|
|
267
290
|
$.parenthesized_expression,
|
|
268
291
|
),
|
|
269
292
|
|
|
270
293
|
parenthesized_expression: ($) =>
|
|
271
|
-
prec(PREC.parenthesized_expression, seq("
|
|
294
|
+
prec(PREC.parenthesized_expression, seq("{", $.expression, "}")),
|
|
272
295
|
|
|
273
296
|
not_operator: ($) =>
|
|
274
297
|
prec(PREC.not, seq("!", field("argument", $.expression))),
|
|
@@ -305,7 +328,7 @@ module.exports = grammar({
|
|
|
305
328
|
[prec.left, "^", PREC.xor],
|
|
306
329
|
[prec.left, "<<", PREC.shift],
|
|
307
330
|
[prec.left, ">>", PREC.shift],
|
|
308
|
-
[prec.left, "..", PREC.range],
|
|
331
|
+
// [prec.left, "..", PREC.range],
|
|
309
332
|
];
|
|
310
333
|
// @ts-ignore
|
|
311
334
|
return choice(
|
|
@@ -343,8 +366,9 @@ module.exports = grammar({
|
|
|
343
366
|
|
|
344
367
|
closure: ($) =>
|
|
345
368
|
seq(
|
|
369
|
+
"|",
|
|
346
370
|
field("parameters", optional(commaSep1($.identifier))),
|
|
347
|
-
"
|
|
371
|
+
"|",
|
|
348
372
|
field("body", $.body),
|
|
349
373
|
),
|
|
350
374
|
|
|
@@ -354,24 +378,30 @@ module.exports = grammar({
|
|
|
354
378
|
seq(
|
|
355
379
|
field("object", $.primary_expression),
|
|
356
380
|
".",
|
|
381
|
+
choice(
|
|
357
|
-
|
|
382
|
+
$.identifier,
|
|
383
|
+
$.fn_call,
|
|
384
|
+
)
|
|
358
385
|
),
|
|
359
386
|
),
|
|
360
387
|
|
|
361
|
-
|
|
388
|
+
fn_call: ($) =>
|
|
362
|
-
prec.left(
|
|
363
|
-
|
|
389
|
+
prec(PREC.call, seq(
|
|
364
|
-
seq(
|
|
365
|
-
|
|
390
|
+
field("function", $.identifier),
|
|
366
|
-
|
|
391
|
+
field(
|
|
367
|
-
|
|
392
|
+
"arguments",
|
|
368
|
-
choice(
|
|
369
|
-
seq(optional($.argument_list), $.lambda_literal),
|
|
370
|
-
|
|
393
|
+
$.argument_list,
|
|
371
|
-
),
|
|
372
|
-
),
|
|
373
394
|
),
|
|
395
|
+
)),
|
|
396
|
+
|
|
397
|
+
type_call: ($) =>
|
|
398
|
+
prec(PREC.call, seq(
|
|
399
|
+
field("type", $.type_identifier),
|
|
400
|
+
field(
|
|
401
|
+
"arguments",
|
|
402
|
+
$.argument_list,
|
|
374
|
-
|
|
403
|
+
),
|
|
404
|
+
)),
|
|
375
405
|
|
|
376
406
|
argument_list: ($) =>
|
|
377
407
|
seq(
|
|
@@ -399,46 +429,46 @@ module.exports = grammar({
|
|
|
399
429
|
// Literals
|
|
400
430
|
// ==========
|
|
401
431
|
|
|
402
|
-
|
|
432
|
+
string: $ => seq(
|
|
403
|
-
prec(
|
|
404
|
-
PREC.LAMBDA_LITERAL,
|
|
405
|
-
seq(
|
|
406
|
-
|
|
433
|
+
$.string_start,
|
|
407
|
-
optional(seq(optional($.lambda_parameters), "->")),
|
|
408
|
-
|
|
434
|
+
repeat(choice($.interpolation, $.string_content)),
|
|
409
|
-
|
|
435
|
+
$.string_end,
|
|
410
|
-
|
|
436
|
+
),
|
|
411
|
-
),
|
|
412
|
-
|
|
413
|
-
lambda_parameters: ($) => sep1($._lambda_parameter, ","),
|
|
414
|
-
|
|
415
|
-
_lambda_parameter: ($) =>
|
|
416
|
-
choice($.variable_declaration, $.multi_variable_declaration),
|
|
417
|
-
|
|
418
|
-
variable_declaration: ($) =>
|
|
419
|
-
prec.left(
|
|
420
|
-
PREC.VAR_DECL,
|
|
421
|
-
seq(
|
|
422
|
-
// repeat($.annotation), TODO
|
|
423
|
-
$.identifier,
|
|
424
|
-
|
|
437
|
+
string_content: $ => prec.right(repeat1(
|
|
425
|
-
),
|
|
426
|
-
),
|
|
427
|
-
|
|
428
|
-
multi_variable_declaration: ($) =>
|
|
429
|
-
seq("(", sep1($.variable_declaration, ","), ")"),
|
|
430
|
-
|
|
431
|
-
string: ($) =>
|
|
432
|
-
seq(
|
|
433
|
-
'"',
|
|
434
|
-
repeat(choice($.escape_sequence, $.quoted_content)),
|
|
435
|
-
token.immediate('"'),
|
|
436
|
-
),
|
|
437
|
-
escape_sequence: ($) =>
|
|
438
438
|
choice(
|
|
439
|
+
$.escape_interpolation,
|
|
440
|
+
$.escape_sequence,
|
|
441
|
+
$._not_escape_sequence,
|
|
442
|
+
$._string_content,
|
|
443
|
+
))),
|
|
444
|
+
|
|
445
|
+
interpolation: $ => seq(
|
|
446
|
+
'{',
|
|
447
|
+
field('expression', "abc"),
|
|
448
|
+
'}',
|
|
449
|
+
),
|
|
450
|
+
|
|
451
|
+
// _f_expression: $ => choice(
|
|
452
|
+
// $.expression,
|
|
453
|
+
// $.expression_list,
|
|
454
|
+
// $.pattern_list,
|
|
455
|
+
// $.yield,
|
|
456
|
+
// ),
|
|
457
|
+
|
|
458
|
+
escape_sequence: _ => token.immediate(prec(1, seq(
|
|
459
|
+
'\\',
|
|
460
|
+
choice(
|
|
461
|
+
/u[a-fA-F\d]{4}/,
|
|
462
|
+
/U[a-fA-F\d]{8}/,
|
|
463
|
+
/x[a-fA-F\d]{2}/,
|
|
464
|
+
/\d{1,3}/,
|
|
465
|
+
/\r?\n/,
|
|
439
|
-
|
|
466
|
+
/['"abfrntv\\]/,
|
|
440
|
-
|
|
467
|
+
/N\{[^}]+\}/,
|
|
441
468
|
),
|
|
469
|
+
))),
|
|
470
|
+
|
|
471
|
+
_not_escape_sequence: _ => token.immediate('\\'),
|
|
442
472
|
|
|
443
473
|
float: ($) =>
|
|
444
474
|
token(
|
|
@@ -466,15 +496,16 @@ module.exports = grammar({
|
|
|
466
496
|
token(seq("0", /[bB]/, BIN_DIGITS)),
|
|
467
497
|
),
|
|
468
498
|
|
|
469
|
-
|
|
499
|
+
this: (_) => /this/,
|
|
470
500
|
identifier: (_) => /[_a-z][_a-zA-Z0-9]*/,
|
|
471
|
-
fnname: (_) => /[a-z][a-z]*(([A-Z][a-z]+)*[A-Z]?|([a-z]+[A-Z])*|[A-Z])/, // lowerCamelCase no digits
|
|
472
|
-
|
|
501
|
+
generic: ($) => choice($.a, $.b, $.c, $.d), // single letter
|
|
502
|
+
a: (_) => token("a"),
|
|
503
|
+
b: (_) => token("b"),
|
|
504
|
+
c: (_) => token("c"),
|
|
505
|
+
d: (_) => token("d"),
|
|
506
|
+
var_identier: (_) => /[a-z]+(_[a-z0-9]+)*/, // lower snake case
|
|
507
|
+
fn_identifier: (_) => /[a-z][a-zA-Z0-9]*/, // camel case
|
|
473
|
-
|
|
508
|
+
type_identifier: (_) => /[A-Z][a-zA-Z0-9]*/, // capital case
|
|
474
|
-
|
|
475
|
-
comment: (_) => token(seq("//", /.*/)),
|
|
476
|
-
// whitespace: (_) => /\s+/,
|
|
477
|
-
doc_comment: (_) => token(seq("`", /.*/)),
|
|
478
509
|
},
|
|
479
510
|
});
|
|
480
511
|
|
|
@@ -482,6 +513,10 @@ function commaSep1(rule) {
|
|
|
482
513
|
return sep1(rule, ",");
|
|
483
514
|
}
|
|
484
515
|
|
|
516
|
+
function newlineSep1(rule) {
|
|
517
|
+
return sep1(rule, $._newline);
|
|
518
|
+
}
|
|
519
|
+
|
|
485
520
|
function sep1(rule, separator) {
|
|
486
521
|
return seq(rule, repeat(seq(separator, rule)));
|
|
487
522
|
}
|
tooling/tree-sitter-plum/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "tree-sitter-
|
|
2
|
+
"name": "tree-sitter-plum",
|
|
3
3
|
"version": "0.0.1",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "plum grammar for tree-sitter",
|
|
5
5
|
"main": "bindings/node",
|
|
6
6
|
"types": "bindings/node",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"parser",
|
|
9
9
|
"lexer",
|
|
10
|
-
"
|
|
10
|
+
"plum"
|
|
11
11
|
],
|
|
12
12
|
"files": [
|
|
13
13
|
"grammar.js",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"parse": "tree-sitter parse",
|
|
49
49
|
"test": "tree-sitter test"
|
|
50
50
|
},
|
|
51
|
-
"repository": "https://github.com/pyrossh/
|
|
51
|
+
"repository": "https://github.com/pyrossh/plum",
|
|
52
52
|
"tree-sitter": [
|
|
53
53
|
{
|
|
54
|
-
"scope": "source.
|
|
54
|
+
"scope": "source.plum",
|
|
55
55
|
"file-types": [
|
|
56
|
-
"
|
|
56
|
+
"plum"
|
|
57
57
|
],
|
|
58
|
-
"injection-regex": "
|
|
58
|
+
"injection-regex": "plum",
|
|
59
59
|
"highlights": [
|
|
60
60
|
"queries/highlights.scm"
|
|
61
61
|
],
|
|
@@ -107,4 +107,4 @@
|
|
|
107
107
|
]
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
}
|
|
110
|
+
}
|
tooling/tree-sitter-plum/prebuilds/darwin-arm64/tree-sitter-kestrel.node
DELETED
|
Binary file
|
tooling/tree-sitter-plum/pyproject.toml
CHANGED
|
@@ -3,10 +3,10 @@ requires = ["setuptools>=42", "wheel"]
|
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
|
-
name = "tree-sitter-
|
|
6
|
+
name = "tree-sitter-plum"
|
|
7
|
-
description = "
|
|
7
|
+
description = "plum grammar for tree-sitter"
|
|
8
8
|
version = "0.0.1"
|
|
9
|
-
keywords = ["incremental", "parsing", "tree-sitter", "
|
|
9
|
+
keywords = ["incremental", "parsing", "tree-sitter", "plum"]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Intended Audience :: Developers",
|
|
12
12
|
"License :: OSI Approved :: MIT License",
|
|
@@ -19,7 +19,7 @@ license.text = "MIT"
|
|
|
19
19
|
readme = "README.md"
|
|
20
20
|
|
|
21
21
|
[project.urls]
|
|
22
|
-
Homepage = "https://github.com/tree-sitter/tree-sitter-
|
|
22
|
+
Homepage = "https://github.com/tree-sitter/tree-sitter-plum"
|
|
23
23
|
|
|
24
24
|
[project.optional-dependencies]
|
|
25
25
|
core = ["tree-sitter~=0.21"]
|
tooling/tree-sitter-plum/setup.py
CHANGED
|
@@ -9,7 +9,7 @@ from wheel.bdist_wheel import bdist_wheel
|
|
|
9
9
|
class Build(build):
|
|
10
10
|
def run(self):
|
|
11
11
|
if isdir("queries"):
|
|
12
|
-
dest = join(self.build_lib, "
|
|
12
|
+
dest = join(self.build_lib, "tree_sitter_plum", "queries")
|
|
13
13
|
self.copy_tree("queries", dest)
|
|
14
14
|
super().run()
|
|
15
15
|
|
|
@@ -26,35 +26,37 @@ setup(
|
|
|
26
26
|
packages=find_packages("bindings/python"),
|
|
27
27
|
package_dir={"": "bindings/python"},
|
|
28
28
|
package_data={
|
|
29
|
-
"
|
|
29
|
+
"tree_sitter_plum": ["*.pyi", "py.typed"],
|
|
30
|
-
"
|
|
30
|
+
"tree_sitter_plum.queries": ["*.scm"],
|
|
31
31
|
},
|
|
32
|
-
ext_package="
|
|
32
|
+
ext_package="tree_sitter_plum",
|
|
33
33
|
ext_modules=[
|
|
34
34
|
Extension(
|
|
35
35
|
name="_binding",
|
|
36
36
|
sources=[
|
|
37
|
-
"bindings/python/
|
|
37
|
+
"bindings/python/tree_sitter_plum/binding.c",
|
|
38
38
|
"src/parser.c",
|
|
39
|
+
"src/scanner.c",
|
|
39
40
|
# NOTE: if your language uses an external scanner, add it here.
|
|
40
41
|
],
|
|
41
|
-
extra_compile_args=
|
|
42
|
+
extra_compile_args=(
|
|
43
|
+
[
|
|
42
|
-
|
|
44
|
+
"-std=c11",
|
|
45
|
+
]
|
|
43
|
-
|
|
46
|
+
if system() != "Windows"
|
|
47
|
+
else [
|
|
44
|
-
|
|
48
|
+
"/std:c11",
|
|
45
|
-
|
|
49
|
+
"/utf-8",
|
|
50
|
+
]
|
|
46
|
-
|
|
51
|
+
),
|
|
47
52
|
define_macros=[
|
|
48
53
|
("Py_LIMITED_API", "0x03080000"),
|
|
49
|
-
("PY_SSIZE_T_CLEAN", None)
|
|
54
|
+
("PY_SSIZE_T_CLEAN", None),
|
|
50
55
|
],
|
|
51
56
|
include_dirs=["src"],
|
|
52
57
|
py_limited_api=True,
|
|
53
58
|
)
|
|
54
59
|
],
|
|
55
|
-
cmdclass={
|
|
56
|
-
"build": Build,
|
|
57
|
-
|
|
60
|
+
cmdclass={"build": Build, "bdist_wheel": BdistWheel},
|
|
58
|
-
},
|
|
59
|
-
zip_safe=False
|
|
61
|
+
zip_safe=False,
|
|
60
62
|
)
|
tooling/tree-sitter-plum/src/grammar.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/node-types.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/parser.c
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/scanner.c
CHANGED
|
@@ -1,29 +1,433 @@
|
|
|
1
|
+
#include "tree_sitter/array.h"
|
|
1
|
-
#include
|
|
2
|
+
#include "tree_sitter/parser.h"
|
|
3
|
+
|
|
4
|
+
#include <assert.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <string.h>
|
|
2
8
|
|
|
3
9
|
enum TokenType {
|
|
10
|
+
NEWLINE,
|
|
11
|
+
INDENT,
|
|
12
|
+
DEDENT,
|
|
13
|
+
STRING_START,
|
|
4
|
-
|
|
14
|
+
STRING_CONTENT,
|
|
15
|
+
ESCAPE_INTERPOLATION,
|
|
16
|
+
STRING_END,
|
|
17
|
+
COMMENT,
|
|
18
|
+
CLOSE_PAREN,
|
|
19
|
+
CLOSE_BRACKET,
|
|
20
|
+
CLOSE_BRACE,
|
|
21
|
+
EXCEPT,
|
|
5
22
|
};
|
|
6
23
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
typedef enum {
|
|
25
|
+
SingleQuote = 1 << 0,
|
|
26
|
+
DoubleQuote = 1 << 1,
|
|
27
|
+
BackQuote = 1 << 2,
|
|
28
|
+
Raw = 1 << 3,
|
|
29
|
+
Format = 1 << 4,
|
|
30
|
+
Triple = 1 << 5,
|
|
31
|
+
Bytes = 1 << 6,
|
|
32
|
+
} Flags;
|
|
33
|
+
|
|
34
|
+
typedef struct {
|
|
35
|
+
char flags;
|
|
36
|
+
} Delimiter;
|
|
37
|
+
|
|
38
|
+
static inline Delimiter new_delimiter() { return (Delimiter){0}; }
|
|
39
|
+
|
|
40
|
+
static inline bool is_format(Delimiter *delimiter) { return delimiter->flags & Format; }
|
|
41
|
+
|
|
42
|
+
static inline bool is_raw(Delimiter *delimiter) { return delimiter->flags & Raw; }
|
|
43
|
+
|
|
44
|
+
static inline bool is_triple(Delimiter *delimiter) { return delimiter->flags & Triple; }
|
|
45
|
+
|
|
46
|
+
static inline bool is_bytes(Delimiter *delimiter) { return delimiter->flags & Bytes; }
|
|
47
|
+
|
|
48
|
+
static inline int32_t end_character(Delimiter *delimiter) {
|
|
49
|
+
if (delimiter->flags & SingleQuote) {
|
|
50
|
+
return '\'';
|
|
51
|
+
}
|
|
52
|
+
if (delimiter->flags & DoubleQuote) {
|
|
53
|
+
return '"';
|
|
54
|
+
}
|
|
55
|
+
if (delimiter->flags & BackQuote) {
|
|
56
|
+
return '`';
|
|
57
|
+
}
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static inline void set_format(Delimiter *delimiter) { delimiter->flags |= Format; }
|
|
62
|
+
|
|
63
|
+
static inline void set_raw(Delimiter *delimiter) { delimiter->flags |= Raw; }
|
|
64
|
+
|
|
65
|
+
static inline void set_triple(Delimiter *delimiter) { delimiter->flags |= Triple; }
|
|
66
|
+
|
|
67
|
+
static inline void set_bytes(Delimiter *delimiter) { delimiter->flags |= Bytes; }
|
|
68
|
+
|
|
69
|
+
static inline void set_end_character(Delimiter *delimiter, int32_t character) {
|
|
70
|
+
switch (character) {
|
|
71
|
+
case '\'':
|
|
72
|
+
delimiter->flags |= SingleQuote;
|
|
73
|
+
break;
|
|
74
|
+
case '"':
|
|
75
|
+
delimiter->flags |= DoubleQuote;
|
|
76
|
+
break;
|
|
77
|
+
case '`':
|
|
78
|
+
delimiter->flags |= BackQuote;
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
assert(false);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
typedef struct {
|
|
86
|
+
Array(uint16_t) indents;
|
|
87
|
+
Array(Delimiter) delimiters;
|
|
88
|
+
bool inside_f_string;
|
|
89
|
+
} Scanner;
|
|
90
|
+
|
|
91
|
+
static inline void advance(TSLexer *lexer) { lexer->advance(lexer, false); }
|
|
92
|
+
|
|
93
|
+
static inline void skip(TSLexer *lexer) { lexer->advance(lexer, true); }
|
|
94
|
+
|
|
95
|
+
bool tree_sitter_plum_external_scanner_scan(void *payload, TSLexer *lexer, const bool *valid_symbols) {
|
|
96
|
+
Scanner *scanner = (Scanner *)payload;
|
|
97
|
+
|
|
98
|
+
bool error_recovery_mode = valid_symbols[STRING_CONTENT] && valid_symbols[INDENT];
|
|
99
|
+
bool within_brackets = valid_symbols[CLOSE_BRACE] || valid_symbols[CLOSE_PAREN] || valid_symbols[CLOSE_BRACKET];
|
|
100
|
+
|
|
101
|
+
bool advanced_once = false;
|
|
102
|
+
if (valid_symbols[ESCAPE_INTERPOLATION] && scanner->delimiters.size > 0 &&
|
|
103
|
+
(lexer->lookahead == '{' || lexer->lookahead == '}') && !error_recovery_mode) {
|
|
104
|
+
Delimiter *delimiter = array_back(&scanner->delimiters);
|
|
105
|
+
if (is_format(delimiter)) {
|
|
106
|
+
lexer->mark_end(lexer);
|
|
107
|
+
bool is_left_brace = lexer->lookahead == '{';
|
|
108
|
+
advance(lexer);
|
|
109
|
+
advanced_once = true;
|
|
110
|
+
if ((lexer->lookahead == '{' && is_left_brace) || (lexer->lookahead == '}' && !is_left_brace)) {
|
|
111
|
+
advance(lexer);
|
|
112
|
+
lexer->mark_end(lexer);
|
|
113
|
+
lexer->result_symbol = ESCAPE_INTERPOLATION;
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (valid_symbols[STRING_CONTENT] && scanner->delimiters.size > 0 && !error_recovery_mode) {
|
|
121
|
+
Delimiter *delimiter = array_back(&scanner->delimiters);
|
|
122
|
+
int32_t end_char = end_character(delimiter);
|
|
123
|
+
bool has_content = advanced_once;
|
|
124
|
+
while (lexer->lookahead) {
|
|
125
|
+
if ((advanced_once || lexer->lookahead == '{' || lexer->lookahead == '}') && is_format(delimiter)) {
|
|
126
|
+
lexer->mark_end(lexer);
|
|
127
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
128
|
+
return has_content;
|
|
129
|
+
}
|
|
130
|
+
if (lexer->lookahead == '\\') {
|
|
131
|
+
if (is_raw(delimiter)) {
|
|
132
|
+
// Step over the backslash.
|
|
133
|
+
advance(lexer);
|
|
134
|
+
// Step over any escaped quotes.
|
|
135
|
+
if (lexer->lookahead == end_character(delimiter) || lexer->lookahead == '\\') {
|
|
136
|
+
advance(lexer);
|
|
137
|
+
}
|
|
138
|
+
// Step over newlines
|
|
139
|
+
if (lexer->lookahead == '\r') {
|
|
140
|
+
advance(lexer);
|
|
141
|
+
if (lexer->lookahead == '\n') {
|
|
142
|
+
advance(lexer);
|
|
143
|
+
}
|
|
144
|
+
} else if (lexer->lookahead == '\n') {
|
|
145
|
+
advance(lexer);
|
|
146
|
+
}
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (is_bytes(delimiter)) {
|
|
150
|
+
lexer->mark_end(lexer);
|
|
151
|
+
advance(lexer);
|
|
152
|
+
if (lexer->lookahead == 'N' || lexer->lookahead == 'u' || lexer->lookahead == 'U') {
|
|
153
|
+
// In bytes string, \N{...}, \uXXXX and \UXXXXXXXX are
|
|
154
|
+
// not escape sequences
|
|
155
|
+
// https://docs.plum.org/3/reference/lexical_analysis.html#string-and-bytes-literals
|
|
156
|
+
advance(lexer);
|
|
157
|
+
} else {
|
|
158
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
159
|
+
return has_content;
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
lexer->mark_end(lexer);
|
|
163
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
164
|
+
return has_content;
|
|
165
|
+
}
|
|
166
|
+
} else if (lexer->lookahead == end_char) {
|
|
167
|
+
if (is_triple(delimiter)) {
|
|
168
|
+
lexer->mark_end(lexer);
|
|
169
|
+
advance(lexer);
|
|
170
|
+
if (lexer->lookahead == end_char) {
|
|
171
|
+
advance(lexer);
|
|
172
|
+
if (lexer->lookahead == end_char) {
|
|
173
|
+
if (has_content) {
|
|
174
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
175
|
+
} else {
|
|
176
|
+
advance(lexer);
|
|
177
|
+
lexer->mark_end(lexer);
|
|
178
|
+
array_pop(&scanner->delimiters);
|
|
179
|
+
lexer->result_symbol = STRING_END;
|
|
180
|
+
scanner->inside_f_string = false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
lexer->mark_end(lexer);
|
|
185
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
lexer->mark_end(lexer);
|
|
189
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
if (has_content) {
|
|
193
|
+
lexer->result_symbol = STRING_CONTENT;
|
|
194
|
+
} else {
|
|
195
|
+
advance(lexer);
|
|
196
|
+
array_pop(&scanner->delimiters);
|
|
197
|
+
lexer->result_symbol = STRING_END;
|
|
198
|
+
scanner->inside_f_string = false;
|
|
199
|
+
}
|
|
200
|
+
lexer->mark_end(lexer);
|
|
201
|
+
return true;
|
|
202
|
+
|
|
203
|
+
} else if (lexer->lookahead == '\n' && has_content && !is_triple(delimiter)) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
advance(lexer);
|
|
207
|
+
has_content = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
lexer->mark_end(lexer);
|
|
212
|
+
|
|
213
|
+
bool found_end_of_line = false;
|
|
214
|
+
uint32_t indent_length = 0;
|
|
215
|
+
int32_t first_comment_indent_length = -1;
|
|
216
|
+
for (;;) {
|
|
217
|
+
if (lexer->lookahead == '\n') {
|
|
218
|
+
found_end_of_line = true;
|
|
219
|
+
indent_length = 0;
|
|
220
|
+
skip(lexer);
|
|
221
|
+
} else if (lexer->lookahead == ' ') {
|
|
222
|
+
indent_length++;
|
|
223
|
+
skip(lexer);
|
|
224
|
+
} else if (lexer->lookahead == '\r' || lexer->lookahead == '\f') {
|
|
225
|
+
indent_length = 0;
|
|
226
|
+
skip(lexer);
|
|
227
|
+
} else if (lexer->lookahead == '\t') {
|
|
228
|
+
indent_length += 8;
|
|
229
|
+
skip(lexer);
|
|
230
|
+
} else if (lexer->lookahead == '#' && (valid_symbols[INDENT] || valid_symbols[DEDENT] ||
|
|
231
|
+
valid_symbols[NEWLINE] || valid_symbols[EXCEPT])) {
|
|
232
|
+
// If we haven't found an EOL yet,
|
|
233
|
+
// then this is a comment after an expression:
|
|
234
|
+
// foo = bar # comment
|
|
235
|
+
// Just return, since we don't want to generate an indent/dedent
|
|
236
|
+
// token.
|
|
237
|
+
if (!found_end_of_line) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
if (first_comment_indent_length == -1) {
|
|
241
|
+
first_comment_indent_length = (int32_t)indent_length;
|
|
242
|
+
}
|
|
243
|
+
while (lexer->lookahead && lexer->lookahead != '\n') {
|
|
244
|
+
skip(lexer);
|
|
245
|
+
}
|
|
246
|
+
skip(lexer);
|
|
247
|
+
indent_length = 0;
|
|
248
|
+
} else if (lexer->lookahead == '\\') {
|
|
249
|
+
skip(lexer);
|
|
250
|
+
if (lexer->lookahead == '\r') {
|
|
251
|
+
skip(lexer);
|
|
252
|
+
}
|
|
253
|
+
if (lexer->lookahead == '\n' || lexer->eof(lexer)) {
|
|
254
|
+
skip(lexer);
|
|
255
|
+
} else {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
} else if (lexer->eof(lexer)) {
|
|
259
|
+
indent_length = 0;
|
|
260
|
+
found_end_of_line = true;
|
|
261
|
+
break;
|
|
262
|
+
} else {
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (found_end_of_line) {
|
|
268
|
+
if (scanner->indents.size > 0) {
|
|
269
|
+
uint16_t current_indent_length = *array_back(&scanner->indents);
|
|
270
|
+
|
|
271
|
+
if (valid_symbols[INDENT] && indent_length > current_indent_length) {
|
|
272
|
+
array_push(&scanner->indents, indent_length);
|
|
273
|
+
lexer->result_symbol = INDENT;
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
bool next_tok_is_string_start =
|
|
278
|
+
lexer->lookahead == '\"' || lexer->lookahead == '\'' || lexer->lookahead == '`';
|
|
279
|
+
|
|
280
|
+
if ((valid_symbols[DEDENT] ||
|
|
281
|
+
(!valid_symbols[NEWLINE] && !(valid_symbols[STRING_START] && next_tok_is_string_start) &&
|
|
282
|
+
!within_brackets)) &&
|
|
283
|
+
indent_length < current_indent_length && !scanner->inside_f_string &&
|
|
284
|
+
|
|
285
|
+
// Wait to create a dedent token until we've consumed any
|
|
286
|
+
// comments
|
|
287
|
+
// whose indentation matches the current block.
|
|
288
|
+
first_comment_indent_length < (int32_t)current_indent_length) {
|
|
289
|
+
array_pop(&scanner->indents);
|
|
290
|
+
lexer->result_symbol = DEDENT;
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (valid_symbols[NEWLINE] && !error_recovery_mode) {
|
|
296
|
+
lexer->result_symbol = NEWLINE;
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
if (first_comment_indent_length == -1 && valid_symbols[STRING_START]) {
|
|
302
|
+
Delimiter delimiter = new_delimiter();
|
|
303
|
+
|
|
304
|
+
bool has_flags = false;
|
|
305
|
+
while (lexer->lookahead) {
|
|
306
|
+
if (lexer->lookahead == 'f' || lexer->lookahead == 'F') {
|
|
307
|
+
set_format(&delimiter);
|
|
308
|
+
} else if (lexer->lookahead == 'r' || lexer->lookahead == 'R') {
|
|
309
|
+
set_raw(&delimiter);
|
|
310
|
+
} else if (lexer->lookahead == 'b' || lexer->lookahead == 'B') {
|
|
311
|
+
set_bytes(&delimiter);
|
|
312
|
+
} else if (lexer->lookahead != 'u' && lexer->lookahead != 'U') {
|
|
313
|
+
break;
|
|
314
|
+
}
|
|
315
|
+
has_flags = true;
|
|
316
|
+
advance(lexer);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (lexer->lookahead == '`') {
|
|
320
|
+
set_end_character(&delimiter, '`');
|
|
321
|
+
advance(lexer);
|
|
322
|
+
lexer->mark_end(lexer);
|
|
323
|
+
} else if (lexer->lookahead == '\'') {
|
|
324
|
+
set_end_character(&delimiter, '\'');
|
|
325
|
+
advance(lexer);
|
|
326
|
+
lexer->mark_end(lexer);
|
|
327
|
+
if (lexer->lookahead == '\'') {
|
|
328
|
+
advance(lexer);
|
|
329
|
+
if (lexer->lookahead == '\'') {
|
|
330
|
+
advance(lexer);
|
|
331
|
+
lexer->mark_end(lexer);
|
|
332
|
+
set_triple(&delimiter);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
} else if (lexer->lookahead == '"') {
|
|
336
|
+
set_end_character(&delimiter, '"');
|
|
337
|
+
advance(lexer);
|
|
338
|
+
lexer->mark_end(lexer);
|
|
339
|
+
if (lexer->lookahead == '"') {
|
|
340
|
+
advance(lexer);
|
|
341
|
+
if (lexer->lookahead == '"') {
|
|
342
|
+
advance(lexer);
|
|
343
|
+
lexer->mark_end(lexer);
|
|
344
|
+
set_triple(&delimiter);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (end_character(&delimiter)) {
|
|
350
|
+
array_push(&scanner->delimiters, delimiter);
|
|
351
|
+
lexer->result_symbol = STRING_START;
|
|
352
|
+
scanner->inside_f_string = is_format(&delimiter);
|
|
353
|
+
return true;
|
|
354
|
+
}
|
|
355
|
+
if (has_flags) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
unsigned tree_sitter_plum_external_scanner_serialize(void *payload, char *buffer) {
|
|
364
|
+
Scanner *scanner = (Scanner *)payload;
|
|
365
|
+
|
|
366
|
+
size_t size = 0;
|
|
367
|
+
|
|
368
|
+
buffer[size++] = (char)scanner->inside_f_string;
|
|
369
|
+
|
|
370
|
+
size_t delimiter_count = scanner->delimiters.size;
|
|
371
|
+
if (delimiter_count > UINT8_MAX) {
|
|
372
|
+
delimiter_count = UINT8_MAX;
|
|
373
|
+
}
|
|
374
|
+
buffer[size++] = (char)delimiter_count;
|
|
375
|
+
|
|
376
|
+
if (delimiter_count > 0) {
|
|
377
|
+
memcpy(&buffer[size], scanner->delimiters.contents, delimiter_count);
|
|
378
|
+
}
|
|
379
|
+
size += delimiter_count;
|
|
380
|
+
|
|
381
|
+
uint32_t iter = 1;
|
|
382
|
+
for (; iter < scanner->indents.size && size < TREE_SITTER_SERIALIZATION_BUFFER_SIZE; ++iter) {
|
|
383
|
+
buffer[size++] = (char)*array_get(&scanner->indents, iter);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
return size;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
void tree_sitter_plum_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {
|
|
390
|
+
Scanner *scanner = (Scanner *)payload;
|
|
391
|
+
|
|
392
|
+
array_delete(&scanner->delimiters);
|
|
393
|
+
array_delete(&scanner->indents);
|
|
394
|
+
array_push(&scanner->indents, 0);
|
|
395
|
+
|
|
396
|
+
if (length > 0) {
|
|
397
|
+
size_t size = 0;
|
|
398
|
+
|
|
399
|
+
scanner->inside_f_string = (bool)buffer[size++];
|
|
400
|
+
|
|
401
|
+
size_t delimiter_count = (uint8_t)buffer[size++];
|
|
402
|
+
if (delimiter_count > 0) {
|
|
403
|
+
array_reserve(&scanner->delimiters, delimiter_count);
|
|
404
|
+
scanner->delimiters.size = delimiter_count;
|
|
405
|
+
memcpy(scanner->delimiters.contents, &buffer[size], delimiter_count);
|
|
406
|
+
size += delimiter_count;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
for (; size < length; size++) {
|
|
410
|
+
array_push(&scanner->indents, (unsigned char)buffer[size]);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
void *tree_sitter_plum_external_scanner_create() {
|
|
416
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
|
417
|
+
_Static_assert(sizeof(Delimiter) == sizeof(char), "");
|
|
418
|
+
#else
|
|
419
|
+
assert(sizeof(Delimiter) == sizeof(char));
|
|
420
|
+
#endif
|
|
421
|
+
Scanner *scanner = calloc(1, sizeof(Scanner));
|
|
422
|
+
array_init(&scanner->indents);
|
|
423
|
+
array_init(&scanner->delimiters);
|
|
424
|
+
tree_sitter_plum_external_scanner_deserialize(scanner, NULL, 0);
|
|
425
|
+
return scanner;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
void tree_sitter_plum_external_scanner_destroy(void *payload) {
|
|
429
|
+
Scanner *scanner = (Scanner *)payload;
|
|
430
|
+
array_delete(&scanner->indents);
|
|
431
|
+
array_delete(&scanner->delimiters);
|
|
432
|
+
free(scanner);
|
|
29
433
|
}
|
tooling/tree-sitter-plum/test/corpus/assert.txt
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
assert
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
main() =
|
|
6
|
+
assert 1 != 2
|
|
7
|
+
assert 5 > 4
|
|
8
|
+
assert 7 != 9
|
|
9
|
+
assert List(1, 2) == List(1, 2)
|
|
10
|
+
assert Map("1" => 2) == Map("1" => 2)
|
|
11
|
+
|
|
12
|
+
--------------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
(source
|
|
15
|
+
(fn
|
|
16
|
+
(fn_identifier)
|
|
17
|
+
(body
|
|
18
|
+
(assert
|
|
19
|
+
(expression
|
|
20
|
+
(comparison_operator
|
|
21
|
+
(primary_expression
|
|
22
|
+
(integer))
|
|
23
|
+
(primary_expression
|
|
24
|
+
(integer)))))
|
|
25
|
+
(assert
|
|
26
|
+
(expression
|
|
27
|
+
(comparison_operator
|
|
28
|
+
(primary_expression
|
|
29
|
+
(integer))
|
|
30
|
+
(primary_expression
|
|
31
|
+
(integer)))))
|
|
32
|
+
(assert
|
|
33
|
+
(expression
|
|
34
|
+
(comparison_operator
|
|
35
|
+
(primary_expression
|
|
36
|
+
(integer))
|
|
37
|
+
(primary_expression
|
|
38
|
+
(integer)))))
|
|
39
|
+
(assert
|
|
40
|
+
(expression
|
|
41
|
+
(comparison_operator
|
|
42
|
+
(primary_expression
|
|
43
|
+
(type_call
|
|
44
|
+
(type_identifier)
|
|
45
|
+
(argument_list
|
|
46
|
+
(expression
|
|
47
|
+
(primary_expression
|
|
48
|
+
(integer)))
|
|
49
|
+
(expression
|
|
50
|
+
(primary_expression
|
|
51
|
+
(integer))))))
|
|
52
|
+
(primary_expression
|
|
53
|
+
(type_call
|
|
54
|
+
(type_identifier)
|
|
55
|
+
(argument_list
|
|
56
|
+
(expression
|
|
57
|
+
(primary_expression
|
|
58
|
+
(integer)))
|
|
59
|
+
(expression
|
|
60
|
+
(primary_expression
|
|
61
|
+
(integer)))))))))
|
|
62
|
+
(assert
|
|
63
|
+
(expression
|
|
64
|
+
(comparison_operator
|
|
65
|
+
(primary_expression
|
|
66
|
+
(type_call
|
|
67
|
+
(type_identifier)
|
|
68
|
+
(argument_list
|
|
69
|
+
(pair_argument
|
|
70
|
+
(string
|
|
71
|
+
(string_start)
|
|
72
|
+
(string_content)
|
|
73
|
+
(string_end))
|
|
74
|
+
(expression
|
|
75
|
+
(primary_expression
|
|
76
|
+
(integer)))))))
|
|
77
|
+
(primary_expression
|
|
78
|
+
(type_call
|
|
79
|
+
(type_identifier)
|
|
80
|
+
(argument_list
|
|
81
|
+
(pair_argument
|
|
82
|
+
(string
|
|
83
|
+
(string_start)
|
|
84
|
+
(string_content)
|
|
85
|
+
(string_end))
|
|
86
|
+
(expression
|
|
87
|
+
(primary_expression
|
|
88
|
+
(integer)))))))))))))
|
tooling/tree-sitter-plum/test/corpus/assign.txt
CHANGED
|
@@ -1,181 +1,8 @@
|
|
|
1
|
-
================================================================================
|
|
2
|
-
assign - Int
|
|
3
|
-
================================================================================
|
|
4
|
-
|
|
5
|
-
val startYear = 2101
|
|
6
|
-
val a = +123
|
|
7
|
-
val b = -111
|
|
8
|
-
val c = 456
|
|
9
|
-
val d = 0xcafe
|
|
10
|
-
// val e = 0b001
|
|
11
|
-
|
|
12
|
-
--------------------------------------------------------------------------------
|
|
13
|
-
|
|
14
|
-
(source
|
|
15
|
-
(assign
|
|
16
|
-
(identifier)
|
|
17
|
-
(expression
|
|
18
|
-
(primary_expression
|
|
19
|
-
(integer))))
|
|
20
|
-
(assign
|
|
21
|
-
(identifier)
|
|
22
|
-
(expression
|
|
23
|
-
(primary_expression
|
|
24
|
-
(unary_operator
|
|
25
|
-
(primary_expression
|
|
26
|
-
(integer))))))
|
|
27
|
-
(assign
|
|
28
|
-
(identifier)
|
|
29
|
-
(expression
|
|
30
|
-
(primary_expression
|
|
31
|
-
(unary_operator
|
|
32
|
-
(primary_expression
|
|
33
|
-
(integer))))))
|
|
34
|
-
(assign
|
|
35
|
-
(identifier)
|
|
36
|
-
(expression
|
|
37
|
-
(primary_expression
|
|
38
|
-
(integer))))
|
|
39
|
-
(assign
|
|
40
|
-
(identifier)
|
|
41
|
-
(expression
|
|
42
|
-
(primary_expression
|
|
43
|
-
(integer))))
|
|
44
|
-
(comment))
|
|
45
|
-
|
|
46
|
-
================================================================================
|
|
47
|
-
assign - Float
|
|
48
|
-
================================================================================
|
|
49
|
-
|
|
50
|
-
val pi = 3.14159
|
|
51
|
-
val a = +1.2
|
|
52
|
-
val b = -0.4
|
|
53
|
-
val c = 12.0f
|
|
54
|
-
val d = 15.03f
|
|
55
|
-
// val e = (1 + 2).mod(3).pow(2).sqrt()
|
|
56
|
-
|
|
57
|
-
--------------------------------------------------------------------------------
|
|
58
|
-
|
|
59
|
-
(source
|
|
60
|
-
(assign
|
|
61
|
-
(identifier)
|
|
62
|
-
(expression
|
|
63
|
-
(primary_expression
|
|
64
|
-
(float))))
|
|
65
|
-
(assign
|
|
66
|
-
(identifier)
|
|
67
|
-
(expression
|
|
68
|
-
(primary_expression
|
|
69
|
-
(unary_operator
|
|
70
|
-
(primary_expression
|
|
71
|
-
(float))))))
|
|
72
|
-
(assign
|
|
73
|
-
(identifier)
|
|
74
|
-
(expression
|
|
75
|
-
(primary_expression
|
|
76
|
-
(unary_operator
|
|
77
|
-
(primary_expression
|
|
78
|
-
(float))))))
|
|
79
|
-
(assign
|
|
80
|
-
(identifier)
|
|
81
|
-
(expression
|
|
82
|
-
(primary_expression
|
|
83
|
-
(float))))
|
|
84
|
-
(assign
|
|
85
|
-
(identifier)
|
|
86
|
-
(expression
|
|
87
|
-
(primary_expression
|
|
88
|
-
(float))))
|
|
89
|
-
(comment))
|
|
90
|
-
|
|
91
|
-
================================================================================
|
|
92
|
-
assign - String
|
|
93
|
-
================================================================================
|
|
94
|
-
|
|
95
|
-
val name = "kestrel"
|
|
96
|
-
val a = strOf("123")
|
|
97
|
-
|
|
98
|
-
--------------------------------------------------------------------------------
|
|
99
|
-
|
|
100
|
-
(source
|
|
101
|
-
(assign
|
|
102
|
-
(identifier)
|
|
103
|
-
(expression
|
|
104
|
-
(primary_expression
|
|
105
|
-
(string
|
|
106
|
-
(quoted_content)))))
|
|
107
|
-
(assign
|
|
108
|
-
(identifier)
|
|
109
|
-
(expression
|
|
110
|
-
(primary_expression
|
|
111
|
-
(call
|
|
112
|
-
(reference
|
|
113
|
-
(identifier))
|
|
114
|
-
(argument_list
|
|
115
|
-
(expression
|
|
116
|
-
(primary_expression
|
|
117
|
-
(string
|
|
118
|
-
(quoted_content))))))))))
|
|
119
|
-
|
|
120
|
-
================================================================================
|
|
121
|
-
assign - Type
|
|
122
|
-
================================================================================
|
|
123
|
-
|
|
124
|
-
val debugEnabled = True
|
|
125
|
-
val a = True
|
|
126
|
-
val b = False
|
|
127
|
-
val c = nil
|
|
128
|
-
|
|
129
|
-
--------------------------------------------------------------------------------
|
|
130
|
-
|
|
131
|
-
(source
|
|
132
|
-
(assign
|
|
133
|
-
(identifier)
|
|
134
|
-
(expression
|
|
135
|
-
(primary_expression
|
|
136
|
-
(typename))))
|
|
137
|
-
(assign
|
|
138
|
-
(identifier)
|
|
139
|
-
(expression
|
|
140
|
-
(primary_expression
|
|
141
|
-
(typename))))
|
|
142
|
-
(assign
|
|
143
|
-
(identifier)
|
|
144
|
-
(expression
|
|
145
|
-
(primary_expression
|
|
146
|
-
(typename))))
|
|
147
|
-
(assign
|
|
148
|
-
(identifier)
|
|
149
|
-
(expression
|
|
150
|
-
(primary_expression
|
|
151
|
-
(identifier)))))
|
|
152
|
-
|
|
153
|
-
================================================================================
|
|
154
|
-
assign - Call
|
|
155
|
-
================================================================================
|
|
156
|
-
|
|
157
|
-
val count = counter(10)
|
|
158
|
-
|
|
159
|
-
--------------------------------------------------------------------------------
|
|
160
|
-
|
|
161
|
-
(source
|
|
162
|
-
(assign
|
|
163
|
-
(identifier)
|
|
164
|
-
(expression
|
|
165
|
-
(primary_expression
|
|
166
|
-
(call
|
|
167
|
-
(reference
|
|
168
|
-
(identifier))
|
|
169
|
-
(argument_list
|
|
170
|
-
(expression
|
|
171
|
-
(primary_expression
|
|
172
|
-
(integer)))))))))
|
|
173
|
-
|
|
174
1
|
================================================================================
|
|
175
2
|
assign - Expression
|
|
176
3
|
================================================================================
|
|
177
4
|
|
|
178
|
-
|
|
5
|
+
sum = 1 + ((2 * 3) / 4)
|
|
179
6
|
|
|
180
7
|
--------------------------------------------------------------------------------
|
|
181
8
|
|
|
@@ -208,7 +35,7 @@ val sum = 1 + ((2 * 3) / 4)
|
|
|
208
35
|
assign - Not
|
|
209
36
|
================================================================================
|
|
210
37
|
|
|
211
|
-
|
|
38
|
+
enabled = !False
|
|
212
39
|
|
|
213
40
|
--------------------------------------------------------------------------------
|
|
214
41
|
|
|
@@ -219,13 +46,13 @@ val enabled = !False
|
|
|
219
46
|
(not_operator
|
|
220
47
|
(expression
|
|
221
48
|
(primary_expression
|
|
222
|
-
(
|
|
49
|
+
(type_identifier)))))))
|
|
223
50
|
|
|
224
51
|
================================================================================
|
|
225
52
|
assign - Boolean expression
|
|
226
53
|
================================================================================
|
|
227
54
|
|
|
228
|
-
|
|
55
|
+
open = (count > 10) && (enabled == True) || (debug == False)
|
|
229
56
|
|
|
230
57
|
--------------------------------------------------------------------------------
|
|
231
58
|
|
|
@@ -253,7 +80,7 @@ val open = (count > 10) && (enabled == True) || (debug == False)
|
|
|
253
80
|
(primary_expression
|
|
254
81
|
(identifier))
|
|
255
82
|
(primary_expression
|
|
256
|
-
(
|
|
83
|
+
(type_identifier)))))))))
|
|
257
84
|
(expression
|
|
258
85
|
(primary_expression
|
|
259
86
|
(parenthesized_expression
|
|
@@ -262,16 +89,16 @@ val open = (count > 10) && (enabled == True) || (debug == False)
|
|
|
262
89
|
(primary_expression
|
|
263
90
|
(identifier))
|
|
264
91
|
(primary_expression
|
|
265
|
-
(
|
|
92
|
+
(type_identifier)))))))))))
|
|
266
93
|
|
|
267
94
|
================================================================================
|
|
268
95
|
assign - Call list
|
|
269
96
|
================================================================================
|
|
270
97
|
|
|
271
|
-
|
|
98
|
+
countriesList = listOf("US", "INDIA", "CANADA")
|
|
272
|
-
|
|
99
|
+
a = list.of(1, 2, 3)
|
|
273
|
-
|
|
100
|
+
b = list.of(list.of(1), list.of(2), list.of(3))
|
|
274
|
-
|
|
101
|
+
c = list.of(1, 2, 3 * 4, 8, n)
|
|
275
102
|
|
|
276
103
|
--------------------------------------------------------------------------------
|
|
277
104
|
|
|
@@ -287,15 +114,21 @@ val c = list.of(1, 2, 3 * 4, 8, n)
|
|
|
287
114
|
(expression
|
|
288
115
|
(primary_expression
|
|
289
116
|
(string
|
|
117
|
+
(string_start)
|
|
290
|
-
(
|
|
118
|
+
(string_content)
|
|
119
|
+
(string_end))))
|
|
291
120
|
(expression
|
|
292
121
|
(primary_expression
|
|
293
122
|
(string
|
|
123
|
+
(string_start)
|
|
294
|
-
(
|
|
124
|
+
(string_content)
|
|
125
|
+
(string_end))))
|
|
295
126
|
(expression
|
|
296
127
|
(primary_expression
|
|
297
128
|
(string
|
|
129
|
+
(string_start)
|
|
130
|
+
(string_content)
|
|
298
|
-
(
|
|
131
|
+
(string_end)))))))))
|
|
299
132
|
(assign
|
|
300
133
|
(identifier)
|
|
301
134
|
(expression
|
|
@@ -386,13 +219,13 @@ val c = list.of(1, 2, 3 * 4, 8, n)
|
|
|
386
219
|
assign - Call map
|
|
387
220
|
================================================================================
|
|
388
221
|
|
|
389
|
-
|
|
222
|
+
countryCode = mapOf(
|
|
390
223
|
"in" => "INDIA",
|
|
391
224
|
"us" => "United States",
|
|
392
225
|
"ca" => "Canada"
|
|
393
226
|
)
|
|
394
|
-
|
|
227
|
+
a = mapOf("a" => 1, "b" => 2)
|
|
395
|
-
|
|
228
|
+
b = mapOf("a" => 1, "b" => map.of("c" => 3, "d" => 4))
|
|
396
229
|
|
|
397
230
|
--------------------------------------------------------------------------------
|
|
398
231
|
|
|
@@ -407,25 +240,37 @@ val b = mapOf("a" => 1, "b" => map.of("c" => 3, "d" => 4))
|
|
|
407
240
|
(argument_list
|
|
408
241
|
(pair_argument
|
|
409
242
|
(string
|
|
243
|
+
(string_start)
|
|
410
|
-
(
|
|
244
|
+
(string_content)
|
|
245
|
+
(string_end))
|
|
411
246
|
(expression
|
|
412
247
|
(primary_expression
|
|
413
248
|
(string
|
|
249
|
+
(string_start)
|
|
414
|
-
(
|
|
250
|
+
(string_content)
|
|
251
|
+
(string_end)))))
|
|
415
252
|
(pair_argument
|
|
416
253
|
(string
|
|
254
|
+
(string_start)
|
|
417
|
-
(
|
|
255
|
+
(string_content)
|
|
256
|
+
(string_end))
|
|
418
257
|
(expression
|
|
419
258
|
(primary_expression
|
|
420
259
|
(string
|
|
260
|
+
(string_start)
|
|
421
|
-
(
|
|
261
|
+
(string_content)
|
|
262
|
+
(string_end)))))
|
|
422
263
|
(pair_argument
|
|
423
264
|
(string
|
|
265
|
+
(string_start)
|
|
424
|
-
(
|
|
266
|
+
(string_content)
|
|
267
|
+
(string_end))
|
|
425
268
|
(expression
|
|
426
269
|
(primary_expression
|
|
427
270
|
(string
|
|
271
|
+
(string_start)
|
|
272
|
+
(string_content)
|
|
428
|
-
(
|
|
273
|
+
(string_end))))))))))
|
|
429
274
|
(assign
|
|
430
275
|
(identifier)
|
|
431
276
|
(expression
|
|
@@ -436,13 +281,17 @@ val b = mapOf("a" => 1, "b" => map.of("c" => 3, "d" => 4))
|
|
|
436
281
|
(argument_list
|
|
437
282
|
(pair_argument
|
|
438
283
|
(string
|
|
284
|
+
(string_start)
|
|
439
|
-
(
|
|
285
|
+
(string_content)
|
|
286
|
+
(string_end))
|
|
440
287
|
(expression
|
|
441
288
|
(primary_expression
|
|
442
289
|
(integer))))
|
|
443
290
|
(pair_argument
|
|
444
291
|
(string
|
|
292
|
+
(string_start)
|
|
445
|
-
(
|
|
293
|
+
(string_content)
|
|
294
|
+
(string_end))
|
|
446
295
|
(expression
|
|
447
296
|
(primary_expression
|
|
448
297
|
(integer)))))))))
|
|
@@ -456,13 +305,17 @@ val b = mapOf("a" => 1, "b" => map.of("c" => 3, "d" => 4))
|
|
|
456
305
|
(argument_list
|
|
457
306
|
(pair_argument
|
|
458
307
|
(string
|
|
308
|
+
(string_start)
|
|
459
|
-
(
|
|
309
|
+
(string_content)
|
|
310
|
+
(string_end))
|
|
460
311
|
(expression
|
|
461
312
|
(primary_expression
|
|
462
313
|
(integer))))
|
|
463
314
|
(pair_argument
|
|
464
315
|
(string
|
|
316
|
+
(string_start)
|
|
465
|
-
(
|
|
317
|
+
(string_content)
|
|
318
|
+
(string_end))
|
|
466
319
|
(expression
|
|
467
320
|
(primary_expression
|
|
468
321
|
(call
|
|
@@ -472,13 +325,17 @@ val b = mapOf("a" => 1, "b" => map.of("c" => 3, "d" => 4))
|
|
|
472
325
|
(argument_list
|
|
473
326
|
(pair_argument
|
|
474
327
|
(string
|
|
328
|
+
(string_start)
|
|
475
|
-
(
|
|
329
|
+
(string_content)
|
|
330
|
+
(string_end))
|
|
476
331
|
(expression
|
|
477
332
|
(primary_expression
|
|
478
333
|
(integer))))
|
|
479
334
|
(pair_argument
|
|
480
335
|
(string
|
|
336
|
+
(string_start)
|
|
481
|
-
(
|
|
337
|
+
(string_content)
|
|
338
|
+
(string_end))
|
|
482
339
|
(expression
|
|
483
340
|
(primary_expression
|
|
484
341
|
(integer)))))))))))))))
|
tooling/tree-sitter-plum/test/corpus/enum.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
enum
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
Bool =
|
|
6
|
+
| True
|
|
7
|
+
| False
|
|
8
|
+
|
|
9
|
+
--------------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
(source
|
|
12
|
+
(enum
|
|
13
|
+
(type_identifier)
|
|
14
|
+
(enum_field
|
|
15
|
+
(type_identifier))
|
|
16
|
+
(enum_field
|
|
17
|
+
(type_identifier))))
|
tooling/tree-sitter-plum/test/corpus/{fn.txt → function.txt}
RENAMED
|
@@ -1,185 +1,173 @@
|
|
|
1
1
|
================================================================================
|
|
2
|
-
|
|
2
|
+
function - no return
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
sum(a: Int, b: Int) =
|
|
6
|
-
|
|
6
|
+
todo
|
|
7
7
|
|
|
8
8
|
--------------------------------------------------------------------------------
|
|
9
9
|
|
|
10
10
|
(source
|
|
11
11
|
(fn
|
|
12
|
-
(
|
|
12
|
+
(fn_identifier)
|
|
13
13
|
(param
|
|
14
14
|
(identifier)
|
|
15
15
|
(type
|
|
16
|
-
(
|
|
16
|
+
(type_identifier)))
|
|
17
17
|
(param
|
|
18
18
|
(identifier)
|
|
19
19
|
(type
|
|
20
|
-
(
|
|
20
|
+
(type_identifier)))
|
|
21
|
+
(body
|
|
21
|
-
|
|
22
|
+
(todo))))
|
|
22
23
|
|
|
23
24
|
================================================================================
|
|
24
|
-
|
|
25
|
+
function - return
|
|
25
26
|
================================================================================
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
sum(a: Int, b: Int) -> Int =
|
|
28
|
-
|
|
29
|
+
todo
|
|
29
30
|
|
|
30
31
|
--------------------------------------------------------------------------------
|
|
31
32
|
|
|
32
33
|
(source
|
|
33
34
|
(fn
|
|
34
|
-
(
|
|
35
|
+
(fn_identifier)
|
|
35
36
|
(param
|
|
36
37
|
(identifier)
|
|
37
38
|
(type
|
|
38
|
-
(
|
|
39
|
+
(type_identifier)))
|
|
39
40
|
(param
|
|
40
41
|
(identifier)
|
|
41
42
|
(type
|
|
42
|
-
(
|
|
43
|
+
(type_identifier)))
|
|
43
44
|
(return_type
|
|
44
|
-
(
|
|
45
|
+
(type_identifier))
|
|
46
|
+
(body
|
|
45
|
-
|
|
47
|
+
(todo))))
|
|
46
48
|
|
|
47
49
|
================================================================================
|
|
48
|
-
|
|
50
|
+
function - default value
|
|
49
51
|
================================================================================
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
random(a: Int = 10) =
|
|
52
|
-
|
|
54
|
+
todo
|
|
53
55
|
|
|
54
56
|
--------------------------------------------------------------------------------
|
|
55
57
|
|
|
56
58
|
(source
|
|
57
59
|
(fn
|
|
58
|
-
(
|
|
60
|
+
(fn_identifier)
|
|
59
61
|
(param
|
|
60
62
|
(identifier)
|
|
61
63
|
(type
|
|
62
|
-
(
|
|
64
|
+
(type_identifier))
|
|
63
65
|
(expression
|
|
64
66
|
(primary_expression
|
|
65
67
|
(integer))))
|
|
66
|
-
(
|
|
68
|
+
(body
|
|
67
|
-
(typename))
|
|
68
|
-
|
|
69
|
+
(todo))))
|
|
69
70
|
|
|
70
71
|
================================================================================
|
|
71
|
-
|
|
72
|
+
function - generics
|
|
72
73
|
================================================================================
|
|
73
74
|
|
|
74
|
-
`converts f in fahrenheit to celsius to a value
|
|
75
|
-
|
|
75
|
+
add(param: a, param2: List(b)) -> List(b) =
|
|
76
|
-
|
|
76
|
+
todo
|
|
77
77
|
|
|
78
78
|
--------------------------------------------------------------------------------
|
|
79
79
|
|
|
80
80
|
(source
|
|
81
81
|
(fn
|
|
82
|
-
(
|
|
82
|
+
(fn_identifier)
|
|
83
|
-
(
|
|
83
|
+
(param
|
|
84
|
+
(identifier)
|
|
85
|
+
(type
|
|
86
|
+
(a)))
|
|
84
87
|
(param
|
|
85
88
|
(identifier)
|
|
86
89
|
(type
|
|
87
|
-
(
|
|
90
|
+
(type_identifier)
|
|
91
|
+
(type
|
|
92
|
+
(b))))
|
|
88
93
|
(return_type
|
|
89
|
-
(
|
|
94
|
+
(type_identifier)
|
|
95
|
+
(generics
|
|
96
|
+
(b)))
|
|
97
|
+
(body
|
|
90
|
-
|
|
98
|
+
(todo))))
|
|
91
99
|
|
|
92
100
|
================================================================================
|
|
93
|
-
|
|
101
|
+
function - method
|
|
94
102
|
================================================================================
|
|
95
103
|
|
|
96
|
-
@get(method = "POST", route = "/posts")
|
|
97
|
-
fn createPostAction(req: Request) -> Response {
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
@get("/posts")
|
|
101
|
-
|
|
104
|
+
User\fullname() -> String =
|
|
102
|
-
|
|
105
|
+
todo
|
|
103
106
|
|
|
104
107
|
--------------------------------------------------------------------------------
|
|
105
108
|
|
|
106
109
|
(source
|
|
107
110
|
(fn
|
|
108
|
-
(
|
|
111
|
+
(method_identifier
|
|
109
|
-
(
|
|
112
|
+
(type_identifier)
|
|
110
|
-
|
|
113
|
+
(fn_identifier))
|
|
111
|
-
(argument_list
|
|
112
|
-
(keyword_argument
|
|
113
|
-
(identifier)
|
|
114
|
-
(expression
|
|
115
|
-
(primary_expression
|
|
116
|
-
(string
|
|
117
|
-
(quoted_content)))))
|
|
118
|
-
(keyword_argument
|
|
119
|
-
(identifier)
|
|
120
|
-
(expression
|
|
121
|
-
(primary_expression
|
|
122
|
-
(string
|
|
123
|
-
(quoted_content)))))))
|
|
124
|
-
(fnname)
|
|
125
|
-
(param
|
|
126
|
-
(identifier)
|
|
127
|
-
(type
|
|
128
|
-
(typename)))
|
|
129
114
|
(return_type
|
|
130
|
-
(
|
|
115
|
+
(type_identifier))
|
|
131
|
-
(body
|
|
116
|
+
(body
|
|
117
|
+
(todo))))
|
|
118
|
+
|
|
119
|
+
================================================================================
|
|
120
|
+
function - construtor
|
|
121
|
+
================================================================================
|
|
122
|
+
|
|
123
|
+
List\init(items: ...a) -> List(a) =
|
|
124
|
+
List().add(items)
|
|
125
|
+
|
|
126
|
+
--------------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
(source
|
|
132
129
|
(fn
|
|
133
|
-
(
|
|
130
|
+
(method_identifier
|
|
134
|
-
(
|
|
131
|
+
(type_identifier)
|
|
135
|
-
|
|
132
|
+
(fn_identifier))
|
|
136
|
-
(argument_list
|
|
137
|
-
(expression
|
|
138
|
-
(primary_expression
|
|
139
|
-
(string
|
|
140
|
-
(quoted_content))))))
|
|
141
|
-
(fnname)
|
|
142
133
|
(param
|
|
143
134
|
(identifier)
|
|
135
|
+
(variadic_type
|
|
144
|
-
|
|
136
|
+
(type
|
|
145
|
-
|
|
137
|
+
(a))))
|
|
146
138
|
(return_type
|
|
147
|
-
(
|
|
139
|
+
(type_identifier)
|
|
140
|
+
(generics
|
|
141
|
+
(a)))
|
|
148
|
-
(body
|
|
142
|
+
(body
|
|
143
|
+
(primary_expression
|
|
144
|
+
(attribute
|
|
145
|
+
(primary_expression
|
|
146
|
+
(type_call
|
|
147
|
+
(type_identifier)
|
|
148
|
+
(argument_list)))
|
|
149
|
+
(fn_call
|
|
150
|
+
(identifier)
|
|
151
|
+
(argument_list
|
|
152
|
+
(expression
|
|
153
|
+
(primary_expression
|
|
154
|
+
(identifier))))))))))
|
|
149
155
|
|
|
150
156
|
================================================================================
|
|
151
|
-
|
|
157
|
+
function - static method
|
|
152
158
|
================================================================================
|
|
153
159
|
|
|
154
|
-
|
|
160
|
+
Int::random() -> Int =
|
|
155
|
-
|
|
161
|
+
todo
|
|
156
162
|
|
|
157
163
|
--------------------------------------------------------------------------------
|
|
158
164
|
|
|
159
165
|
(source
|
|
160
166
|
(fn
|
|
161
|
-
(fnname)
|
|
162
|
-
(generics
|
|
163
|
-
|
|
167
|
+
(static_identifier
|
|
164
|
-
(genericname)
|
|
165
|
-
|
|
168
|
+
(type_identifier)
|
|
166
|
-
(generic_type
|
|
167
|
-
(genericname)
|
|
168
|
-
(typename)
|
|
169
|
-
(typename)))
|
|
170
|
-
(param
|
|
171
|
-
(
|
|
169
|
+
(fn_identifier))
|
|
172
|
-
(type
|
|
173
|
-
(typename)
|
|
174
|
-
(typename)))
|
|
175
|
-
(param
|
|
176
|
-
(identifier)
|
|
177
|
-
(type
|
|
178
|
-
(typename)
|
|
179
|
-
(typename)))
|
|
180
170
|
(return_type
|
|
181
|
-
(typename)
|
|
182
|
-
(generics
|
|
183
|
-
(generic_type
|
|
184
|
-
|
|
171
|
+
(type_identifier))
|
|
172
|
+
(body
|
|
185
|
-
|
|
173
|
+
(todo))))
|
tooling/tree-sitter-plum/test/corpus/if.txt
CHANGED
|
@@ -1,161 +1,106 @@
|
|
|
1
1
|
================================================================================
|
|
2
|
-
|
|
2
|
+
if
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
main() =
|
|
6
|
-
val a = (1 * 5) + (2 + 3)
|
|
7
|
-
if a < b
|
|
6
|
+
if a < b
|
|
8
|
-
printLn(a
|
|
7
|
+
printLn("a is less than b")
|
|
9
|
-
|
|
8
|
+
else if a > 9
|
|
10
9
|
printLn(a == 9)
|
|
11
|
-
|
|
10
|
+
else if a > 18
|
|
12
11
|
printLn(b == 0)
|
|
13
|
-
|
|
12
|
+
else
|
|
13
|
+
if a > 5
|
|
14
|
-
|
|
14
|
+
printLn(a)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
--------------------------------------------------------------------------------
|
|
19
|
-
|
|
20
|
-
(source
|
|
21
|
-
|
|
15
|
+
else
|
|
22
|
-
(string
|
|
23
|
-
(string_start)
|
|
24
|
-
(string_end))
|
|
25
|
-
(lambda
|
|
26
|
-
(identifier)
|
|
27
|
-
(body
|
|
28
|
-
(assignment_statement
|
|
29
|
-
(identifier)
|
|
30
|
-
(binary_operator
|
|
31
|
-
|
|
16
|
+
printLn("None")
|
|
32
|
-
(binary_operator
|
|
33
|
-
(integer)
|
|
34
|
-
(integer)))
|
|
35
|
-
(parenthesized_expression
|
|
36
|
-
(binary_operator
|
|
37
|
-
(integer)
|
|
38
|
-
(integer)))))
|
|
39
|
-
(if_statement
|
|
40
|
-
(comparison_operator
|
|
41
|
-
(identifier)
|
|
42
|
-
(identifier))
|
|
43
|
-
(block
|
|
44
|
-
(assert_statement
|
|
45
|
-
(comparison_operator
|
|
46
|
-
(identifier)
|
|
47
|
-
(identifier))))
|
|
48
|
-
(else_if_clause
|
|
49
|
-
(comparison_operator
|
|
50
|
-
(identifier)
|
|
51
|
-
(integer))
|
|
52
|
-
(block
|
|
53
|
-
(assert_statement
|
|
54
|
-
(comparison_operator
|
|
55
|
-
(identifier)
|
|
56
|
-
(integer)))))
|
|
57
|
-
(else_if_clause
|
|
58
|
-
(comparison_operator
|
|
59
|
-
(identifier)
|
|
60
|
-
(integer))
|
|
61
|
-
(block
|
|
62
|
-
(assert_statement
|
|
63
|
-
(comparison_operator
|
|
64
|
-
(identifier)
|
|
65
|
-
(integer)))))
|
|
66
|
-
(else_clause
|
|
67
|
-
(block
|
|
68
|
-
(assert_statement
|
|
69
|
-
(comparison_operator
|
|
70
|
-
(identifier)
|
|
71
|
-
(integer))))))))))
|
|
72
|
-
|
|
73
|
-
================================================================================
|
|
74
|
-
statement - assert
|
|
75
|
-
================================================================================
|
|
76
|
-
|
|
77
|
-
fn main() {
|
|
78
|
-
assert 1 != 2
|
|
79
|
-
assert 5 > 4
|
|
80
|
-
assert 7 != 9
|
|
81
|
-
assert listOf(1, 2) == listOf(1, 2)
|
|
82
|
-
assert mapOf("1" => 2) == mapOf("1" => 2)
|
|
83
|
-
}
|
|
84
17
|
|
|
85
18
|
--------------------------------------------------------------------------------
|
|
86
19
|
|
|
87
20
|
(source
|
|
88
21
|
(fn
|
|
89
|
-
(
|
|
22
|
+
(fn_identifier)
|
|
90
23
|
(body
|
|
91
|
-
(
|
|
24
|
+
(if
|
|
92
25
|
(expression
|
|
93
26
|
(comparison_operator
|
|
94
27
|
(primary_expression
|
|
95
|
-
(
|
|
28
|
+
(identifier))
|
|
96
29
|
(primary_expression
|
|
97
|
-
(
|
|
30
|
+
(identifier))))
|
|
31
|
+
(body
|
|
32
|
+
(primary_expression
|
|
98
|
-
|
|
33
|
+
(fn_call
|
|
34
|
+
(identifier)
|
|
35
|
+
(argument_list
|
|
99
|
-
|
|
36
|
+
(expression
|
|
37
|
+
(primary_expression
|
|
38
|
+
(string
|
|
39
|
+
(string_start)
|
|
40
|
+
(string_content)
|
|
41
|
+
(string_end))))))))
|
|
42
|
+
(else_if
|
|
43
|
+
(expression
|
|
100
|
-
|
|
44
|
+
(comparison_operator
|
|
101
|
-
|
|
45
|
+
(primary_expression
|
|
102
|
-
|
|
46
|
+
(identifier))
|
|
103
|
-
|
|
47
|
+
(primary_expression
|
|
104
|
-
|
|
48
|
+
(integer))))
|
|
105
|
-
|
|
49
|
+
(body
|
|
106
|
-
(expression
|
|
107
|
-
(comparison_operator
|
|
108
|
-
(primary_expression
|
|
109
|
-
(integer))
|
|
110
|
-
(primary_expression
|
|
111
|
-
(integer)))))
|
|
112
|
-
(assert
|
|
113
|
-
(expression
|
|
114
|
-
(comparison_operator
|
|
115
50
|
(primary_expression
|
|
116
|
-
(
|
|
51
|
+
(fn_call
|
|
117
|
-
(reference
|
|
118
|
-
|
|
52
|
+
(identifier)
|
|
119
53
|
(argument_list
|
|
120
54
|
(expression
|
|
55
|
+
(comparison_operator
|
|
121
|
-
|
|
56
|
+
(primary_expression
|
|
57
|
+
(identifier))
|
|
58
|
+
(primary_expression
|
|
122
|
-
|
|
59
|
+
(integer)))))))))
|
|
60
|
+
(else_if
|
|
123
|
-
|
|
61
|
+
(expression
|
|
62
|
+
(comparison_operator
|
|
124
|
-
|
|
63
|
+
(primary_expression
|
|
64
|
+
(identifier))
|
|
65
|
+
(primary_expression
|
|
125
|
-
|
|
66
|
+
(integer))))
|
|
67
|
+
(body
|
|
126
68
|
(primary_expression
|
|
127
|
-
(
|
|
69
|
+
(fn_call
|
|
128
|
-
(reference
|
|
129
|
-
|
|
70
|
+
(identifier)
|
|
130
71
|
(argument_list
|
|
131
72
|
(expression
|
|
132
|
-
(primary_expression
|
|
133
|
-
(integer)))
|
|
134
|
-
(expression
|
|
135
|
-
(primary_expression
|
|
136
|
-
(integer)))))))))
|
|
137
|
-
(assert
|
|
138
|
-
(expression
|
|
139
|
-
|
|
73
|
+
(comparison_operator
|
|
140
|
-
(primary_expression
|
|
141
|
-
(call
|
|
142
|
-
(reference
|
|
143
|
-
(identifier))
|
|
144
|
-
(argument_list
|
|
145
|
-
(pair_argument
|
|
146
|
-
(string
|
|
147
|
-
(quoted_content))
|
|
148
|
-
(expression
|
|
149
74
|
(primary_expression
|
|
150
|
-
(integer)))))))
|
|
151
|
-
(primary_expression
|
|
152
|
-
(call
|
|
153
|
-
(reference
|
|
154
|
-
|
|
75
|
+
(identifier))
|
|
155
|
-
(argument_list
|
|
156
|
-
(pair_argument
|
|
157
|
-
(string
|
|
158
|
-
(quoted_content))
|
|
159
|
-
(expression
|
|
160
76
|
(primary_expression
|
|
161
|
-
(integer)))))))))
|
|
77
|
+
(integer)))))))))
|
|
78
|
+
(else
|
|
79
|
+
(body
|
|
80
|
+
(if
|
|
81
|
+
(expression
|
|
82
|
+
(comparison_operator
|
|
83
|
+
(primary_expression
|
|
84
|
+
(identifier))
|
|
85
|
+
(primary_expression
|
|
86
|
+
(integer))))
|
|
87
|
+
(body
|
|
88
|
+
(primary_expression
|
|
89
|
+
(fn_call
|
|
90
|
+
(identifier)
|
|
91
|
+
(argument_list
|
|
92
|
+
(expression
|
|
93
|
+
(primary_expression
|
|
94
|
+
(identifier)))))))
|
|
95
|
+
(else
|
|
96
|
+
(body
|
|
97
|
+
(primary_expression
|
|
98
|
+
(fn_call
|
|
99
|
+
(identifier)
|
|
100
|
+
(argument_list
|
|
101
|
+
(expression
|
|
102
|
+
(primary_expression
|
|
103
|
+
(string
|
|
104
|
+
(string_start)
|
|
105
|
+
(string_content)
|
|
106
|
+
(string_end))))))))))))))))
|
tooling/tree-sitter-plum/test/corpus/literals.txt
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
Literals
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
main() =
|
|
6
|
+
startYear = 2101
|
|
7
|
+
a = +123
|
|
8
|
+
b = -111
|
|
9
|
+
c = 456
|
|
10
|
+
d = 0xcafe
|
|
11
|
+
e = 0b001
|
|
12
|
+
pi = 3.14159
|
|
13
|
+
a = +1.2
|
|
14
|
+
b = -0.4
|
|
15
|
+
c = 12.0f
|
|
16
|
+
d = 15.03f
|
|
17
|
+
name = "plum"
|
|
18
|
+
a = True
|
|
19
|
+
b = False
|
|
20
|
+
c = Nil
|
|
21
|
+
count = counter(10)
|
|
22
|
+
sum = 1 + {{2 * 3} / 4}
|
|
23
|
+
"e = {1 + 2}.mod(3).pow(2).sqrt()"
|
|
24
|
+
|
|
25
|
+
--------------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
(source
|
|
28
|
+
(fn
|
|
29
|
+
(fn_identifier)
|
|
30
|
+
(body
|
|
31
|
+
(assign
|
|
32
|
+
(identifier)
|
|
33
|
+
(expression
|
|
34
|
+
(primary_expression
|
|
35
|
+
(integer))))
|
|
36
|
+
(assign
|
|
37
|
+
(identifier)
|
|
38
|
+
(expression
|
|
39
|
+
(primary_expression
|
|
40
|
+
(unary_operator
|
|
41
|
+
(primary_expression
|
|
42
|
+
(integer))))))
|
|
43
|
+
(assign
|
|
44
|
+
(identifier)
|
|
45
|
+
(expression
|
|
46
|
+
(primary_expression
|
|
47
|
+
(unary_operator
|
|
48
|
+
(primary_expression
|
|
49
|
+
(integer))))))
|
|
50
|
+
(assign
|
|
51
|
+
(identifier)
|
|
52
|
+
(expression
|
|
53
|
+
(primary_expression
|
|
54
|
+
(integer))))
|
|
55
|
+
(assign
|
|
56
|
+
(identifier)
|
|
57
|
+
(expression
|
|
58
|
+
(primary_expression
|
|
59
|
+
(integer))))
|
|
60
|
+
(assign
|
|
61
|
+
(identifier)
|
|
62
|
+
(expression
|
|
63
|
+
(primary_expression
|
|
64
|
+
(integer))))
|
|
65
|
+
(primary_expression
|
|
66
|
+
(integer))
|
|
67
|
+
(assign
|
|
68
|
+
(identifier)
|
|
69
|
+
(expression
|
|
70
|
+
(primary_expression
|
|
71
|
+
(float))))
|
|
72
|
+
(assign
|
|
73
|
+
(identifier)
|
|
74
|
+
(expression
|
|
75
|
+
(primary_expression
|
|
76
|
+
(unary_operator
|
|
77
|
+
(primary_expression
|
|
78
|
+
(float))))))
|
|
79
|
+
(assign
|
|
80
|
+
(identifier)
|
|
81
|
+
(expression
|
|
82
|
+
(primary_expression
|
|
83
|
+
(unary_operator
|
|
84
|
+
(primary_expression
|
|
85
|
+
(float))))))
|
|
86
|
+
(assign
|
|
87
|
+
(identifier)
|
|
88
|
+
(expression
|
|
89
|
+
(primary_expression
|
|
90
|
+
(float))))
|
|
91
|
+
(assign
|
|
92
|
+
(identifier)
|
|
93
|
+
(expression
|
|
94
|
+
(primary_expression
|
|
95
|
+
(float))))
|
|
96
|
+
(assign
|
|
97
|
+
(identifier)
|
|
98
|
+
(expression
|
|
99
|
+
(primary_expression
|
|
100
|
+
(string
|
|
101
|
+
(string_start)
|
|
102
|
+
(string_content)
|
|
103
|
+
(string_end)))))
|
|
104
|
+
(assign
|
|
105
|
+
(identifier)
|
|
106
|
+
(expression
|
|
107
|
+
(primary_expression
|
|
108
|
+
(type_identifier))))
|
|
109
|
+
(assign
|
|
110
|
+
(identifier)
|
|
111
|
+
(expression
|
|
112
|
+
(primary_expression
|
|
113
|
+
(type_identifier))))
|
|
114
|
+
(assign
|
|
115
|
+
(identifier)
|
|
116
|
+
(expression
|
|
117
|
+
(primary_expression
|
|
118
|
+
(type_identifier))))
|
|
119
|
+
(assign
|
|
120
|
+
(identifier)
|
|
121
|
+
(expression
|
|
122
|
+
(primary_expression
|
|
123
|
+
(fn_call
|
|
124
|
+
(identifier)
|
|
125
|
+
(argument_list
|
|
126
|
+
(expression
|
|
127
|
+
(primary_expression
|
|
128
|
+
(integer))))))))
|
|
129
|
+
(assign
|
|
130
|
+
(identifier)
|
|
131
|
+
(expression
|
|
132
|
+
(primary_expression
|
|
133
|
+
(binary_operator
|
|
134
|
+
(primary_expression
|
|
135
|
+
(integer))
|
|
136
|
+
(primary_expression
|
|
137
|
+
(parenthesized_expression
|
|
138
|
+
(expression
|
|
139
|
+
(primary_expression
|
|
140
|
+
(binary_operator
|
|
141
|
+
(primary_expression
|
|
142
|
+
(parenthesized_expression
|
|
143
|
+
(expression
|
|
144
|
+
(primary_expression
|
|
145
|
+
(binary_operator
|
|
146
|
+
(primary_expression
|
|
147
|
+
(integer))
|
|
148
|
+
(primary_expression
|
|
149
|
+
(integer)))))))
|
|
150
|
+
(primary_expression
|
|
151
|
+
(integer)))))))))))
|
|
152
|
+
(primary_expression
|
|
153
|
+
(string
|
|
154
|
+
(string_start)
|
|
155
|
+
(string_content)
|
|
156
|
+
(string_end))))))
|
tooling/tree-sitter-plum/test/corpus/match.txt
CHANGED
|
@@ -1,24 +1,17 @@
|
|
|
1
1
|
================================================================================
|
|
2
|
-
|
|
2
|
+
match
|
|
3
3
|
================================================================================
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
main() =
|
|
6
|
-
val a = (1 * 5) + (2 + 3)
|
|
7
|
-
match a
|
|
6
|
+
match a
|
|
8
|
-
|
|
7
|
+
a < b =>
|
|
9
8
|
printLn(a != b)
|
|
10
|
-
}
|
|
11
|
-
|
|
9
|
+
a > 9 =>
|
|
12
10
|
printLn(a == 9)
|
|
13
|
-
}
|
|
14
|
-
|
|
11
|
+
a < 9 =>
|
|
15
12
|
printLn(b == 0)
|
|
16
|
-
}
|
|
17
|
-
|
|
13
|
+
_ =>
|
|
18
14
|
printLn(a == 9)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
15
|
|
|
23
16
|
--------------------------------------------------------------------------------
|
|
24
17
|
|
tooling/tree-sitter-plum/test/corpus/object.txt
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
================================================================================
|
|
2
|
-
object
|
|
3
|
-
================================================================================
|
|
4
|
-
|
|
5
|
-
object environment: ToStr {
|
|
6
|
-
val debug = false
|
|
7
|
-
val connUrl = "123"
|
|
8
|
-
override fn toStr() -> Str {
|
|
9
|
-
return "123"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
--------------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
(source
|
|
16
|
-
(test
|
|
17
|
-
(string
|
|
18
|
-
(string_start)
|
|
19
|
-
(string_end))
|
|
20
|
-
(lambda
|
|
21
|
-
(identifier)
|
|
22
|
-
(body
|
|
23
|
-
(assignment_statement
|
|
24
|
-
(identifier)
|
|
25
|
-
(binary_operator
|
|
26
|
-
(parenthesized_expression
|
|
27
|
-
(binary_operator
|
|
28
|
-
(integer)
|
|
29
|
-
(integer)))
|
|
30
|
-
(parenthesized_expression
|
|
31
|
-
(binary_operator
|
|
32
|
-
(integer)
|
|
33
|
-
(integer)))))
|
|
34
|
-
(if_statement
|
|
35
|
-
(comparison_operator
|
|
36
|
-
(identifier)
|
|
37
|
-
(identifier))
|
|
38
|
-
(block
|
|
39
|
-
(assert_statement
|
|
40
|
-
(comparison_operator
|
|
41
|
-
(identifier)
|
|
42
|
-
(identifier))))
|
|
43
|
-
(else_if_clause
|
|
44
|
-
(comparison_operator
|
|
45
|
-
(identifier)
|
|
46
|
-
(integer))
|
|
47
|
-
(block
|
|
48
|
-
(assert_statement
|
|
49
|
-
(comparison_operator
|
|
50
|
-
(identifier)
|
|
51
|
-
(integer)))))
|
|
52
|
-
(else_if_clause
|
|
53
|
-
(comparison_operator
|
|
54
|
-
(identifier)
|
|
55
|
-
(integer))
|
|
56
|
-
(block
|
|
57
|
-
(assert_statement
|
|
58
|
-
(comparison_operator
|
|
59
|
-
(identifier)
|
|
60
|
-
(integer)))))
|
|
61
|
-
(else_clause
|
|
62
|
-
(block
|
|
63
|
-
(assert_statement
|
|
64
|
-
(comparison_operator
|
|
65
|
-
(identifier)
|
|
66
|
-
(integer))))))))))
|
tooling/tree-sitter-plum/test/corpus/record.txt
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
================================================================================
|
|
2
|
-
record - simple
|
|
3
|
-
================================================================================
|
|
4
|
-
|
|
5
|
-
record Cat(name: Str, age: Int)
|
|
6
|
-
|
|
7
|
-
record Dog(
|
|
8
|
-
name: Str,
|
|
9
|
-
age: Int
|
|
10
|
-
)
|
|
11
|
-
|
|
12
|
-
--------------------------------------------------------------------------------
|
|
13
|
-
|
|
14
|
-
(source
|
|
15
|
-
(record
|
|
16
|
-
(typename)
|
|
17
|
-
(record_field
|
|
18
|
-
(identifier)
|
|
19
|
-
(type
|
|
20
|
-
(typename)))
|
|
21
|
-
(record_field
|
|
22
|
-
(identifier)
|
|
23
|
-
(type
|
|
24
|
-
(typename))))
|
|
25
|
-
(record
|
|
26
|
-
(typename)
|
|
27
|
-
(record_field
|
|
28
|
-
(identifier)
|
|
29
|
-
(type
|
|
30
|
-
(typename)))
|
|
31
|
-
(record_field
|
|
32
|
-
(identifier)
|
|
33
|
-
(type
|
|
34
|
-
(typename)))))
|
|
35
|
-
|
|
36
|
-
================================================================================
|
|
37
|
-
type - generic
|
|
38
|
-
================================================================================
|
|
39
|
-
|
|
40
|
-
record Dog<A, B>(
|
|
41
|
-
name: A,
|
|
42
|
-
age: B
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
record Dog<A: Compare + String, B>(
|
|
46
|
-
name: A,
|
|
47
|
-
age: B
|
|
48
|
-
)
|
|
49
|
-
--------------------------------------------------------------------------------
|
|
50
|
-
|
|
51
|
-
(source
|
|
52
|
-
(record
|
|
53
|
-
(typename)
|
|
54
|
-
(generics
|
|
55
|
-
(generic_type
|
|
56
|
-
(genericname))
|
|
57
|
-
(generic_type
|
|
58
|
-
(genericname)))
|
|
59
|
-
(record_field
|
|
60
|
-
(identifier)
|
|
61
|
-
(type
|
|
62
|
-
(typename)))
|
|
63
|
-
(record_field
|
|
64
|
-
(identifier)
|
|
65
|
-
(type
|
|
66
|
-
(typename))))
|
|
67
|
-
(record
|
|
68
|
-
(typename)
|
|
69
|
-
(generics
|
|
70
|
-
(generic_type
|
|
71
|
-
(genericname)
|
|
72
|
-
(typename)
|
|
73
|
-
(typename))
|
|
74
|
-
(generic_type
|
|
75
|
-
(genericname)))
|
|
76
|
-
(record_field
|
|
77
|
-
(identifier)
|
|
78
|
-
(type
|
|
79
|
-
(typename)))
|
|
80
|
-
(record_field
|
|
81
|
-
(identifier)
|
|
82
|
-
(type
|
|
83
|
-
(typename)))))
|
|
84
|
-
|
|
85
|
-
================================================================================
|
|
86
|
-
record - doc_comment
|
|
87
|
-
================================================================================
|
|
88
|
-
|
|
89
|
-
`A Cat is new a new type of animal
|
|
90
|
-
record Cat(name: Str, age: Int)
|
|
91
|
-
--------------------------------------------------------------------------------
|
|
92
|
-
|
|
93
|
-
(source
|
|
94
|
-
(record
|
|
95
|
-
(doc_comment)
|
|
96
|
-
(typename)
|
|
97
|
-
(record_field
|
|
98
|
-
(identifier)
|
|
99
|
-
(type
|
|
100
|
-
(typename)))
|
|
101
|
-
(record_field
|
|
102
|
-
(identifier)
|
|
103
|
-
(type
|
|
104
|
-
(typename)))))
|
|
105
|
-
|
|
106
|
-
================================================================================
|
|
107
|
-
record - implements
|
|
108
|
-
================================================================================
|
|
109
|
-
|
|
110
|
-
record Cat(
|
|
111
|
-
name: Option<Str>,
|
|
112
|
-
age: Int
|
|
113
|
-
): Stringable {
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
--------------------------------------------------------------------------------
|
|
118
|
-
|
|
119
|
-
(source
|
|
120
|
-
(record
|
|
121
|
-
(typename)
|
|
122
|
-
(record_field
|
|
123
|
-
(identifier)
|
|
124
|
-
(type
|
|
125
|
-
(typename)
|
|
126
|
-
(typename)))
|
|
127
|
-
(record_field
|
|
128
|
-
(identifier)
|
|
129
|
-
(type
|
|
130
|
-
(typename)))
|
|
131
|
-
(typename)))
|
|
132
|
-
|
|
133
|
-
================================================================================
|
|
134
|
-
record - methods
|
|
135
|
-
================================================================================
|
|
136
|
-
|
|
137
|
-
record Cat(
|
|
138
|
-
name: Str,
|
|
139
|
-
age: Int
|
|
140
|
-
) {
|
|
141
|
-
|
|
142
|
-
static fn withName(name: Str): Cat {
|
|
143
|
-
return Cat(name = name, age = 0)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
static fn withAge(age: Int): Cat {
|
|
147
|
-
return Cat(name = "", age = age)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
fn fullname(): Str {
|
|
151
|
-
return "${name} ${age}"
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
override fn toStr(): Str {
|
|
155
|
-
return "Cat<${fullname()}, ${age}>"
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
override fn plus(other: Cat): Cat {
|
|
159
|
-
return Cat(name = self.name, age = age)
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
--------------------------------------------------------------------------------
|
|
164
|
-
|
|
165
|
-
(source
|
|
166
|
-
(record
|
|
167
|
-
(typename)
|
|
168
|
-
(record_field
|
|
169
|
-
(identifier)
|
|
170
|
-
(type
|
|
171
|
-
(typename)))
|
|
172
|
-
(record_field
|
|
173
|
-
(identifier)
|
|
174
|
-
(type
|
|
175
|
-
(typename)))
|
|
176
|
-
(fn
|
|
177
|
-
(fn_modifier)
|
|
178
|
-
(fnname)
|
|
179
|
-
(param
|
|
180
|
-
(identifier)
|
|
181
|
-
(type
|
|
182
|
-
(typename)))
|
|
183
|
-
(return_type
|
|
184
|
-
(typename))
|
|
185
|
-
(body
|
|
186
|
-
(return
|
|
187
|
-
(expression
|
|
188
|
-
(primary_expression
|
|
189
|
-
(call
|
|
190
|
-
(reference
|
|
191
|
-
(typename))
|
|
192
|
-
(argument_list
|
|
193
|
-
(keyword_argument
|
|
194
|
-
(identifier)
|
|
195
|
-
(expression
|
|
196
|
-
(primary_expression
|
|
197
|
-
(identifier))))
|
|
198
|
-
(keyword_argument
|
|
199
|
-
(identifier)
|
|
200
|
-
(expression
|
|
201
|
-
(primary_expression
|
|
202
|
-
(integer)))))))))))
|
|
203
|
-
(fn
|
|
204
|
-
(fn_modifier)
|
|
205
|
-
(fnname)
|
|
206
|
-
(param
|
|
207
|
-
(identifier)
|
|
208
|
-
(type
|
|
209
|
-
(typename)))
|
|
210
|
-
(return_type
|
|
211
|
-
(typename))
|
|
212
|
-
(body
|
|
213
|
-
(return
|
|
214
|
-
(expression
|
|
215
|
-
(primary_expression
|
|
216
|
-
(call
|
|
217
|
-
(reference
|
|
218
|
-
(typename))
|
|
219
|
-
(argument_list
|
|
220
|
-
(keyword_argument
|
|
221
|
-
(identifier)
|
|
222
|
-
(expression
|
|
223
|
-
(primary_expression
|
|
224
|
-
(string))))
|
|
225
|
-
(keyword_argument
|
|
226
|
-
(identifier)
|
|
227
|
-
(expression
|
|
228
|
-
(primary_expression
|
|
229
|
-
(identifier)))))))))))
|
|
230
|
-
(fn
|
|
231
|
-
(fnname)
|
|
232
|
-
(return_type
|
|
233
|
-
(typename))
|
|
234
|
-
(body
|
|
235
|
-
(return
|
|
236
|
-
(expression
|
|
237
|
-
(primary_expression
|
|
238
|
-
(string
|
|
239
|
-
(quoted_content)))))))
|
|
240
|
-
(fn
|
|
241
|
-
(fn_modifier)
|
|
242
|
-
(fnname)
|
|
243
|
-
(return_type
|
|
244
|
-
(typename))
|
|
245
|
-
(body
|
|
246
|
-
(return
|
|
247
|
-
(expression
|
|
248
|
-
(primary_expression
|
|
249
|
-
(string
|
|
250
|
-
(quoted_content)))))))
|
|
251
|
-
(fn
|
|
252
|
-
(fn_modifier)
|
|
253
|
-
(fnname)
|
|
254
|
-
(param
|
|
255
|
-
(identifier)
|
|
256
|
-
(type
|
|
257
|
-
(typename)))
|
|
258
|
-
(return_type
|
|
259
|
-
(typename))
|
|
260
|
-
(body
|
|
261
|
-
(return
|
|
262
|
-
(expression
|
|
263
|
-
(primary_expression
|
|
264
|
-
(call
|
|
265
|
-
(reference
|
|
266
|
-
(typename))
|
|
267
|
-
(argument_list
|
|
268
|
-
(keyword_argument
|
|
269
|
-
(identifier)
|
|
270
|
-
(expression
|
|
271
|
-
(primary_expression
|
|
272
|
-
(attribute
|
|
273
|
-
(primary_expression
|
|
274
|
-
(self))
|
|
275
|
-
(identifier)))))
|
|
276
|
-
(keyword_argument
|
|
277
|
-
(identifier)
|
|
278
|
-
(expression
|
|
279
|
-
(primary_expression
|
|
280
|
-
(identifier)))))))))))))
|
tooling/tree-sitter-plum/test/corpus/trait.txt
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
================================================================================
|
|
2
|
-
trait
|
|
3
|
-
================================================================================
|
|
4
|
-
|
|
5
|
-
trait Comparable[A] {
|
|
6
|
-
fn compare(left: A, right: A): Bool
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
trait Stringable {
|
|
10
|
-
fn toStr(): Str
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
--------------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
(source
|
|
16
|
-
(trait
|
|
17
|
-
(typename)
|
|
18
|
-
(generics
|
|
19
|
-
(generic_type
|
|
20
|
-
(genericname)))
|
|
21
|
-
(trait_field
|
|
22
|
-
(identifier)
|
|
23
|
-
(param
|
|
24
|
-
(identifier)
|
|
25
|
-
(type
|
|
26
|
-
(typename)))
|
|
27
|
-
(param
|
|
28
|
-
(identifier)
|
|
29
|
-
(type
|
|
30
|
-
(typename)))
|
|
31
|
-
(return_type
|
|
32
|
-
(typename))))
|
|
33
|
-
(trait
|
|
34
|
-
(typename)
|
|
35
|
-
(trait_field
|
|
36
|
-
(identifier)
|
|
37
|
-
(return_type
|
|
38
|
-
(typename)))))
|
tooling/tree-sitter-plum/test/corpus/type.txt
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
type - definition
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
Cat : ToStr = {
|
|
6
|
+
name: Str
|
|
7
|
+
age: Int
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Dog = {
|
|
11
|
+
name: a
|
|
12
|
+
age: b
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Dog(a: Compare + String, b) = {
|
|
16
|
+
name: a
|
|
17
|
+
age: b
|
|
18
|
+
}
|
|
19
|
+
--------------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
(source
|
|
22
|
+
(record
|
|
23
|
+
(type_identifier)
|
|
24
|
+
(type_identifier)
|
|
25
|
+
(record_field
|
|
26
|
+
(identifier)
|
|
27
|
+
(type
|
|
28
|
+
(type_identifier)))
|
|
29
|
+
(record_field
|
|
30
|
+
(identifier)
|
|
31
|
+
(type
|
|
32
|
+
(type_identifier))))
|
|
33
|
+
(record
|
|
34
|
+
(type_identifier)
|
|
35
|
+
(record_field
|
|
36
|
+
(identifier)
|
|
37
|
+
(type
|
|
38
|
+
(a)))
|
|
39
|
+
(record_field
|
|
40
|
+
(identifier)
|
|
41
|
+
(type
|
|
42
|
+
(b))))
|
|
43
|
+
(record
|
|
44
|
+
(type_identifier)
|
|
45
|
+
(generics
|
|
46
|
+
(a)
|
|
47
|
+
(type_identifier)
|
|
48
|
+
(type_identifier)
|
|
49
|
+
(b))
|
|
50
|
+
(record_field
|
|
51
|
+
(identifier)
|
|
52
|
+
(type
|
|
53
|
+
(a)))
|
|
54
|
+
(record_field
|
|
55
|
+
(identifier)
|
|
56
|
+
(type
|
|
57
|
+
(b)))))
|
|
58
|
+
|
|
59
|
+
================================================================================
|
|
60
|
+
type - methods
|
|
61
|
+
================================================================================
|
|
62
|
+
|
|
63
|
+
Cat : ToStr = {
|
|
64
|
+
name: Str
|
|
65
|
+
age: Int
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Cat\withName(name: Str) -> Cat =
|
|
69
|
+
Cat(name = name, age = 0)
|
|
70
|
+
|
|
71
|
+
Cat\withAge(age: Int) -> Cat =
|
|
72
|
+
Cat(name = "", age = age)
|
|
73
|
+
|
|
74
|
+
Cat\fullname() -> Str =
|
|
75
|
+
"${name} ${age}"
|
|
76
|
+
|
|
77
|
+
Cat\toStr() -> Str =
|
|
78
|
+
"Cat<{fullname()}, {age}>"
|
|
79
|
+
|
|
80
|
+
--------------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
(source
|
|
83
|
+
(record
|
|
84
|
+
(type_identifier)
|
|
85
|
+
(type_identifier)
|
|
86
|
+
(record_field
|
|
87
|
+
(identifier)
|
|
88
|
+
(type
|
|
89
|
+
(type_identifier)))
|
|
90
|
+
(record_field
|
|
91
|
+
(identifier)
|
|
92
|
+
(type
|
|
93
|
+
(type_identifier))))
|
|
94
|
+
(fn
|
|
95
|
+
(method_identifier
|
|
96
|
+
(type_identifier)
|
|
97
|
+
(fn_identifier))
|
|
98
|
+
(param
|
|
99
|
+
(identifier)
|
|
100
|
+
(type
|
|
101
|
+
(type_identifier)))
|
|
102
|
+
(return_type
|
|
103
|
+
(type_identifier))
|
|
104
|
+
(body
|
|
105
|
+
(primary_expression
|
|
106
|
+
(type_call
|
|
107
|
+
(type_identifier)
|
|
108
|
+
(argument_list
|
|
109
|
+
(keyword_argument
|
|
110
|
+
(identifier)
|
|
111
|
+
(expression
|
|
112
|
+
(primary_expression
|
|
113
|
+
(identifier))))
|
|
114
|
+
(keyword_argument
|
|
115
|
+
(identifier)
|
|
116
|
+
(expression
|
|
117
|
+
(primary_expression
|
|
118
|
+
(integer)))))))))
|
|
119
|
+
(fn
|
|
120
|
+
(method_identifier
|
|
121
|
+
(type_identifier)
|
|
122
|
+
(fn_identifier))
|
|
123
|
+
(param
|
|
124
|
+
(identifier)
|
|
125
|
+
(type
|
|
126
|
+
(type_identifier)))
|
|
127
|
+
(return_type
|
|
128
|
+
(type_identifier))
|
|
129
|
+
(body
|
|
130
|
+
(primary_expression
|
|
131
|
+
(type_call
|
|
132
|
+
(type_identifier)
|
|
133
|
+
(argument_list
|
|
134
|
+
(keyword_argument
|
|
135
|
+
(identifier)
|
|
136
|
+
(expression
|
|
137
|
+
(primary_expression
|
|
138
|
+
(string
|
|
139
|
+
(string_start)
|
|
140
|
+
(string_end)))))
|
|
141
|
+
(keyword_argument
|
|
142
|
+
(identifier)
|
|
143
|
+
(expression
|
|
144
|
+
(primary_expression
|
|
145
|
+
(identifier)))))))))
|
|
146
|
+
(fn
|
|
147
|
+
(method_identifier
|
|
148
|
+
(type_identifier)
|
|
149
|
+
(fn_identifier))
|
|
150
|
+
(return_type
|
|
151
|
+
(type_identifier))
|
|
152
|
+
(body
|
|
153
|
+
(primary_expression
|
|
154
|
+
(string
|
|
155
|
+
(string_start)
|
|
156
|
+
(string_content)
|
|
157
|
+
(string_end)))))
|
|
158
|
+
(fn
|
|
159
|
+
(method_identifier
|
|
160
|
+
(type_identifier)
|
|
161
|
+
(fn_identifier))
|
|
162
|
+
(return_type
|
|
163
|
+
(type_identifier))
|
|
164
|
+
(body
|
|
165
|
+
(primary_expression
|
|
166
|
+
(string
|
|
167
|
+
(string_start)
|
|
168
|
+
(string_content)
|
|
169
|
+
(string_end))))))
|