plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


ddac811 — pyrossh 2024-01-05T10:04:33+05:30
langium

Generated files not shown: package-lock.json, src/parser.c

Files changed (59) hide show
  1. .eslintrc.json +13 -0
  2. .gitattributes +0 -2
  3. .github/workflows/ci.yml +0 -22
  4. .gitignore +11 -7
  5. .npmignore +0 -6
  6. .vscode/extensions.json +9 -0
  7. .vscode/launch.json +36 -0
  8. .vscode/tasks.json +21 -0
  9. .vscodeignore +4 -0
  10. Cargo.toml +0 -26
  11. bin/cli.js +4 -0
  12. binding.gyp +0 -19
  13. bindings/node/binding.cc +0 -28
  14. bindings/node/index.js +0 -19
  15. bindings/rust/README.md +0 -36
  16. bindings/rust/build.rs +0 -35
  17. bindings/rust/lib.rs +0 -54
  18. esbuild.mjs +54 -0
  19. example/sample.palm +184 -0
  20. grammar.js +0 -445
  21. index.html +22 -0
  22. langium-config.json +15 -0
  23. langium-quickstart.md +40 -0
  24. language-configuration.json +30 -0
  25. package.json +78 -31
  26. queries/highlights.scm +0 -102
  27. queries/locals.scm +0 -15
  28. queries/tags.scm +0 -41
  29. readme.md +0 -315
  30. sample.palm +0 -168
  31. scripts/bundle.js +21 -0
  32. scripts/prepare.js +20 -0
  33. spec.gleam +0 -198
  34. src/cli/cli-util.ts +51 -0
  35. src/cli/generator.ts +20 -0
  36. src/cli/main.ts +42 -0
  37. src/extension/main.ts +58 -0
  38. src/grammar.json +0 -3570
  39. src/language/main-browser.ts +14 -0
  40. src/language/main.ts +13 -0
  41. src/language/palm-module.ts +63 -0
  42. src/language/palm-validator.ts +32 -0
  43. src/language/palm.langium +109 -0
  44. src/node-types.json +0 -2488
  45. src/scanner.c +0 -29
  46. src/tree_sitter/parser.h +0 -224
  47. static/monacoClassic.html +28 -0
  48. static/monacoExtended.html +28 -0
  49. static/setup.js +18 -0
  50. static/setupClassic.js +32 -0
  51. static/setupExtended.js +62 -0
  52. static/styles.css +28 -0
  53. test/corpus/expressions.txt +0 -140
  54. test/corpus/functions.txt +0 -85
  55. test/corpus/statements.txt +0 -257
  56. test/corpus/types.txt +0 -129
  57. tsconfig.json +24 -0
  58. tsconfig.monarch.json +20 -0
  59. vite.bundle.config.ts +26 -0
.eslintrc.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "root": true,
3
+ "parser": "@typescript-eslint/parser",
4
+ "parserOptions": {
5
+ "ecmaVersion": 6,
6
+ "sourceType": "module"
7
+ },
8
+ "plugins": [
9
+ "@typescript-eslint"
10
+ ],
11
+ "rules": {
12
+ }
13
+ }
.gitattributes DELETED
@@ -1,2 +0,0 @@
1
- /src/** linguist-vendored
2
- /examples/* linguist-vendored
.github/workflows/ci.yml DELETED
@@ -1,22 +0,0 @@
1
- name: Build/test
2
- on:
3
- pull_request:
4
- branches:
5
- - "**"
6
- push:
7
- branches:
8
- - "master"
9
- jobs:
10
- test:
11
- runs-on: ${{ matrix.os }}
12
- strategy:
13
- fail-fast: true
14
- matrix:
15
- os: [macos-latest, ubuntu-latest]
16
- steps:
17
- - uses: actions/checkout@v2
18
- - uses: actions/setup-node@v2
19
- with:
20
- node-version: 18
21
- - run: npm install
22
- - run: npm test
.gitignore CHANGED
@@ -1,7 +1,11 @@
1
- Cargo.lock
1
+ .vscode/*
2
+ !.vscode/extensions.json
2
- package-lock.json
3
+ !.vscode/launch.json
4
+ !.vscode/tasks.json
3
- node_modules
5
+ node_modules/
4
- build
6
+ out/
5
- *.log
6
- /examples/*/
7
+ src/language/generated/
8
+ static/bundle/
9
+ static/monaco-editor-workers/
7
- /target/
10
+ static/worker/
11
+ syntaxes/
.npmignore DELETED
@@ -1,6 +0,0 @@
1
- corpus
2
- examples
3
- build
4
- script
5
- target
6
- bindings/rust
.vscode/extensions.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
3
+ // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
4
+
5
+ // List of extensions which should be recommended for users of this workspace.
6
+ "recommendations": [
7
+ "langium.langium-vscode"
8
+ ]
9
+ }
.vscode/launch.json ADDED
@@ -0,0 +1,36 @@
1
+ // A launch configuration that launches the extension inside a new window
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ {
6
+ "version": "0.2.0",
7
+ "configurations": [
8
+ {
9
+ "name": "Run Extension",
10
+ "type": "extensionHost",
11
+ "request": "launch",
12
+ "args": [
13
+ "${workspaceFolder}/example",
14
+ "--extensionDevelopmentPath=${workspaceFolder}"
15
+ ],
16
+ "sourceMaps": true,
17
+ "outFiles": [
18
+ "${workspaceFolder}/out/**/*.js"
19
+ ]
20
+ },
21
+ {
22
+ "name": "Attach to Language Server",
23
+ "type": "node",
24
+ "port": 6009,
25
+ "request": "attach",
26
+ "skipFiles": [
27
+ "<node_internals>/**"
28
+ ],
29
+ "sourceMaps": true,
30
+ "outFiles": [
31
+ "${workspaceFolder}/out/**/*.js",
32
+ "${workspaceFolder}/node_modules/langium"
33
+ ]
34
+ }
35
+ ]
36
+ }
.vscode/tasks.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
3
+ // for the documentation about the tasks.json format
4
+ "version": "2.0.0",
5
+ "tasks": [
6
+ {
7
+ "label": "Build palm",
8
+ "command": "npm run langium:generate && npm run build",
9
+ "type": "shell",
10
+ "group": {
11
+ "kind": "build",
12
+ "isDefault": true
13
+ },
14
+ "detail": "Langium: Generate grammar and build the palm language",
15
+ "icon": {
16
+ "color": "terminal.ansiGreen",
17
+ "id": "server-process"
18
+ }
19
+ }
20
+ ]
21
+ }
.vscodeignore ADDED
@@ -0,0 +1,4 @@
1
+ .vscode/**
2
+ .vscode-test/**
3
+ .gitignore
4
+ langium-quickstart.md
Cargo.toml DELETED
@@ -1,26 +0,0 @@
1
- [package]
2
- name = "tree-sitter-palm"
3
- description = "palm grammar for the tree-sitter parsing library"
4
- version = "0.1.0"
5
- keywords = ["incremental", "parsing", "palm"]
6
- categories = ["parsing", "text-editors"]
7
- repository = "https://github.com/pyrossh/tree-sitter-palm"
8
- edition = "2018"
9
- license = "MIT"
10
-
11
- build = "bindings/rust/build.rs"
12
- include = [
13
- "bindings/rust/*",
14
- "grammar.js",
15
- "queries/*",
16
- "src/*",
17
- ]
18
-
19
- [lib]
20
- path = "bindings/rust/lib.rs"
21
-
22
- [dependencies]
23
- tree-sitter = "~0.20"
24
-
25
- [build-dependencies]
26
- cc = "1.0"
bin/cli.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+
3
+ import main from '../out/cli/main.js';
4
+ main();
binding.gyp DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "targets": [
3
- {
4
- "target_name": "tree_sitter_palm_binding",
5
- "include_dirs": [
6
- "<!(node -e \"require('nan')\")",
7
- "src"
8
- ],
9
- "sources": [
10
- "bindings/node/binding.cc",
11
- "src/parser.c",
12
- "src/scanner.c"
13
- ],
14
- "cflags_c": [
15
- "-std=c99",
16
- ]
17
- }
18
- ]
19
- }
bindings/node/binding.cc DELETED
@@ -1,28 +0,0 @@
1
- #include "tree_sitter/parser.h"
2
- #include <node.h>
3
- #include "nan.h"
4
-
5
- using namespace v8;
6
-
7
- extern "C" TSLanguage * tree_sitter_palm();
8
-
9
- namespace {
10
-
11
- NAN_METHOD(New) {}
12
-
13
- void Init(Local<Object> exports, Local<Object> module) {
14
- Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15
- tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
17
-
18
- Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19
- Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
20
- Nan::SetInternalFieldPointer(instance, 0, tree_sitter_palm());
21
-
22
- Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("palm").ToLocalChecked());
23
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
24
- }
25
-
26
- NODE_MODULE(tree_sitter_palm_binding, Init)
27
-
28
- } // namespace
bindings/node/index.js DELETED
@@ -1,19 +0,0 @@
1
- try {
2
- module.exports = require("../../build/Release/tree_sitter_palm_binding");
3
- } catch (error1) {
4
- if (error1.code !== 'MODULE_NOT_FOUND') {
5
- throw error1;
6
- }
7
- try {
8
- module.exports = require("../../build/Debug/tree_sitter_palm_binding");
9
- } catch (error2) {
10
- if (error2.code !== 'MODULE_NOT_FOUND') {
11
- throw error2;
12
- }
13
- throw error1
14
- }
15
- }
16
-
17
- try {
18
- module.exports.nodeTypeInfo = require("../../src/node-types.json");
19
- } catch (_) {}
bindings/rust/README.md DELETED
@@ -1,36 +0,0 @@
1
- # tree-sitter-python
2
-
3
- This crate provides a Python grammar for the [tree-sitter][] parsing library.
4
- To use this crate, add it to the `[dependencies]` section of your `Cargo.toml`
5
- file. (Note that you will probably also need to depend on the
6
- [`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful
7
- way.)
8
-
9
- ``` toml
10
- [dependencies]
11
- tree-sitter = "0.17"
12
- tree-sitter-python = "0.17"
13
- ```
14
-
15
- Typically, you will use the [language][language func] function to add this
16
- grammar to a tree-sitter [Parser][], and then use the parser to parse some code:
17
-
18
- ``` rust
19
- let code = r#"
20
- def double(x):
21
- return x * 2
22
- "#;
23
- let mut parser = Parser::new();
24
- parser.set_language(tree_sitter_python::language()).expect("Error loading Python grammar");
25
- let parsed = parser.parse(code, None);
26
- ```
27
-
28
- If you have any questions, please reach out to us in the [tree-sitter
29
- discussions] page.
30
-
31
- [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
32
- [language func]: https://docs.rs/tree-sitter-python/*/tree_sitter_python/fn.language.html
33
- [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
34
- [tree-sitter]: https://tree-sitter.github.io/
35
- [tree-sitter crate]: https://crates.io/crates/tree-sitter
36
- [tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions
bindings/rust/build.rs DELETED
@@ -1,35 +0,0 @@
1
- fn main() {
2
- let src_dir = std::path::Path::new("src");
3
-
4
- let mut c_config = cc::Build::new();
5
- c_config.include(&src_dir);
6
- c_config
7
- .flag_if_supported("-Wno-unused-parameter")
8
- .flag_if_supported("-Wno-unused-but-set-variable")
9
- .flag_if_supported("-Wno-trigraphs");
10
- let parser_path = src_dir.join("parser.c");
11
- c_config.file(&parser_path);
12
-
13
- let scanner_path = src_dir.join("scanner.c");
14
- c_config.file(&scanner_path);
15
- println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
16
-
17
- c_config.compile("parser");
18
- println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
19
-
20
- // If your language uses an external scanner written in C++,
21
- // then include this block of code:
22
-
23
- /*
24
- let mut cpp_config = cc::Build::new();
25
- cpp_config.cpp(true);
26
- cpp_config.include(&src_dir);
27
- cpp_config
28
- .flag_if_supported("-Wno-unused-parameter")
29
- .flag_if_supported("-Wno-unused-but-set-variable");
30
- let scanner_path = src_dir.join("scanner.cc");
31
- cpp_config.file(&scanner_path);
32
- cpp_config.compile("scanner");
33
- println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
34
- */
35
- }
bindings/rust/lib.rs DELETED
@@ -1,54 +0,0 @@
1
- //! This crate provides palm language support for the [tree-sitter][] parsing library.
2
- //!
3
- //! Typically, you will use the [language][language func] function to add this language to a
4
- //! tree-sitter [Parser][], and then use the parser to parse some code:
5
- //!
6
- //! ```
7
- //! let code = "";
8
- //! let mut parser = tree_sitter::Parser::new();
9
- //! parser.set_language(tree_sitter_palm::language()).expect("Error loading palm grammar");
10
- //! let tree = parser.parse(code, None).unwrap();
11
- //! ```
12
- //!
13
- //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
14
- //! [language func]: fn.language.html
15
- //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
16
- //! [tree-sitter]: https://tree-sitter.github.io/
17
-
18
- use tree_sitter::Language;
19
-
20
- extern "C" {
21
- fn tree_sitter_palm() -> Language;
22
- }
23
-
24
- /// Returns the tree-sitter [Language][] for this grammar.
25
- ///
26
- /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
27
- pub fn language() -> Language {
28
- unsafe { tree_sitter_palm() }
29
- }
30
-
31
- /// The source of the palm tree-sitter grammar description.
32
- pub const GRAMMAR: &'static str = include_str!("../../grammar.js");
33
-
34
- /// The syntax highlighting query for this language.
35
- pub const HIGHLIGHT_QUERY: &'static str = include_str!("../../queries/highlights.scm");
36
-
37
- /// The content of the [`node-types.json`][] file for this grammar.
38
- ///
39
- /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
40
- pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
41
-
42
- /// The symbol tagging query for this language.
43
- pub const TAGGING_QUERY: &'static str = include_str!("../../queries/tags.scm");
44
-
45
- #[cfg(test)]
46
- mod tests {
47
- #[test]
48
- fn can_load_grammar() {
49
- let mut parser = tree_sitter::Parser::new();
50
- parser
51
- .set_language(super::language())
52
- .expect("Error loading palm grammar");
53
- }
54
- }
esbuild.mjs ADDED
@@ -0,0 +1,54 @@
1
+ //@ts-check
2
+ import * as esbuild from 'esbuild';
3
+
4
+ const watch = process.argv.includes('--watch');
5
+ const minify = process.argv.includes('--minify');
6
+
7
+ const success = watch ? 'Watch build succeeded' : 'Build succeeded';
8
+
9
+ function getTime() {
10
+ const date = new Date();
11
+ return `[${`${padZeroes(date.getHours())}:${padZeroes(date.getMinutes())}:${padZeroes(date.getSeconds())}`}] `;
12
+ }
13
+
14
+ function padZeroes(i) {
15
+ return i.toString().padStart(2, '0');
16
+ }
17
+
18
+ const plugins = [{
19
+ name: 'watch-plugin',
20
+ setup(build) {
21
+ build.onEnd(result => {
22
+ if (result.errors.length === 0) {
23
+ console.log(getTime() + success);
24
+ }
25
+ });
26
+ },
27
+ }];
28
+
29
+ const ctx = await esbuild.context({
30
+ // Entry points for the vscode extension and the language server
31
+ entryPoints: ['src/extension/main.ts', 'src/language/main.ts'],
32
+ outdir: 'out',
33
+ bundle: true,
34
+ target: "ES2017",
35
+ // VSCode's extension host is still using cjs, so we need to transform the code
36
+ format: 'cjs',
37
+ // To prevent confusing node, we explicitly use the `.cjs` extension
38
+ outExtension: {
39
+ '.js': '.cjs'
40
+ },
41
+ loader: { '.ts': 'ts' },
42
+ external: ['vscode'],
43
+ platform: 'node',
44
+ sourcemap: !minify,
45
+ minify,
46
+ plugins
47
+ });
48
+
49
+ if (watch) {
50
+ await ctx.watch();
51
+ } else {
52
+ await ctx.rebuild();
53
+ ctx.dispose();
54
+ }
example/sample.palm ADDED
@@ -0,0 +1,184 @@
1
+ module palm
2
+
3
+ // [] for arrays []int []string
4
+ // {} for maps {int}int {string}string
5
+ // ? for optional int? string?
6
+ // ! for error types int!, string!
7
+ // nil
8
+
9
+ // match a {
10
+ // 1, 2, 3 => 0,
11
+ // 5...100 => 1,
12
+ // else => 9,
13
+ // _ => 10
14
+ // }
15
+
16
+ primitive str {
17
+ }
18
+
19
+ primitive int {
20
+ fn add() {
21
+ }
22
+ fn sub() {
23
+ }
24
+ fn minus() {
25
+ }
26
+ }
27
+
28
+ primitive float {
29
+ fn add() {
30
+ }
31
+ fn sub() {
32
+ }
33
+ fn minus() {
34
+ }
35
+ }
36
+
37
+ entity decimal {
38
+ mantissa: int
39
+ exponent: float
40
+ }
41
+
42
+ fn println() -> bool? {
43
+ }
44
+
45
+ // value Email(str) {
46
+ // fn parse() {
47
+
48
+ // }
49
+ // }
50
+
51
+ entity Cat<a> {
52
+ first_name: str
53
+ middle_name: str
54
+ last_name: str
55
+
56
+ fn is_equal(other: bool) -> bool {
57
+ const dest = "123"
58
+ println("123")
59
+ // return this == other
60
+ }
61
+ }
62
+
63
+ extension CatExtn on Cat<a> {
64
+ fn fullname() {
65
+ // return "first_name $middle_name $lastname"
66
+ }
67
+ }
68
+
69
+ trait IO {
70
+ fn read()
71
+ fn write()
72
+ }
73
+
74
+ // entity EdgeInsets {
75
+ // top, left, bottom, right: float
76
+
77
+ // // static fn symmetric(horizontal: double = 0, vertical: double = 0) {
78
+ // // return EdgeInsets(left = horizontal, right = horizontal, top = vertical, bottom = vertical)
79
+ // // }
80
+
81
+ // // static fn only(top: double = 0, left: double = 0, bottom: double = 0, right: double = 0) {
82
+ // // return EdgeInsets(top, left, bottom, right)
83
+ // // }
84
+ // }
85
+
86
+ enum bool {
87
+ false
88
+ true
89
+
90
+ fn is_equal(other: bool) -> bool {
91
+ // return this == other
92
+ }
93
+
94
+ fn to_string() -> str {
95
+ println("123")
96
+ println(1 + 2 + 4 + 5.33 + 7.8km)
97
+ }
98
+ }
99
+
100
+ enum Color {
101
+ red
102
+ green
103
+ blue
104
+
105
+ fn log() {
106
+ println("log")
107
+ }
108
+
109
+ fn to_string() -> str {
110
+ println("ToString")
111
+ }
112
+
113
+ fn where_is() -> int {
114
+ // match a {
115
+ // 1, 2, 3 => 0,
116
+ // 5...100 => 1,
117
+ // else => 9,
118
+ // _ => 10
119
+ // }
120
+ }
121
+ }
122
+
123
+
124
+ // repeat(10) |i| {
125
+ // println(i)
126
+ // }
127
+
128
+ // range(10, 20) |i| {
129
+ // println(i)
130
+ // }
131
+
132
+ // fn decrement() {
133
+ // println("decrementing")
134
+ // Cat(...c, age: c.age + 1)
135
+ // }
136
+
137
+ // fn add(x: Int, y: Int) -> Int {
138
+ // x + y
139
+ // }
140
+
141
+ // list
142
+ // .map(|it| it + 1)
143
+ // .each(|_| println("it", it))
144
+
145
+ // test "enum ordinal value" {
146
+ // expect(Value.zero).to_equal(0);
147
+ // expect(Value.one).to_equal(1);
148
+ // expect(Value.two).to_equal(2);
149
+ // }
150
+
151
+ // test("enum ordinal value") |t| {
152
+ // expect(Value.zero).to_equal(0);
153
+ // expect(Value.one).to_equal(1);
154
+ // expect(Value.two).to_equal(2);
155
+ // }
156
+
157
+ // group("Group 1") |g| {
158
+ // test("Test 1") |t| {
159
+
160
+ // }
161
+ // }
162
+
163
+ // bench("1231") |t, n| {
164
+ // }
165
+
166
+ // tree = {
167
+ // value: "Fred",
168
+ // left: {
169
+ // value: "Jim",
170
+ // },
171
+ // right: {
172
+ // value: "Shiela",
173
+ // left: {
174
+ // value: "Alice",
175
+ // },
176
+ // right: {
177
+ // value: "Bob"
178
+ // },
179
+ // },
180
+ // }
181
+
182
+ // Node "Fred" (Node "Jim" Leaf Leaf)
183
+ // (Node "Sheila" (Node "Alice" Leaf Leaf)
184
+ // (Node "Bob" Leaf Leaf))
grammar.js DELETED
@@ -1,445 +0,0 @@
1
- const NEWLINE = /\r?\n/;
2
-
3
- module.exports = grammar({
4
- name: "palm",
5
- extras: ($) => [
6
- NEWLINE,
7
- /\s/,
8
- $.module_comment,
9
- $.statement_comment,
10
- $.comment,
11
- ],
12
- externals: ($) => [$.quoted_content],
13
- rules: {
14
- source_file: ($) =>
15
- seq($.module, repeat($.import), repeat(choice($.struct, $.enum, $.function, $.const))),
16
-
17
- module: ($) => seq("module", field("module", $.module_name)),
18
-
19
- /* Comments */
20
- module_comment: ($) => token(seq("////", /.*/)),
21
- statement_comment: ($) => token(seq("///", /.*/)),
22
- comment: ($) => token(seq("//", /.*/)),
23
-
24
- /* Import _statement_seq */
25
- import: ($) =>
26
- seq(
27
- "import",
28
- field("module", $.module_name),
29
- optional(seq(".", field("imports", $.unqualified_imports))),
30
- optional(seq("as", field("alias", $.identifier)))
31
- ),
32
- module_name: ($) => seq($._name, repeat(seq("/", $._name))),
33
- unqualified_imports: ($) =>
34
- seq("{", optional(series_of($.unqualified_import, ",")), "}"),
35
- unqualified_import: ($) =>
36
- choice(
37
- seq(
38
- field("name", $.identifier),
39
- optional(seq("as", field("alias", $.identifier)))
40
- ),
41
- seq(
42
- field("name", $.type_identifier),
43
- optional(seq("as", field("alias", $.type_identifier)))
44
- )
45
- ),
46
-
47
- /* Constant _statement_seq */
48
- // _constant_type_annotation: ($) => seq(":", field("type", $._constant_type)),
49
-
50
- /* Declarations */
51
-
52
- struct: ($) =>
53
- seq(
54
- optional($.visibility_modifier),
55
- "type",
56
- field("name", $.type_identifier),
57
- field("generics", optional($.generics)),
58
- field("fields", seq("(", repeat($.field), ")")),
59
- ),
60
-
61
- enum: ($) =>
62
- seq(
63
- optional($.visibility_modifier),
64
- "type",
65
- field("name", $.type_identifier),
66
- field("generics", optional($.generics)),
67
- field("fields", seq(
68
- "{",
69
- repeat(
70
- seq(
71
- field("name", $.type_identifier),
72
- optional(seq(
73
- "(",
74
- choice(
75
- series_of($.identifier, ","),
76
- series_of($.field, ","),
77
- ),
78
- ")"),
79
- ),
80
- ),
81
- ),
82
- "}"
83
- ))
84
- ),
85
-
86
- function: ($) =>
87
- seq(
88
- optional($.visibility_modifier),
89
- "fn",
90
- field("name", $.identifier),
91
- field("params", seq("(", optional(series_of($.field, ",")), ")")),
92
- field("return", optional($.return_type)),
93
- field("body", seq("{", $._statement_seq, "}"))
94
- ),
95
-
96
- const: ($) => seq(
97
- "const",
98
- $.identifier,
99
- "=",
100
- field("value", $._const_expression)
101
- ),
102
- _const_expression: ($) => choice($._const_expression_unit, $.const_binary_expression),
103
- const_binary_expression: ($) => arithmeticExpression($._const_expression),
104
- _const_expression_unit: ($) =>
105
- choice(
106
- $.string,
107
- $.integer,
108
- $.float,
109
- $.const_record,
110
- $.const_function_call,
111
- ),
112
-
113
- const_record: ($) =>
114
- seq(
115
- field("name", choice($.constructor_name, $.remote_constructor_name)),
116
- optional(field("arguments", $.arguments))
117
- ),
118
-
119
- const_function_call: ($) =>
120
- seq(
121
- field("function", choice($.function_name, $.remote_function_identifier)),
122
- field("arguments", $.const_arguments)
123
- ),
124
-
125
- const_arguments: ($) => seq("(", optional(series_of($.const_argument, ",")), ")"),
126
- const_argument: ($) =>
127
- seq(
128
- optional(seq(field("label", $.label), ":")),
129
- field("value", $._const_expression)),
130
-
131
- /* Expressions */
132
-
133
- _name_param: ($) => field("name", $.identifier),
134
- _statement_seq: ($) => repeat1($._statement),
135
- _statement: ($) => choice($._expression, $.let),
136
- _expression: ($) => choice($._expression_unit, $.binary_expression),
137
- binary_expression: ($) => choice(
138
- binaryExpr(prec.left, 1, "||", $._expression),
139
- binaryExpr(prec.left, 2, "&&", $._expression),
140
- binaryExpr(prec.left, 3, "==", $._expression),
141
- binaryExpr(prec.left, 3, "!=", $._expression),
142
- binaryExpr(prec.left, 4, "<", $._expression),
143
- binaryExpr(prec.left, 4, "<=", $._expression),
144
- binaryExpr(prec.left, 4, ">", $._expression),
145
- binaryExpr(prec.left, 4, ">=", $._expression),
146
- binaryExpr(prec.left, 5, "|>", $._expression),
147
- binaryExpr(prec.left, 6, "+", $._expression),
148
- binaryExpr(prec.left, 6, "-", $._expression),
149
- binaryExpr(prec.left, 7, "*", $._expression),
150
- binaryExpr(prec.left, 7, "/", $._expression),
151
- binaryExpr(prec.left, 7, "%", $._expression),
152
- binaryExpr(prec.left, 7, "<>", $._expression)
153
- ),
154
- _expression_unit: ($) =>
155
- choice(
156
- $.string,
157
- $.integer,
158
- $.float,
159
- $.record,
160
- // $.todo,
161
- // $.panic,
162
- // $.list,
163
- $.identifier,
164
- $.anonymous_function,
165
- $.expression_group,
166
- $.if,
167
- $.when,
168
- // $.assert,
169
- $.negation,
170
- $.record_update,
171
- $.field_access,
172
- $.function_call
173
- ),
174
- record: ($) =>
175
- seq(
176
- field("name", $.constructor_name),
177
- optional(field("arguments", $.arguments))
178
- ),
179
- list: ($) =>
180
- seq(
181
- "[",
182
- optional(
183
- seq(
184
- $._expression,
185
- optional(repeat(seq(",", $._expression))),
186
- optional(","),
187
- optional(seq("..", field("spread", $._expression)))
188
- )
189
- ),
190
- "]"
191
- ),
192
- anonymous_function: ($) =>
193
- seq(
194
- "fn",
195
- field(
196
- "parameters",
197
- alias($.anonymous_function_parameters, $.function_parameters)
198
- ),
199
- optional(seq("->", field("return_type", $._type))),
200
- "{",
201
- field("body", alias($._statement_seq, $.function_body)),
202
- "}"
203
- ),
204
- anonymous_function_parameters: ($) =>
205
- seq(
206
- "(",
207
- optional(
208
- series_of(
209
- alias($.anonymous_function_parameter, $.function_parameter),
210
- ","
211
- )
212
- ),
213
- ")"
214
- ),
215
-
216
- _discard_param: ($) => field("name", $.discard),
217
- anonymous_function_parameter: ($) =>
218
- seq(
219
- choice($._discard_param, $._name_param),
220
- optional($._type_annotation)
221
- ),
222
- expression_group: ($) => seq("{", $._statement_seq, "}"),
223
-
224
- when: $ => seq(
225
- "when",
226
- optional($._expression),
227
- "{",
228
- repeat($.when_entry),
229
- "}"
230
- ),
231
-
232
- if: $ => seq(
233
- "if",
234
- $._expression,
235
- "{",
236
- repeat($._expression),
237
- "}"
238
- ),
239
-
240
- when_entry: $ => seq(
241
- choice(
242
- $._expression,
243
- "_"
244
- ),
245
- "->",
246
- $._expression,
247
- ),
248
-
249
- _maybe_record_expression: ($) =>
250
- choice(
251
- $.record,
252
- $.identifier,
253
- $.function_call,
254
- $.expression_group,
255
- $.if,
256
- $.when,
257
- // $.record_update,
258
- $.field_access,
259
- ),
260
-
261
-
262
- _maybe_function_expression: ($) =>
263
- choice(
264
- $.identifier,
265
- $.anonymous_function,
266
- $.expression_group,
267
- $.if,
268
- $.when,
269
- $.field_access,
270
- $.function_call
271
- ),
272
-
273
- field_access: ($) =>
274
- prec.left(
275
- seq(
276
- field("record", $._maybe_record_expression),
277
- ".",
278
- field("field", $.label)
279
- )
280
- ),
281
-
282
- arguments: ($) => seq("(", optional(series_of($.argument, ",")), ")"),
283
- argument: ($) =>
284
- seq(
285
- optional(seq(field("label", $.label), ":")),
286
- field("value", choice($.hole, $._expression))
287
- ),
288
- hole: ($) => $._discard_name,
289
-
290
- function_call: ($) =>
291
- seq(
292
- field("function", $._maybe_function_expression),
293
- field("arguments", $.arguments)
294
- ),
295
-
296
- negation: ($) => seq("!", $._expression_unit),
297
- let: ($) => seq("let", $._assignment),
298
- _assignment: ($) =>
299
- seq(
300
- field("pattern", $._pattern_expression),
301
- "=",
302
- field("value", $._expression)
303
- ),
304
-
305
- record_update: ($) =>
306
- seq(
307
- field(
308
- "constructor", $.constructor_name
309
- ),
310
- "(",
311
- "..",
312
- field("spread", $._expression),
313
- ",",
314
- field("arguments", $.record_update_arguments),
315
- ")"
316
- ),
317
- record_update_arguments: ($) => series_of($.record_update_argument, ","),
318
- record_update_argument: ($) =>
319
- seq(field("label", $.label), ":", field("value", $._expression)),
320
-
321
- _pattern_expression: ($) =>
322
- choice(
323
- $.identifier,
324
- $.discard,
325
- $.record_pattern,
326
- $.string,
327
- $.integer,
328
- $.float,
329
- ),
330
-
331
- record_pattern: ($) =>
332
- seq(
333
- field("name", $.constructor_name),
334
- optional(field("arguments", $.record_pattern_arguments))
335
- ),
336
- record_pattern_arguments: ($) =>
337
- seq(
338
- "(",
339
- optional(series_of($.record_pattern_argument, ",")),
340
- optional($.pattern_spread),
341
- ")"
342
- ),
343
- record_pattern_argument: ($) =>
344
- seq(
345
- optional(seq(field("label", $.label), ":")),
346
- field("pattern", $._pattern_expression)
347
- ),
348
- pattern_spread: ($) => seq("..", optional(",")),
349
-
350
- /* Types */
351
- field: ($) =>
352
- seq(field("name", $.identifier), ":", field("type", $._type)),
353
-
354
- function_type: ($) =>
355
- seq(
356
- "fn",
357
- optional(field("parameter_types", $.function_parameter_types)),
358
- optional($.return_type),
359
- ),
360
- function_parameter_types: ($) =>
361
- seq("(", optional(series_of($._type, ",")), ")"),
362
-
363
- type: ($) =>
364
- seq(
365
- field("name", $.type_identifier),
366
- optional(field("arguments", $.type_arguments))
367
- ),
368
- type_arguments: ($) =>
369
- seq("(", optional(series_of($.type_argument, ",")), ")"),
370
- type_argument: ($) => $._type,
371
-
372
- return_type: ($) => seq("->", field("return_type", $._type)),
373
-
374
- generics: ($) => seq("(", series_of($.generic, ","), ")"),
375
- generic: ($) => /[a-z][a-z]*/,
376
- visibility_modifier: ($) => "pub",
377
-
378
- /* Literals */
379
- float: ($) => /-?[0-9]+\.[0-9]*/,
380
- integer: ($) =>
381
- seq(optional("-"), choice($._hex, $._decimal, $._octal, $._binary)),
382
- string: ($) =>
383
- seq(
384
- `"`,
385
- repeat(choice($.escape_sequence, $.quoted_content)),
386
- token.immediate(`"`)
387
- ),
388
- _hex: ($) => /0[xX][0-9a-fA-F_]+/,
389
- _decimal: ($) => /[0-9][0-9_]*/,
390
- _octal: ($) => /0[oO][0-7_]+/,
391
- _binary: ($) => /0[bB][0-1_]+/,
392
- _interpolation: ($) => choice(seq("{", $.identifier, "}")),
393
- escape_sequence: ($) => token.immediate(/\\[efnrt\"\\]/),
394
- // identifier: ($) => $._name,
395
- identifier: ($) => /[_a-z][_0-9a-z]*/,
396
- label: ($) => $._name,
397
- discard: ($) => $._discard_name,
398
- type_identifier: ($) => $._upname,
399
- constructor_name: ($) => $._upname,
400
- function_name: ($) => $._name,
401
- remote_function_identifier: ($) =>
402
- seq(field("module", $.identifier), ".", field("name", $.identifier)),
403
- remote_constructor_name: ($) =>
404
- seq(field("module", $.identifier), ".", field("name", $.type_identifier)),
405
- _type_annotation: ($) => seq(":", field("type", $._type)),
406
- _type: ($) =>
407
- choice($.type, $.generic, $.function_type),
408
-
409
-
410
- _discard_name: ($) => /_[_0-9a-z]*/,
411
- _name: ($) => /[_a-z][_0-9a-z]*/,
412
- _upname: ($) => /[A-Z][0-9a-zA-Z]*/,
413
- },
414
- });
415
-
416
- function series_of(rule, separator) {
417
- return seq(rule, repeat(seq(separator, rule)), optional(separator));
418
- }
419
-
420
- function arithmeticExpression(exprType) {
421
- return choice(
422
- binaryExpr(prec.left, 1, "||", exprType),
423
- binaryExpr(prec.left, 2, "&&", exprType),
424
- binaryExpr(prec.left, 3, "==", exprType),
425
- binaryExpr(prec.left, 3, "!=", exprType),
426
- binaryExpr(prec.left, 4, "<", exprType),
427
- binaryExpr(prec.left, 4, "<=", exprType),
428
- binaryExpr(prec.left, 4, ">", exprType),
429
- binaryExpr(prec.left, 4, ">=", exprType),
430
- binaryExpr(prec.left, 5, "|>", exprType),
431
- binaryExpr(prec.left, 6, "+", exprType),
432
- binaryExpr(prec.left, 6, "-", exprType),
433
- binaryExpr(prec.left, 7, "*", exprType),
434
- binaryExpr(prec.left, 7, "/", exprType),
435
- binaryExpr(prec.left, 7, "%", exprType),
436
- binaryExpr(prec.left, 7, "<>", exprType)
437
- )
438
- }
439
-
440
- function binaryExpr(assoc, precedence, operator, expr) {
441
- return assoc(
442
- precedence,
443
- seq(field("left", expr), field("operator", operator), field("right", expr))
444
- );
445
- }
index.html ADDED
@@ -0,0 +1,22 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Langium Web</title>
8
+ <link href="./static/styles.css" rel="stylesheet"/>
9
+ </head>
10
+
11
+ <body>
12
+ <div style="padding: 5px">
13
+ <h1>Palm in Langium</h1>
14
+ Please select which grammar definition you want to use with monaco-editor:
15
+ <br>
16
+ <a href="./static/monacoClassic.html">Palm + Monarch (Classic monaco-editor config)</a>
17
+ <br>
18
+ <a href="./static/monacoExtended.html">Palm + Textmate (Extended Vscode Extension Config)</a>
19
+ </div>
20
+ </body>
21
+
22
+ </html>
langium-config.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "projectName": "Palm",
3
+ "languages": [{
4
+ "id": "palm",
5
+ "grammar": "src/language/palm.langium",
6
+ "fileExtensions": [".palm"],
7
+ "textMate": {
8
+ "out": "syntaxes/palm.tmLanguage.json"
9
+ },
10
+ "monarch": {
11
+ "out": "syntaxes/palm.monarch.ts"
12
+ }
13
+ }],
14
+ "out": "src/language/generated"
15
+ }
langium-quickstart.md ADDED
@@ -0,0 +1,40 @@
1
+ # Welcome to your Langium VS Code Extension
2
+
3
+ ## What's in the folder
4
+
5
+ This folder contains all necessary files for your language extension.
6
+ * `package.json` - the manifest file in which you declare your language support.
7
+ * `language-configuration.json` - the language configuration used in the VS Code editor, defining the tokens that are used for comments and brackets.
8
+ * `src/extension/main.ts` - the main code of the extension, which is responsible for launching a language server and client.
9
+ * `src/language/palm.langium` - the grammar definition of your language.
10
+ * `src/language/main.ts` - the entry point of the language server process.
11
+ * `src/language/palm-module.ts` - the dependency injection module of your language implementation. Use this to register overridden and added services.
12
+ * `src/language/palm-validator.ts` - an example validator. You should change it to reflect the semantics of your language.
13
+ * `src/cli/main.ts` - the entry point of the command line interface (CLI) of your language.
14
+ * `src/cli/generator.ts` - the code generator used by the CLI to write output files from DSL documents.
15
+ * `src/cli/cli-util.ts` - utility code for the CLI.
16
+
17
+ ## Get up and running straight away
18
+
19
+ * Run `npm run langium:generate` to generate TypeScript code from the grammar definition.
20
+ * Run `npm run build` to compile all TypeScript code.
21
+ * Press `F5` to open a new window with your extension loaded.
22
+ * Create a new file with a file name suffix matching your language.
23
+ * Verify that syntax highlighting, validation, completion etc. are working as expected.
24
+ * Run `node ./bin/cli` to see options for the CLI; `node ./bin/cli generate <file>` generates code for a given DSL file.
25
+
26
+ ## Make changes
27
+
28
+ * Run `npm run watch` to have the TypeScript compiler run automatically after every change of the source files.
29
+ * Run `npm run langium:watch` to have the Langium generator run automatically after every change of the grammar declaration.
30
+ * You can relaunch the extension from the debug toolbar after making changes to the files listed above.
31
+ * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes.
32
+
33
+ ## Install your extension
34
+
35
+ * To start using your extension with VS Code, copy it into the `<user home>/.vscode/extensions` folder and restart Code.
36
+ * To share your extension with the world, read the [VS Code documentation](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) about publishing an extension.
37
+
38
+ ## To Go Further
39
+
40
+ Documentation about the Langium framework is available at https://langium.org
language-configuration.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "comments": {
3
+ // symbol used for single line comment. Remove this entry if your language does not support line comments
4
+ "lineComment": "//",
5
+ // symbols used for start and end a block comment. Remove this entry if your language does not support block comments
6
+ "blockComment": [ "/*", "*/" ]
7
+ },
8
+ // symbols used as brackets
9
+ "brackets": [
10
+ ["{", "}"],
11
+ ["[", "]"],
12
+ ["(", ")"]
13
+ ],
14
+ // symbols that are auto closed when typing
15
+ "autoClosingPairs": [
16
+ ["{", "}"],
17
+ ["[", "]"],
18
+ ["(", ")"],
19
+ ["\"", "\""],
20
+ ["'", "'"]
21
+ ],
22
+ // symbols that can be used to surround a selection
23
+ "surroundingPairs": [
24
+ ["{", "}"],
25
+ ["[", "]"],
26
+ ["(", ")"],
27
+ ["\"", "\""],
28
+ ["'", "'"]
29
+ ]
30
+ }
package.json CHANGED
@@ -1,40 +1,87 @@
1
1
  {
2
- "name": "tree-sitter-palm",
2
+ "name": "palm-lang",
3
+ "description": "Please enter a brief description here",
3
- "version": "0.1.0",
4
+ "version": "0.0.1",
4
- "description": "A tree-sitter grammar for the Palm programming language",
5
+ "files": [
6
+ "bin"
7
+ ],
5
- "main": "bindings/node",
8
+ "type": "module",
6
9
  "scripts": {
10
+ "build": "tsc -b tsconfig.json && node esbuild.mjs",
11
+ "watch": "concurrently -n tsc,esbuild -c blue,yellow \"tsc -b tsconfig.json --watch\" \"node esbuild.mjs --watch\"",
12
+ "lint": "eslint src --ext ts",
13
+ "langium:generate": "langium generate",
14
+ "langium:watch": "langium generate --watch",
15
+ "vscode:prepublish": "npm run build && npm run lint",
16
+ "prepare:static": "node ./scripts/prepare.js",
17
+ "build:web": "npm run build && npm run prepare:static && npm run build:monarch && npm run build:worker && npm run build:bundle",
18
+ "build:monarch": "tsc -b tsconfig.monarch.json",
19
+ "build:bundle": "vite --config ./vite.bundle.config.ts build",
20
+ "build:worker": "esbuild --minify ./out/language/main-browser.js --bundle --format=iife --outfile=./static/worker/palm-server-worker.js",
21
+ "dev": "vite",
22
+ "dev:debug": "vite --debug --force",
7
- "install": "node-gyp rebuild",
23
+ "serve": "npm run dev"
8
- "format": "prettier --write grammar.js",
9
- "test": "tree-sitter generate && tree-sitter test"
10
24
  },
11
- "author": "pyrossh",
12
- "license": "MIT",
13
- "keywords": [
14
- "palm",
15
- "tree-sitter",
16
- "parser",
17
- "lexer",
18
- "grammar"
19
- ],
20
25
  "dependencies": {
21
- "nan": "^2.17.0"
26
+ "langium": "~2.1.0",
27
+ "vscode-languageclient": "~9.0.1",
28
+ "vscode-languageserver": "~9.0.1",
29
+ "chalk": "~5.3.0",
30
+ "commander": "~11.0.0",
31
+ "@codingame/monaco-vscode-editor-service-override": "~1.83.2",
32
+ "@codingame/monaco-vscode-keybindings-service-override": "~1.83.2",
33
+ "monaco-editor-workers": "~0.44.0",
34
+ "monaco-editor-wrapper": "~3.3.0",
35
+ "monaco-languageclient": "~6.6.0",
36
+ "vscode": "npm:@codingame/monaco-vscode-api@>=1.83.2 <1.84.0"
22
37
  },
23
38
  "devDependencies": {
39
+ "@types/node": "~16.18.41",
40
+ "@typescript-eslint/parser": "~6.4.1",
41
+ "@typescript-eslint/eslint-plugin": "~6.4.1",
24
- "prettier": "^2.8.7",
42
+ "eslint": "~8.47.0",
25
- "tree-sitter-cli": "^0.20.7"
43
+ "langium-cli": "~2.1.0",
44
+ "typescript": "~5.1.6",
45
+ "@types/vscode": "~1.67.0",
46
+ "concurrently": "~8.2.1",
47
+ "esbuild": "~0.19.2",
48
+ "vite": "~4.4.11"
26
49
  },
50
+ "displayName": "palm-lang",
27
- "repository": {
51
+ "engines": {
28
- "type": "git",
52
+ "vscode": "^1.67.0",
29
- "url": "git+ssh://git@github.com/pyrossh/tree-sitter-palm.git"
53
+ "node": ">=16.0.0"
30
54
  },
31
- "tree-sitter": [
55
+ "categories": [
56
+ "Programming Languages"
57
+ ],
58
+ "contributes": {
59
+ "languages": [
32
- {
60
+ {
33
- "scope": "source.palm",
61
+ "id": "palm",
34
- "file-types": [
62
+ "aliases": [
63
+ "Palm",
35
- "palm"
64
+ "palm"
36
- ],
65
+ ],
66
+ "extensions": [
67
+ ".palm"
68
+ ],
37
- "injection-regex": "^palm$"
69
+ "configuration": "./language-configuration.json"
38
- }
70
+ }
71
+ ],
72
+ "grammars": [
73
+ {
74
+ "language": "palm",
75
+ "scopeName": "source.palm",
76
+ "path": "syntaxes/palm.tmLanguage.json"
77
+ }
39
- ]
78
+ ]
79
+ },
80
+ "activationEvents": [
81
+ "onLanguage:palm"
82
+ ],
83
+ "main": "./out/extension/main.cjs",
84
+ "bin": {
85
+ "palm-cli": "./bin/cli.js"
86
+ }
40
87
  }
queries/highlights.scm DELETED
@@ -1,102 +0,0 @@
1
- ; Comments
2
- (module_comment) @comment
3
- (statement_comment) @comment
4
- (comment) @comment
5
-
6
- ; Constants
7
- (constant
8
- name: (identifier) @constant)
9
-
10
- ; Modules
11
- (module) @module
12
- (import alias: (identifier) @module)
13
- (remote_type_identifier
14
- module: (identifier) @module)
15
- (remote_constructor_name
16
- module: (identifier) @module)
17
- ((field_access
18
- record: (identifier) @module
19
- field: (label) @function)
20
- (#is-not? local))
21
-
22
- ; Functions
23
- (unqualified_import (identifier) @function)
24
- (function
25
- name: (identifier) @function)
26
- (external_function
27
- name: (identifier) @function)
28
- (function_parameter
29
- name: (identifier) @variable.parameter)
30
- ((function_call
31
- function: (identifier) @function)
32
- (#is-not? local))
33
- ((binary_expression
34
- operator: "|>"
35
- right: (identifier) @function)
36
- (#is-not? local))
37
-
38
- ; "Properties"
39
- ; Assumed to be intended to refer to a name for a field; something that comes
40
- ; before ":" or after "."
41
- ; e.g. record field names, tuple indices, names for named arguments, etc
42
- (label) @property
43
- (tuple_access
44
- index: (integer) @property)
45
-
46
- ; Type names
47
- (remote_type_identifier) @type
48
- (type_identifier) @type
49
-
50
- ; Data constructors
51
- (constructor_name) @constructor
52
-
53
- ; Literals
54
- (string) @string
55
- (bit_string_segment_option) @function.builtin
56
- (integer) @number
57
- (float) @number
58
-
59
- ; Variables
60
- (identifier) @variable
61
- (discard) @comment.unused
62
-
63
- ; Operators
64
- (binary_expression
65
- operator: _ @operator)
66
- "!" @operator
67
-
68
- ; Keywords
69
- [
70
- "as"
71
- "assert"
72
- "case"
73
- "const"
74
- "extern"
75
- "fn"
76
- "import"
77
- "let"
78
- "panic"
79
- "todo"
80
- "type"
81
- ] @keyword
82
-
83
- ; Punctuation
84
- [
85
- "("
86
- ")"
87
- "["
88
- "]"
89
- "{"
90
- "}"
91
- ] @punctuation.bracket
92
- [
93
- "."
94
- ","
95
- ":"
96
- "#"
97
- "="
98
- "->"
99
- ".."
100
- "-"
101
- "<-"
102
- ] @punctuation.delimiter
queries/locals.scm DELETED
@@ -1,15 +0,0 @@
1
- ; Scopes
2
- (function) @local.scope
3
-
4
- (case_clause) @local.scope
5
-
6
- ; Definitions
7
- (let pattern: (identifier) @local.definition)
8
- (function_parameter name: (identifier) @local.definition)
9
- (list_pattern (identifier) @local.definition)
10
- (list_pattern assign: (identifier) @local.definition)
11
- (tuple_pattern (identifier) @local.definition)
12
- (record_pattern_argument pattern: (identifier) @local.definition)
13
-
14
- ; References
15
- (identifier) @local.reference
queries/tags.scm DELETED
@@ -1,41 +0,0 @@
1
- ; Modules
2
- (module) @name @reference.module
3
- (import alias: (identifier) @name) @reference.module
4
- ; (remote_type_identifier
5
- ; module: (identifier) @name) @reference.module
6
- ; ((field_access
7
- ; record: (identifier) @name)
8
- ; (#is-not? local)) @reference.module
9
-
10
- ; Functions
11
- (function
12
- name: (identifier) @name) @definition.function
13
- (external_function
14
- name: (identifier) @name) @definition.function
15
- (unqualified_import (identifier) @name) @reference.function
16
- ((function_call
17
- function: (identifier) @name) @reference.function
18
- (#is-not? local))
19
- ((field_access
20
- record: (identifier) @ignore
21
- field: (label) @name)
22
- (#is-not? local)) @reference.function
23
- ((binary_expression
24
- operator: "|>"
25
- right: (identifier) @name)
26
- (#is-not? local)) @reference.function
27
-
28
- ; Types
29
- (type_definition
30
- (type_name
31
- name: (type_identifier) @name)) @definition.type
32
- (type_definition
33
- (data_constructors
34
- (data_constructor
35
- name: (constructor_name) @name))) @definition.constructor
36
- (external_type
37
- (type_name
38
- name: (type_identifier) @name)) @definition.type
39
-
40
- (type_identifier) @name @reference.type
41
- (constructor_name) @name @reference.constructor
readme.md DELETED
@@ -1,315 +0,0 @@
1
- # Palm Programming Language
2
-
3
- 🌴 A statically typed programming language 🌴
4
-
5
- - Aims to be compiled to [WASM](https://webassembly.org/) with [WASI](https://wasi.dev/) support.
6
- - No memory management as the script/program is meant to run only once and exit.
7
- - Targetting to run only in Edge environments like [wasmedge](https://wasmedge.org/), [fermyon](https://www.fermyon.com/)
8
-
9
- ## Quick start
10
-
11
- ```sh
12
- palm new demo # Create a new project called demo
13
- palm run # Run the project
14
- palm test # Run the tests
15
- ```
16
-
17
- ## Syntax
18
-
19
- ### 1. Imports
20
-
21
- ```gleam
22
- import nasa/rocket_ship
23
- import animal/cat.{Cat, stroke}
24
- import animal/cat as kitty
25
- ```
26
-
27
- #### 2. Constants
28
-
29
- ```gleam
30
- const start_year = 2101
31
- const end_year = 2111
32
- const name: String = "Gleam"
33
- const size: Int = 100
34
- ```
35
-
36
- #### 3. Inbuilt Types
37
-
38
- ```gleam
39
- Byte
40
- Bytes
41
- Bool
42
- Int
43
- Float
44
- List(element)
45
- Nil
46
- Result(value, error)
47
- String
48
- UtfCodepoint
49
- Error
50
- False
51
- Nil
52
- Ok
53
- True
54
- ```
55
-
56
- #### 4. Expressions
57
-
58
- ```gleam
59
- import palm/string
60
- import palm/bool
61
-
62
- let value: Bool = {
63
- "Hello"
64
- 42 + 12
65
- False
66
- }
67
- let celsius = { fahrenheit - 32 } * 5 / 9
68
- let st = "Hello, {celsius}!"
69
-
70
- case some_number {
71
- 0 -> "Zero"
72
- 1 -> "One"
73
- 2 -> "Two"
74
- n -> "Some other number" // This matches anything
75
- }
76
-
77
- let description =
78
- case True {
79
- True -> "It's true!"
80
- False -> "It's not true."
81
- }
82
-
83
- case x, y {
84
- 1, 1 -> "both are 1"
85
- 1, _ -> "x is 1"
86
- _, 1 -> "y is 1"
87
- _, _ -> "neither is 1"
88
- }
89
-
90
- case number {
91
- 2 | 4 | 6 | 8 -> "This is an even number"
92
- 1 | 3 | 5 | 7 -> "This is an odd number"
93
- _ -> "I'm not sure"
94
- }
95
-
96
- case xs {
97
- [] -> "This list is empty"
98
- [a] -> "This list has 1 element"
99
- [a, b] -> "This list has 2 elements"
100
- _other -> "This list has more than 2 elements"
101
- }
102
-
103
- // Pipe
104
- "Hello"
105
- |> string_builder.from_string
106
- |> string_builder.reverse
107
- |> string_builder.to_string // => "olleh"
108
- ```
109
-
110
- #### 5. Types
111
-
112
- #### A. ADT (Algebraic Data Type)
113
-
114
- ```gleam
115
- type Bool = True | False
116
-
117
- type MyDatabaseError =
118
- | InvalidQuery
119
- | NetworkTimeout
120
-
121
- type User = LoggedIn(name: String) | Guest
122
-
123
- fn get_name(user: User) {
124
- case user {
125
- LoggedIn(name) -> name
126
- Guest -> "Guest user"
127
- }
128
- }
129
-
130
- fn run() {
131
- let sara = LoggedIn(name: "Sara")
132
- let visitor = Guest
133
- let name = sara
134
- |> get_name() // => "Sara"
135
- }
136
-
137
- // Generics
138
-
139
- type Result(value, reason) = Ok(value) | Error(reason)
140
- ```
141
-
142
- #### B. Record Type
143
-
144
- ```gleam
145
- import palm/option.{Option}
146
-
147
- type Cat(name: String, cuteness: Int, age: Int)
148
-
149
- type Person(
150
- name: String,
151
- gender: Option(String),
152
- shoe_size: Int,
153
- age: Int,
154
- is_happy: Bool
155
- )
156
-
157
- fn have_birthday(person: Person) -> Person {
158
- Person(..person, age: person.age + 1, is_happy: True)
159
- }
160
-
161
- fn run() {
162
- let cat = Cat(name: "Felix", cuteness: 9001, age: 5)
163
- }
164
-
165
- // Generics
166
- type Box(inner: inner_type)
167
-
168
- let a = Box(123) // type is Box(Int)
169
- let b = Box("G") // type is Box(String)
170
-
171
- // Opaque types
172
- // At times it may be useful to create a type and make the constructors and fields private so that
173
- // users of this type can only use the type through publically exported functions.
174
-
175
- type Counter(value: Int)
176
-
177
- fn new() {
178
- Counter(0)
179
- }
180
-
181
- fn increment(counter: Counter) {
182
- Counter(counter.value + 1)
183
- }
184
-
185
- let c = Counter(0)
186
- |> increment()
187
- |> increment()
188
-
189
- // Type aliases
190
-
191
- type Headers = List(String, String)
192
- ```
193
-
194
- #### 6. Functions
195
-
196
- ```gleam
197
- fn add(x: Int, y: Int) -> Int:
198
- x + y
199
-
200
- fn multiply(x: Int, y: Int) -> Int {
201
- x * y
202
- }
203
-
204
- /// HoF
205
- fn twice(f: fn(t) -> t, x: t) -> t {
206
- f(f(x))
207
- }
208
-
209
- fn add_one(x: Int) -> Int {
210
- x + 1
211
- }
212
-
213
- fn add_two(x: Int) -> Int {
214
- twice(add_one, x)
215
- }
216
-
217
- /// Type annotations
218
-
219
- fn identity(x: some_type) -> some_type {
220
- x
221
- }
222
-
223
- fn inferred_identity(x) {
224
- x
225
- }
226
-
227
- /// Generic functions
228
-
229
- fn list_of_two(my_value: a) -> List(a) {
230
- [my_value, my_value]
231
- }
232
-
233
- fn multi_result(x: a, y: b, condition: Bool) -> Result(a, b):
234
- case condition:
235
- True -> Ok(x)
236
- False -> Error(y)
237
-
238
-
239
- /// Anonymous functions
240
-
241
- fn run() {
242
- let add = fn(x, y) { x + y }
243
-
244
- add(1, 2)
245
- }
246
-
247
- /// Currying
248
-
249
- fn add(x, y) {
250
- x + y
251
- }
252
-
253
- fn run():
254
- 1
255
- |> add(3)
256
- |> add(6)
257
- |> add(9)
258
-
259
- fn returns_nil(a) -> Nil {
260
- Nil
261
- }
262
- ```
263
-
264
- #### 7. Lists
265
-
266
- ```gleam
267
- import palm/list
268
-
269
- list.new("Krabs")
270
- |> list.add("Spongebob")
271
- |> list.length() // ==> 3
272
- |> list.contains("Krabs") // ==> true
273
- |> list.get(0) // => Some("Krabs")
274
- |> list.get(5) // => None
275
-
276
- let x = list.new(2, 3)
277
- let y = list.new(1, ..x)
278
- ```
279
-
280
- #### 8. Maps
281
-
282
- ```gleam
283
- import palm/map
284
-
285
- let nums = map.new(:one => 1, :two => 2) // => Map(k, v)
286
- nums |> map.get(:one) // => Some(1)
287
- nums |> map.get(:unknown) // => None
288
- ```
289
-
290
- #### 9. Optional
291
-
292
- ```gleam
293
- import palm/option.{Some, None}
294
-
295
- let number = Some(1)
296
-
297
- case number {
298
- Some(n) -> n
299
- None -> 0
300
- }
301
- ```
302
-
303
- #### 9. Result
304
-
305
- ```gleam
306
- import palm/io.{println}
307
- import palm/result.{Ok, Error}
308
-
309
- let connect_res = Error("Connection failed")
310
-
311
- case connect_res {
312
- Ok(a) -> println("Connection succeeded")
313
- Err(a) -> println("Error occurred: {a}")
314
- }
315
- ```
sample.palm DELETED
@@ -1,168 +0,0 @@
1
- module palm
2
-
3
- pub type Cat = struct(
4
- firstName: String,
5
- middleName: String,
6
- lastName: String,
7
- age: Int
8
- cb: |Int| -> Int
9
- )
10
-
11
- pub decrement = |c: Cat| -> Cat {
12
- println("decrementing")
13
- Cat(...c, age: c.age + 1)
14
- }
15
-
16
- pub fn have_birthday(person: Person) -> Person {
17
- Person(..person, age: person.age + 1, is_happy: True)
18
- }
19
-
20
- pub have_birthday = |person: Person| -> Person {
21
- Person(..person, age: person.age + 1, is_happy: True)
22
- }
23
-
24
- pub fn main {
25
- const cat = Cat(name: "Felix", cuteness: 9001, age: 5)
26
- cat
27
- |> increment()
28
- |> increment()
29
- |> increment()
30
- }
31
-
32
-
33
- isSingleton(b : Bool) -> Type =
34
- | True = Int
35
- | False = List(Int)
36
-
37
- -- module palm/list
38
-
39
- type List(a)(
40
- items: []a
41
- )
42
-
43
- pub fn new(l: ...a) -> List(a) {
44
- List(items: l, size: l.size)
45
- }
46
-
47
- pub fn head(l: List(a)) -> a {
48
- when {
49
- l.size == 0 -> panic("accessing head of empty list")
50
- _ -> l[0]
51
- }
52
- }
53
-
54
- pub fn tail(l: List(a)) -> a {
55
- when {
56
- l.size == 0 -> []
57
- l.size == 1 -> []
58
- _ -> new(l[1:l.size])
59
- }
60
- }
61
-
62
- pub fn is_empty(l: List(a)) -> Bool {
63
- l.size == 0
64
- }
65
-
66
- pub fn contains(l: List(a), elem: a) -> Bool {
67
- when l {
68
- is_empty(l) -> False
69
- head(l) == elem -> True
70
- _ -> contains(tail(l), elem)
71
- }
72
- }
73
-
74
- pub fn each(l: List(a), f: fn (a)) {
75
- if !is_empty(l) {
76
- head(l) |> f()
77
- tail(l) |> each(f)
78
- }
79
- }
80
-
81
- pub type Iterator(element)(
82
- continuation: fn() -> Action(element)
83
- )
84
-
85
- type Action(element) {
86
- Stop
87
- Continue(element, fn() -> Action(element))
88
- }
89
-
90
- pub type Step(element, accumulator) {
91
- Next(element: element, accumulator: accumulator)
92
- Done
93
- }
94
-
95
- InfiniteIteror = Iterator(Bool)(
96
- continuation: fn () -> Action(Bool) {
97
- True
98
- }
99
- )
100
-
101
-
102
- pub fn while(cond: Iterator, cb: fn()) {
103
- when cond().next() {
104
- cb()
105
- while(cond, cb)
106
- }
107
- }
108
-
109
-
110
- items
111
- |> list.each(|| println(item.name) })
112
- |> list.map(|| Person(...item, name: "123") })
113
-
114
- filter(l: List(a), f: (a) -> Bool, acc: List(a) = new()) -> List(a) =
115
- | is_empty(l) -> acc
116
- | f(head(l)) ->
117
- acc |> add(head(l))
118
- filter(tail(l), f, acc)
119
- | _ ->
120
- filter(tail(l), f, acc)
121
-
122
- fn map_res(res: Response) -> Result(String, String) {
123
- case (x = res.status()) {
124
- x >= 500 -> Error("failed")
125
- _ -> Ok("success")
126
- }
127
- }
128
-
129
- handler(request: Request(t)) -> Response(String) =
130
- body = bit_builder.from_string("Hello, world!")
131
- response.new(200)
132
- |> response.prepend_header("made-with", "Gleam")
133
- |> response.set_body(body)
134
-
135
- fn main(args: List(String)) -> Result(Int, String) {
136
- println "Sum of x + y = "
137
- println addMe(10 25)
138
-
139
- list.new(1, 2, 3, 4, 5)
140
- |> list.filter(|x| -> x > 5)
141
- |> list.map(|x| -> x * 2)
142
- |> list.each(|x| -> prinln(x))
143
- |> list.is_empty()
144
-
145
- let res = request.new()
146
- |> request.set_method(Get)
147
- |> request.set_host("test-api.service.hmrc.gov.uk")
148
- |> request.set_path("/hello/world")
149
- |> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
150
- |> request.fetch()
151
-
152
- res
153
- |> map_res
154
- }
155
-
156
-
157
- fn add(x: Int, y: Int) -> Int {
158
- x + y
159
- }
160
-
161
- multiply(x: Int, y: Int) -> Int =
162
- x * y
163
-
164
- twice(f: (t) -> t, x: t) -> t =
165
- f(f(x))
166
-
167
- add_one(x: Int) -> Int =
168
- x + 1
scripts/bundle.js ADDED
@@ -0,0 +1,21 @@
1
+ import getEditorServiceOverride from '@codingame/monaco-vscode-editor-service-override';
2
+ import getKeybindingsServiceOverride from '@codingame/monaco-vscode-keybindings-service-override';
3
+ import { useOpenEditorStub } from 'monaco-languageclient';
4
+ import { MonacoEditorLanguageClientWrapper } from 'monaco-editor-wrapper';
5
+ import { addMonacoStyles } from 'monaco-editor-wrapper/styles';
6
+
7
+ export const defineUserServices = () => {
8
+ return {
9
+ userServices: {
10
+ ...getEditorServiceOverride(useOpenEditorStub),
11
+ ...getKeybindingsServiceOverride()
12
+ },
13
+ debugLogging: true
14
+ }
15
+ };
16
+ export {
17
+ getEditorServiceOverride,
18
+ getKeybindingsServiceOverride,
19
+ addMonacoStyles,
20
+ MonacoEditorLanguageClientWrapper
21
+ }
scripts/prepare.js ADDED
@@ -0,0 +1,20 @@
1
+ import { cp, existsSync, mkdirSync } from "node:fs";
2
+
3
+ if (!existsSync('./syntaxes')) {
4
+ mkdirSync('./syntaxes');
5
+ }
6
+ if (!existsSync('./static/worker')) {
7
+ mkdirSync('./static/worker');
8
+ }
9
+
10
+ if (!existsSync('./static/monaco-editor-workers/workers')) {
11
+ mkdirSync('./static/monaco-editor-workers/workers', { recursive: true });
12
+ }
13
+ const logError = (err) => {
14
+ if (err) {
15
+ console.error(err);
16
+ }
17
+ };
18
+ cp('./node_modules/monaco-editor-workers/dist/index.js', './static/monaco-editor-workers/index.js', logError);
19
+ cp('./node_modules/monaco-editor-workers/dist/workers/editorWorker-es.js', './static/monaco-editor-workers/workers/editorWorker-es.js', logError);
20
+ cp('./node_modules/monaco-editor-workers/dist/workers/editorWorker-iife.js', './static/monaco-editor-workers/workers/editorWorker-iife.js', logError);
spec.gleam DELETED
@@ -1,198 +0,0 @@
1
- import gleam/io
2
- import gleam/bool
3
- import gleam/string
4
- import gleam/list
5
- import gleam/http/response.{Request, Response}
6
- import gleam/bit_builder.{BitBuilder}
7
-
8
- pub fn main() {
9
- io.print("hi")
10
- False
11
- |> bool.nand(False)
12
- }
13
-
14
- pub type Result(value, reason) {
15
- Ok(value)
16
- Error(reason)
17
- }
18
-
19
- pub fn fib(x: Int) -> Int {
20
- when x {
21
- 0..1 -> 1
22
- _ -> fib(x - 1) + fib(x - 2)
23
- }
24
-
25
- when x > 5 {
26
- }
27
- }
28
-
29
- pub fn handler(request: Request) -> Response {
30
- let body = bit_builder.from_string("Hello, world!")
31
-
32
- response.new(200)
33
- |> response.prepend_header("made-with", "Gleam")
34
- |> response.set_body(body)
35
- }
36
-
37
- pub fn main() {
38
- let res =
39
- request.new()
40
- |> request.set_method(Get)
41
- |> request.set_host("test-api.service.hmrc.gov.uk")
42
- |> request.set_path("/hello/world")
43
- |> request.prepend_header("accept", "application/vnd.hmrc.1.0+json")
44
- |> request.fetch()
45
-
46
- case res {
47
- Ok(b) -> {
48
- let data = json.parse(b)
49
- response.new(200)
50
- |> response.set_body(json.stringify(data))
51
- }
52
- Error(_) -> {
53
- response.new(500)
54
- |> response.set_body("Could not find data")
55
- }
56
- }
57
- }
58
-
59
- pub fn all(results: List(Result(a, e))) -> Result(List(a), e) {
60
- list.try_map(results, fn(x) { x })
61
- }
62
-
63
- pub fn add(x: Int, y: Int) -> Int {
64
- x + y
65
- }
66
-
67
- pub fn multiply(x: Int, y: Int) -> Int {
68
- x * y
69
- }
70
-
71
- /// This function takes a function as an argument
72
- pub fn twice(f: fn(t) -> t, x: t) -> t {
73
- f(f(x))
74
- }
75
-
76
- pub fn add_one(x: Int) -> Int {
77
- x + 1
78
- }
79
-
80
- pub fn add_two(x: Int) -> Int {
81
- twice(add_one, x)
82
- }
83
-
84
- pub const start_year = 2101
85
-
86
- pub const end_year = 2111
87
-
88
- pub fn is_before(year: Int) -> Bool {
89
- year < start_year
90
- }
91
-
92
- pub fn is_during(year: Int) -> Bool {
93
- start_year <= year && year <= end_year
94
- }
95
-
96
- struct Int:
97
- fn is_before(year: Int) -> Bool:
98
- year < start_year
99
-
100
- fn is_during(year: Int) -> Bool:
101
- start_year <= year && year <= end_year
102
-
103
- fn describe(year: Int) -> String:
104
- case year:
105
- year if year < start_year -> "Before"
106
- year if year > end_year -> "After"
107
- _ -> "During"
108
-
109
- pub const name: String = "Gleam"
110
-
111
- pub const size: Int = 100
112
-
113
- pub type Headers =
114
- List(#(String, String))
115
-
116
- pub fn main() {
117
- let string = "123"
118
- string
119
- |> string_builder.from_string
120
- |> string_builder.reverse
121
- |> string_builder.to_string
122
- }
123
-
124
- pub external fn random_float() -> Float =
125
- "rand" "uniform"
126
-
127
- // Elixir modules start with `Elixir.`
128
- pub external fn inspect(a) -> a =
129
- "Elixir.IO" "inspect"
130
-
131
- pub external type Queue(a)
132
-
133
- pub external fn new() -> Queue(a) =
134
- "queue" "new"
135
-
136
- pub external fn length(Queue(a)) -> Int =
137
- "queue" "len"
138
-
139
- pub external fn push(Queue(a), a) -> Queue(a) =
140
- "queue" "in"
141
-
142
- fn favourite_number() -> Int {
143
- // The type annotations says this returns an Int, but we don't need
144
- // to implement it yet.
145
- todo
146
- }
147
-
148
- pub fn main() {
149
- favourite_number() * 2
150
- }
151
-
152
- fn more_usage() {
153
- list.new(1, 2, 3)
154
- |> list.contains(any: 2)
155
- }
156
-
157
- pub fn get_name(user: User) {
158
- case user {
159
- LoggedIn(name) -> {
160
- let a = 1.2
161
- let b = 4.5
162
- let c = n * factorial(n - 1)
163
- name
164
- }
165
- Guest -> "Guest user"
166
- }
167
- }
168
-
169
- pub type Result(p, q) {
170
- Ok(p)
171
- Error(q)
172
- }
173
-
174
- // pub type Cat(
175
- // name: String,
176
- // cuteness: Int,
177
- // age: Int
178
- // )
179
-
180
- pub fn make_api_call(r: String) -> Result(String, String) {
181
- make_request(r) |> response.map()
182
- }
183
-
184
- pub fn map(res: Response) -> Result(String, String) {
185
- | res.status() >= 500 -> Error("failed")
186
- | _ -> Ok("success")
187
- }
188
-
189
- pub fn get_hex(c: String) -> Int {
190
- when c {
191
- "red" -> 0xff0000
192
- "blue" -> 0xff0123
193
- "green" -> 0xff0123
194
- "black" -> 0x000000
195
- "white" -> 0xffffff
196
- "violet" -> 0x0f0f23
197
- }
198
- }
src/cli/cli-util.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type { AstNode, LangiumDocument, LangiumServices } from 'langium';
2
+ import chalk from 'chalk';
3
+ import * as path from 'node:path';
4
+ import * as fs from 'node:fs';
5
+ import { URI } from 'langium';
6
+
7
+ export async function extractDocument(fileName: string, services: LangiumServices): Promise<LangiumDocument> {
8
+ const extensions = services.LanguageMetaData.fileExtensions;
9
+ if (!extensions.includes(path.extname(fileName))) {
10
+ console.error(chalk.yellow(`Please choose a file with one of these extensions: ${extensions}.`));
11
+ process.exit(1);
12
+ }
13
+
14
+ if (!fs.existsSync(fileName)) {
15
+ console.error(chalk.red(`File ${fileName} does not exist.`));
16
+ process.exit(1);
17
+ }
18
+
19
+ const document = services.shared.workspace.LangiumDocuments.getOrCreateDocument(URI.file(path.resolve(fileName)));
20
+ await services.shared.workspace.DocumentBuilder.build([document], { validation: true });
21
+
22
+ const validationErrors = (document.diagnostics ?? []).filter(e => e.severity === 1);
23
+ if (validationErrors.length > 0) {
24
+ console.error(chalk.red('There are validation errors:'));
25
+ for (const validationError of validationErrors) {
26
+ console.error(chalk.red(
27
+ `line ${validationError.range.start.line + 1}: ${validationError.message} [${document.textDocument.getText(validationError.range)}]`
28
+ ));
29
+ }
30
+ process.exit(1);
31
+ }
32
+
33
+ return document;
34
+ }
35
+
36
+ export async function extractAstNode<T extends AstNode>(fileName: string, services: LangiumServices): Promise<T> {
37
+ return (await extractDocument(fileName, services)).parseResult?.value as T;
38
+ }
39
+
40
+ interface FilePathData {
41
+ destination: string,
42
+ name: string
43
+ }
44
+
45
+ export function extractDestinationAndName(filePath: string, destination: string | undefined): FilePathData {
46
+ filePath = path.basename(filePath, path.extname(filePath)).replace(/[.-]/g, '');
47
+ return {
48
+ destination: destination ?? path.join(path.dirname(filePath), 'generated'),
49
+ name: path.basename(filePath)
50
+ };
51
+ }
src/cli/generator.ts ADDED
@@ -0,0 +1,20 @@
1
+ import type { Program } from '../language/generated/ast.js';
2
+ import * as fs from 'node:fs';
3
+ import { CompositeGeneratorNode, NL, toString } from 'langium';
4
+ import * as path from 'node:path';
5
+ import { extractDestinationAndName } from './cli-util.js';
6
+
7
+ export function generateJavaScript(model: Program, filePath: string, destination: string | undefined): string {
8
+ const data = extractDestinationAndName(filePath, destination);
9
+ const generatedFilePath = `${path.join(data.destination, data.name)}.js`;
10
+
11
+ const fileNode = new CompositeGeneratorNode();
12
+ fileNode.append('"use strict";', NL, NL);
13
+ // model.greetings.forEach(greeting => fileNode.append(`console.log('Hello, ${greeting.person.ref?.name}!');`, NL));
14
+
15
+ if (!fs.existsSync(data.destination)) {
16
+ fs.mkdirSync(data.destination, { recursive: true });
17
+ }
18
+ fs.writeFileSync(generatedFilePath, toString(fileNode));
19
+ return generatedFilePath;
20
+ }
src/cli/main.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { Program } from '../language/generated/ast.js';
2
+ import chalk from 'chalk';
3
+ import { Command } from 'commander';
4
+ import { PalmLanguageMetaData } from '../language/generated/module.js';
5
+ import { createPalmServices } from '../language/palm-module.js';
6
+ import { extractAstNode } from './cli-util.js';
7
+ import { generateJavaScript } from './generator.js';
8
+ import { NodeFileSystem } from 'langium/node';
9
+ import * as url from 'node:url';
10
+ import * as fs from 'node:fs/promises';
11
+ import * as path from 'node:path';
12
+ const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
13
+
14
+ const packagePath = path.resolve(__dirname, '..', '..', 'package.json');
15
+ const packageContent = await fs.readFile(packagePath, 'utf-8');
16
+
17
+ export const generateAction = async (fileName: string, opts: GenerateOptions): Promise<void> => {
18
+ const services = createPalmServices(NodeFileSystem).Palm;
19
+ const model = await extractAstNode<Program>(fileName, services);
20
+ const generatedFilePath = generateJavaScript(model, fileName, opts.destination);
21
+ console.log(chalk.green(`JavaScript code generated successfully: ${generatedFilePath}`));
22
+ };
23
+
24
+ export type GenerateOptions = {
25
+ destination?: string;
26
+ }
27
+
28
+ export default function (): void {
29
+ const program = new Command();
30
+
31
+ program.version(JSON.parse(packageContent).version);
32
+
33
+ const fileExtensions = PalmLanguageMetaData.fileExtensions.join(', ');
34
+ program
35
+ .command('generate')
36
+ .argument('<file>', `source file (possible file extensions: ${fileExtensions})`)
37
+ .option('-d, --destination <dir>', 'destination directory of generating')
38
+ .description('generates JavaScript code that prints "Hello, {name}!" for each greeting in a source file')
39
+ .action(generateAction);
40
+
41
+ program.parse(process.argv);
42
+ }
src/extension/main.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { LanguageClientOptions, ServerOptions} from 'vscode-languageclient/node.js';
2
+ import * as vscode from 'vscode';
3
+ import * as path from 'node:path';
4
+ import { LanguageClient, TransportKind } from 'vscode-languageclient/node.js';
5
+
6
+ let client: LanguageClient;
7
+
8
+ // This function is called when the extension is activated.
9
+ export function activate(context: vscode.ExtensionContext): void {
10
+ client = startLanguageClient(context);
11
+ }
12
+
13
+ // This function is called when the extension is deactivated.
14
+ export function deactivate(): Thenable<void> | undefined {
15
+ if (client) {
16
+ return client.stop();
17
+ }
18
+ return undefined;
19
+ }
20
+
21
+ function startLanguageClient(context: vscode.ExtensionContext): LanguageClient {
22
+ const serverModule = context.asAbsolutePath(path.join('out', 'language', 'main.cjs'));
23
+ // The debug options for the server
24
+ // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging.
25
+ // By setting `process.env.DEBUG_BREAK` to a truthy value, the language server will wait until a debugger is attached.
26
+ const debugOptions = { execArgv: ['--nolazy', `--inspect${process.env.DEBUG_BREAK ? '-brk' : ''}=${process.env.DEBUG_SOCKET || '6009'}`] };
27
+
28
+ // If the extension is launched in debug mode then the debug server options are used
29
+ // Otherwise the run options are used
30
+ const serverOptions: ServerOptions = {
31
+ run: { module: serverModule, transport: TransportKind.ipc },
32
+ debug: { module: serverModule, transport: TransportKind.ipc, options: debugOptions }
33
+ };
34
+
35
+ const fileSystemWatcher = vscode.workspace.createFileSystemWatcher('**/*.palm');
36
+ context.subscriptions.push(fileSystemWatcher);
37
+
38
+ // Options to control the language client
39
+ const clientOptions: LanguageClientOptions = {
40
+ documentSelector: [{ scheme: 'file', language: 'palm' }],
41
+ synchronize: {
42
+ // Notify the server about file changes to files contained in the workspace
43
+ fileEvents: fileSystemWatcher
44
+ }
45
+ };
46
+
47
+ // Create the language client and start the client.
48
+ const client = new LanguageClient(
49
+ 'palm',
50
+ 'Palm',
51
+ serverOptions,
52
+ clientOptions
53
+ );
54
+
55
+ // Start the client. This will also launch the server
56
+ client.start();
57
+ return client;
58
+ }
src/grammar.json DELETED
@@ -1,3570 +0,0 @@
1
- {
2
- "name": "palm",
3
- "rules": {
4
- "source_file": {
5
- "type": "SEQ",
6
- "members": [
7
- {
8
- "type": "SYMBOL",
9
- "name": "module"
10
- },
11
- {
12
- "type": "REPEAT",
13
- "content": {
14
- "type": "SYMBOL",
15
- "name": "import"
16
- }
17
- },
18
- {
19
- "type": "REPEAT",
20
- "content": {
21
- "type": "CHOICE",
22
- "members": [
23
- {
24
- "type": "SYMBOL",
25
- "name": "struct"
26
- },
27
- {
28
- "type": "SYMBOL",
29
- "name": "enum"
30
- },
31
- {
32
- "type": "SYMBOL",
33
- "name": "function"
34
- },
35
- {
36
- "type": "SYMBOL",
37
- "name": "const"
38
- }
39
- ]
40
- }
41
- }
42
- ]
43
- },
44
- "module": {
45
- "type": "SEQ",
46
- "members": [
47
- {
48
- "type": "STRING",
49
- "value": "module"
50
- },
51
- {
52
- "type": "FIELD",
53
- "name": "module",
54
- "content": {
55
- "type": "SYMBOL",
56
- "name": "module_name"
57
- }
58
- }
59
- ]
60
- },
61
- "module_comment": {
62
- "type": "TOKEN",
63
- "content": {
64
- "type": "SEQ",
65
- "members": [
66
- {
67
- "type": "STRING",
68
- "value": "////"
69
- },
70
- {
71
- "type": "PATTERN",
72
- "value": ".*"
73
- }
74
- ]
75
- }
76
- },
77
- "statement_comment": {
78
- "type": "TOKEN",
79
- "content": {
80
- "type": "SEQ",
81
- "members": [
82
- {
83
- "type": "STRING",
84
- "value": "///"
85
- },
86
- {
87
- "type": "PATTERN",
88
- "value": ".*"
89
- }
90
- ]
91
- }
92
- },
93
- "comment": {
94
- "type": "TOKEN",
95
- "content": {
96
- "type": "SEQ",
97
- "members": [
98
- {
99
- "type": "STRING",
100
- "value": "//"
101
- },
102
- {
103
- "type": "PATTERN",
104
- "value": ".*"
105
- }
106
- ]
107
- }
108
- },
109
- "import": {
110
- "type": "SEQ",
111
- "members": [
112
- {
113
- "type": "STRING",
114
- "value": "import"
115
- },
116
- {
117
- "type": "FIELD",
118
- "name": "module",
119
- "content": {
120
- "type": "SYMBOL",
121
- "name": "module_name"
122
- }
123
- },
124
- {
125
- "type": "CHOICE",
126
- "members": [
127
- {
128
- "type": "SEQ",
129
- "members": [
130
- {
131
- "type": "STRING",
132
- "value": "."
133
- },
134
- {
135
- "type": "FIELD",
136
- "name": "imports",
137
- "content": {
138
- "type": "SYMBOL",
139
- "name": "unqualified_imports"
140
- }
141
- }
142
- ]
143
- },
144
- {
145
- "type": "BLANK"
146
- }
147
- ]
148
- },
149
- {
150
- "type": "CHOICE",
151
- "members": [
152
- {
153
- "type": "SEQ",
154
- "members": [
155
- {
156
- "type": "STRING",
157
- "value": "as"
158
- },
159
- {
160
- "type": "FIELD",
161
- "name": "alias",
162
- "content": {
163
- "type": "SYMBOL",
164
- "name": "identifier"
165
- }
166
- }
167
- ]
168
- },
169
- {
170
- "type": "BLANK"
171
- }
172
- ]
173
- }
174
- ]
175
- },
176
- "module_name": {
177
- "type": "SEQ",
178
- "members": [
179
- {
180
- "type": "SYMBOL",
181
- "name": "_name"
182
- },
183
- {
184
- "type": "REPEAT",
185
- "content": {
186
- "type": "SEQ",
187
- "members": [
188
- {
189
- "type": "STRING",
190
- "value": "/"
191
- },
192
- {
193
- "type": "SYMBOL",
194
- "name": "_name"
195
- }
196
- ]
197
- }
198
- }
199
- ]
200
- },
201
- "unqualified_imports": {
202
- "type": "SEQ",
203
- "members": [
204
- {
205
- "type": "STRING",
206
- "value": "{"
207
- },
208
- {
209
- "type": "CHOICE",
210
- "members": [
211
- {
212
- "type": "SEQ",
213
- "members": [
214
- {
215
- "type": "SYMBOL",
216
- "name": "unqualified_import"
217
- },
218
- {
219
- "type": "REPEAT",
220
- "content": {
221
- "type": "SEQ",
222
- "members": [
223
- {
224
- "type": "STRING",
225
- "value": ","
226
- },
227
- {
228
- "type": "SYMBOL",
229
- "name": "unqualified_import"
230
- }
231
- ]
232
- }
233
- },
234
- {
235
- "type": "CHOICE",
236
- "members": [
237
- {
238
- "type": "STRING",
239
- "value": ","
240
- },
241
- {
242
- "type": "BLANK"
243
- }
244
- ]
245
- }
246
- ]
247
- },
248
- {
249
- "type": "BLANK"
250
- }
251
- ]
252
- },
253
- {
254
- "type": "STRING",
255
- "value": "}"
256
- }
257
- ]
258
- },
259
- "unqualified_import": {
260
- "type": "CHOICE",
261
- "members": [
262
- {
263
- "type": "SEQ",
264
- "members": [
265
- {
266
- "type": "FIELD",
267
- "name": "name",
268
- "content": {
269
- "type": "SYMBOL",
270
- "name": "identifier"
271
- }
272
- },
273
- {
274
- "type": "CHOICE",
275
- "members": [
276
- {
277
- "type": "SEQ",
278
- "members": [
279
- {
280
- "type": "STRING",
281
- "value": "as"
282
- },
283
- {
284
- "type": "FIELD",
285
- "name": "alias",
286
- "content": {
287
- "type": "SYMBOL",
288
- "name": "identifier"
289
- }
290
- }
291
- ]
292
- },
293
- {
294
- "type": "BLANK"
295
- }
296
- ]
297
- }
298
- ]
299
- },
300
- {
301
- "type": "SEQ",
302
- "members": [
303
- {
304
- "type": "FIELD",
305
- "name": "name",
306
- "content": {
307
- "type": "SYMBOL",
308
- "name": "type_identifier"
309
- }
310
- },
311
- {
312
- "type": "CHOICE",
313
- "members": [
314
- {
315
- "type": "SEQ",
316
- "members": [
317
- {
318
- "type": "STRING",
319
- "value": "as"
320
- },
321
- {
322
- "type": "FIELD",
323
- "name": "alias",
324
- "content": {
325
- "type": "SYMBOL",
326
- "name": "type_identifier"
327
- }
328
- }
329
- ]
330
- },
331
- {
332
- "type": "BLANK"
333
- }
334
- ]
335
- }
336
- ]
337
- }
338
- ]
339
- },
340
- "struct": {
341
- "type": "SEQ",
342
- "members": [
343
- {
344
- "type": "CHOICE",
345
- "members": [
346
- {
347
- "type": "SYMBOL",
348
- "name": "visibility_modifier"
349
- },
350
- {
351
- "type": "BLANK"
352
- }
353
- ]
354
- },
355
- {
356
- "type": "STRING",
357
- "value": "type"
358
- },
359
- {
360
- "type": "FIELD",
361
- "name": "name",
362
- "content": {
363
- "type": "SYMBOL",
364
- "name": "type_identifier"
365
- }
366
- },
367
- {
368
- "type": "FIELD",
369
- "name": "generics",
370
- "content": {
371
- "type": "CHOICE",
372
- "members": [
373
- {
374
- "type": "SYMBOL",
375
- "name": "generics"
376
- },
377
- {
378
- "type": "BLANK"
379
- }
380
- ]
381
- }
382
- },
383
- {
384
- "type": "FIELD",
385
- "name": "fields",
386
- "content": {
387
- "type": "SEQ",
388
- "members": [
389
- {
390
- "type": "STRING",
391
- "value": "("
392
- },
393
- {
394
- "type": "REPEAT",
395
- "content": {
396
- "type": "SYMBOL",
397
- "name": "field"
398
- }
399
- },
400
- {
401
- "type": "STRING",
402
- "value": ")"
403
- }
404
- ]
405
- }
406
- }
407
- ]
408
- },
409
- "enum": {
410
- "type": "SEQ",
411
- "members": [
412
- {
413
- "type": "CHOICE",
414
- "members": [
415
- {
416
- "type": "SYMBOL",
417
- "name": "visibility_modifier"
418
- },
419
- {
420
- "type": "BLANK"
421
- }
422
- ]
423
- },
424
- {
425
- "type": "STRING",
426
- "value": "type"
427
- },
428
- {
429
- "type": "FIELD",
430
- "name": "name",
431
- "content": {
432
- "type": "SYMBOL",
433
- "name": "type_identifier"
434
- }
435
- },
436
- {
437
- "type": "FIELD",
438
- "name": "generics",
439
- "content": {
440
- "type": "CHOICE",
441
- "members": [
442
- {
443
- "type": "SYMBOL",
444
- "name": "generics"
445
- },
446
- {
447
- "type": "BLANK"
448
- }
449
- ]
450
- }
451
- },
452
- {
453
- "type": "FIELD",
454
- "name": "fields",
455
- "content": {
456
- "type": "SEQ",
457
- "members": [
458
- {
459
- "type": "STRING",
460
- "value": "{"
461
- },
462
- {
463
- "type": "REPEAT",
464
- "content": {
465
- "type": "SEQ",
466
- "members": [
467
- {
468
- "type": "FIELD",
469
- "name": "name",
470
- "content": {
471
- "type": "SYMBOL",
472
- "name": "type_identifier"
473
- }
474
- },
475
- {
476
- "type": "CHOICE",
477
- "members": [
478
- {
479
- "type": "SEQ",
480
- "members": [
481
- {
482
- "type": "STRING",
483
- "value": "("
484
- },
485
- {
486
- "type": "CHOICE",
487
- "members": [
488
- {
489
- "type": "SEQ",
490
- "members": [
491
- {
492
- "type": "SYMBOL",
493
- "name": "identifier"
494
- },
495
- {
496
- "type": "REPEAT",
497
- "content": {
498
- "type": "SEQ",
499
- "members": [
500
- {
501
- "type": "STRING",
502
- "value": ","
503
- },
504
- {
505
- "type": "SYMBOL",
506
- "name": "identifier"
507
- }
508
- ]
509
- }
510
- },
511
- {
512
- "type": "CHOICE",
513
- "members": [
514
- {
515
- "type": "STRING",
516
- "value": ","
517
- },
518
- {
519
- "type": "BLANK"
520
- }
521
- ]
522
- }
523
- ]
524
- },
525
- {
526
- "type": "SEQ",
527
- "members": [
528
- {
529
- "type": "SYMBOL",
530
- "name": "field"
531
- },
532
- {
533
- "type": "REPEAT",
534
- "content": {
535
- "type": "SEQ",
536
- "members": [
537
- {
538
- "type": "STRING",
539
- "value": ","
540
- },
541
- {
542
- "type": "SYMBOL",
543
- "name": "field"
544
- }
545
- ]
546
- }
547
- },
548
- {
549
- "type": "CHOICE",
550
- "members": [
551
- {
552
- "type": "STRING",
553
- "value": ","
554
- },
555
- {
556
- "type": "BLANK"
557
- }
558
- ]
559
- }
560
- ]
561
- }
562
- ]
563
- },
564
- {
565
- "type": "STRING",
566
- "value": ")"
567
- }
568
- ]
569
- },
570
- {
571
- "type": "BLANK"
572
- }
573
- ]
574
- }
575
- ]
576
- }
577
- },
578
- {
579
- "type": "STRING",
580
- "value": "}"
581
- }
582
- ]
583
- }
584
- }
585
- ]
586
- },
587
- "function": {
588
- "type": "SEQ",
589
- "members": [
590
- {
591
- "type": "CHOICE",
592
- "members": [
593
- {
594
- "type": "SYMBOL",
595
- "name": "visibility_modifier"
596
- },
597
- {
598
- "type": "BLANK"
599
- }
600
- ]
601
- },
602
- {
603
- "type": "STRING",
604
- "value": "fn"
605
- },
606
- {
607
- "type": "FIELD",
608
- "name": "name",
609
- "content": {
610
- "type": "SYMBOL",
611
- "name": "identifier"
612
- }
613
- },
614
- {
615
- "type": "FIELD",
616
- "name": "params",
617
- "content": {
618
- "type": "SEQ",
619
- "members": [
620
- {
621
- "type": "STRING",
622
- "value": "("
623
- },
624
- {
625
- "type": "CHOICE",
626
- "members": [
627
- {
628
- "type": "SEQ",
629
- "members": [
630
- {
631
- "type": "SYMBOL",
632
- "name": "field"
633
- },
634
- {
635
- "type": "REPEAT",
636
- "content": {
637
- "type": "SEQ",
638
- "members": [
639
- {
640
- "type": "STRING",
641
- "value": ","
642
- },
643
- {
644
- "type": "SYMBOL",
645
- "name": "field"
646
- }
647
- ]
648
- }
649
- },
650
- {
651
- "type": "CHOICE",
652
- "members": [
653
- {
654
- "type": "STRING",
655
- "value": ","
656
- },
657
- {
658
- "type": "BLANK"
659
- }
660
- ]
661
- }
662
- ]
663
- },
664
- {
665
- "type": "BLANK"
666
- }
667
- ]
668
- },
669
- {
670
- "type": "STRING",
671
- "value": ")"
672
- }
673
- ]
674
- }
675
- },
676
- {
677
- "type": "FIELD",
678
- "name": "return",
679
- "content": {
680
- "type": "CHOICE",
681
- "members": [
682
- {
683
- "type": "SYMBOL",
684
- "name": "return_type"
685
- },
686
- {
687
- "type": "BLANK"
688
- }
689
- ]
690
- }
691
- },
692
- {
693
- "type": "FIELD",
694
- "name": "body",
695
- "content": {
696
- "type": "SEQ",
697
- "members": [
698
- {
699
- "type": "STRING",
700
- "value": "{"
701
- },
702
- {
703
- "type": "SYMBOL",
704
- "name": "_statement_seq"
705
- },
706
- {
707
- "type": "STRING",
708
- "value": "}"
709
- }
710
- ]
711
- }
712
- }
713
- ]
714
- },
715
- "const": {
716
- "type": "SEQ",
717
- "members": [
718
- {
719
- "type": "STRING",
720
- "value": "const"
721
- },
722
- {
723
- "type": "SYMBOL",
724
- "name": "identifier"
725
- },
726
- {
727
- "type": "STRING",
728
- "value": "="
729
- },
730
- {
731
- "type": "FIELD",
732
- "name": "value",
733
- "content": {
734
- "type": "SYMBOL",
735
- "name": "_const_expression"
736
- }
737
- }
738
- ]
739
- },
740
- "_const_expression": {
741
- "type": "CHOICE",
742
- "members": [
743
- {
744
- "type": "SYMBOL",
745
- "name": "_const_expression_unit"
746
- },
747
- {
748
- "type": "SYMBOL",
749
- "name": "const_binary_expression"
750
- }
751
- ]
752
- },
753
- "const_binary_expression": {
754
- "type": "CHOICE",
755
- "members": [
756
- {
757
- "type": "PREC_LEFT",
758
- "value": 1,
759
- "content": {
760
- "type": "SEQ",
761
- "members": [
762
- {
763
- "type": "FIELD",
764
- "name": "left",
765
- "content": {
766
- "type": "SYMBOL",
767
- "name": "_const_expression"
768
- }
769
- },
770
- {
771
- "type": "FIELD",
772
- "name": "operator",
773
- "content": {
774
- "type": "STRING",
775
- "value": "||"
776
- }
777
- },
778
- {
779
- "type": "FIELD",
780
- "name": "right",
781
- "content": {
782
- "type": "SYMBOL",
783
- "name": "_const_expression"
784
- }
785
- }
786
- ]
787
- }
788
- },
789
- {
790
- "type": "PREC_LEFT",
791
- "value": 2,
792
- "content": {
793
- "type": "SEQ",
794
- "members": [
795
- {
796
- "type": "FIELD",
797
- "name": "left",
798
- "content": {
799
- "type": "SYMBOL",
800
- "name": "_const_expression"
801
- }
802
- },
803
- {
804
- "type": "FIELD",
805
- "name": "operator",
806
- "content": {
807
- "type": "STRING",
808
- "value": "&&"
809
- }
810
- },
811
- {
812
- "type": "FIELD",
813
- "name": "right",
814
- "content": {
815
- "type": "SYMBOL",
816
- "name": "_const_expression"
817
- }
818
- }
819
- ]
820
- }
821
- },
822
- {
823
- "type": "PREC_LEFT",
824
- "value": 3,
825
- "content": {
826
- "type": "SEQ",
827
- "members": [
828
- {
829
- "type": "FIELD",
830
- "name": "left",
831
- "content": {
832
- "type": "SYMBOL",
833
- "name": "_const_expression"
834
- }
835
- },
836
- {
837
- "type": "FIELD",
838
- "name": "operator",
839
- "content": {
840
- "type": "STRING",
841
- "value": "=="
842
- }
843
- },
844
- {
845
- "type": "FIELD",
846
- "name": "right",
847
- "content": {
848
- "type": "SYMBOL",
849
- "name": "_const_expression"
850
- }
851
- }
852
- ]
853
- }
854
- },
855
- {
856
- "type": "PREC_LEFT",
857
- "value": 3,
858
- "content": {
859
- "type": "SEQ",
860
- "members": [
861
- {
862
- "type": "FIELD",
863
- "name": "left",
864
- "content": {
865
- "type": "SYMBOL",
866
- "name": "_const_expression"
867
- }
868
- },
869
- {
870
- "type": "FIELD",
871
- "name": "operator",
872
- "content": {
873
- "type": "STRING",
874
- "value": "!="
875
- }
876
- },
877
- {
878
- "type": "FIELD",
879
- "name": "right",
880
- "content": {
881
- "type": "SYMBOL",
882
- "name": "_const_expression"
883
- }
884
- }
885
- ]
886
- }
887
- },
888
- {
889
- "type": "PREC_LEFT",
890
- "value": 4,
891
- "content": {
892
- "type": "SEQ",
893
- "members": [
894
- {
895
- "type": "FIELD",
896
- "name": "left",
897
- "content": {
898
- "type": "SYMBOL",
899
- "name": "_const_expression"
900
- }
901
- },
902
- {
903
- "type": "FIELD",
904
- "name": "operator",
905
- "content": {
906
- "type": "STRING",
907
- "value": "<"
908
- }
909
- },
910
- {
911
- "type": "FIELD",
912
- "name": "right",
913
- "content": {
914
- "type": "SYMBOL",
915
- "name": "_const_expression"
916
- }
917
- }
918
- ]
919
- }
920
- },
921
- {
922
- "type": "PREC_LEFT",
923
- "value": 4,
924
- "content": {
925
- "type": "SEQ",
926
- "members": [
927
- {
928
- "type": "FIELD",
929
- "name": "left",
930
- "content": {
931
- "type": "SYMBOL",
932
- "name": "_const_expression"
933
- }
934
- },
935
- {
936
- "type": "FIELD",
937
- "name": "operator",
938
- "content": {
939
- "type": "STRING",
940
- "value": "<="
941
- }
942
- },
943
- {
944
- "type": "FIELD",
945
- "name": "right",
946
- "content": {
947
- "type": "SYMBOL",
948
- "name": "_const_expression"
949
- }
950
- }
951
- ]
952
- }
953
- },
954
- {
955
- "type": "PREC_LEFT",
956
- "value": 4,
957
- "content": {
958
- "type": "SEQ",
959
- "members": [
960
- {
961
- "type": "FIELD",
962
- "name": "left",
963
- "content": {
964
- "type": "SYMBOL",
965
- "name": "_const_expression"
966
- }
967
- },
968
- {
969
- "type": "FIELD",
970
- "name": "operator",
971
- "content": {
972
- "type": "STRING",
973
- "value": ">"
974
- }
975
- },
976
- {
977
- "type": "FIELD",
978
- "name": "right",
979
- "content": {
980
- "type": "SYMBOL",
981
- "name": "_const_expression"
982
- }
983
- }
984
- ]
985
- }
986
- },
987
- {
988
- "type": "PREC_LEFT",
989
- "value": 4,
990
- "content": {
991
- "type": "SEQ",
992
- "members": [
993
- {
994
- "type": "FIELD",
995
- "name": "left",
996
- "content": {
997
- "type": "SYMBOL",
998
- "name": "_const_expression"
999
- }
1000
- },
1001
- {
1002
- "type": "FIELD",
1003
- "name": "operator",
1004
- "content": {
1005
- "type": "STRING",
1006
- "value": ">="
1007
- }
1008
- },
1009
- {
1010
- "type": "FIELD",
1011
- "name": "right",
1012
- "content": {
1013
- "type": "SYMBOL",
1014
- "name": "_const_expression"
1015
- }
1016
- }
1017
- ]
1018
- }
1019
- },
1020
- {
1021
- "type": "PREC_LEFT",
1022
- "value": 5,
1023
- "content": {
1024
- "type": "SEQ",
1025
- "members": [
1026
- {
1027
- "type": "FIELD",
1028
- "name": "left",
1029
- "content": {
1030
- "type": "SYMBOL",
1031
- "name": "_const_expression"
1032
- }
1033
- },
1034
- {
1035
- "type": "FIELD",
1036
- "name": "operator",
1037
- "content": {
1038
- "type": "STRING",
1039
- "value": "|>"
1040
- }
1041
- },
1042
- {
1043
- "type": "FIELD",
1044
- "name": "right",
1045
- "content": {
1046
- "type": "SYMBOL",
1047
- "name": "_const_expression"
1048
- }
1049
- }
1050
- ]
1051
- }
1052
- },
1053
- {
1054
- "type": "PREC_LEFT",
1055
- "value": 6,
1056
- "content": {
1057
- "type": "SEQ",
1058
- "members": [
1059
- {
1060
- "type": "FIELD",
1061
- "name": "left",
1062
- "content": {
1063
- "type": "SYMBOL",
1064
- "name": "_const_expression"
1065
- }
1066
- },
1067
- {
1068
- "type": "FIELD",
1069
- "name": "operator",
1070
- "content": {
1071
- "type": "STRING",
1072
- "value": "+"
1073
- }
1074
- },
1075
- {
1076
- "type": "FIELD",
1077
- "name": "right",
1078
- "content": {
1079
- "type": "SYMBOL",
1080
- "name": "_const_expression"
1081
- }
1082
- }
1083
- ]
1084
- }
1085
- },
1086
- {
1087
- "type": "PREC_LEFT",
1088
- "value": 6,
1089
- "content": {
1090
- "type": "SEQ",
1091
- "members": [
1092
- {
1093
- "type": "FIELD",
1094
- "name": "left",
1095
- "content": {
1096
- "type": "SYMBOL",
1097
- "name": "_const_expression"
1098
- }
1099
- },
1100
- {
1101
- "type": "FIELD",
1102
- "name": "operator",
1103
- "content": {
1104
- "type": "STRING",
1105
- "value": "-"
1106
- }
1107
- },
1108
- {
1109
- "type": "FIELD",
1110
- "name": "right",
1111
- "content": {
1112
- "type": "SYMBOL",
1113
- "name": "_const_expression"
1114
- }
1115
- }
1116
- ]
1117
- }
1118
- },
1119
- {
1120
- "type": "PREC_LEFT",
1121
- "value": 7,
1122
- "content": {
1123
- "type": "SEQ",
1124
- "members": [
1125
- {
1126
- "type": "FIELD",
1127
- "name": "left",
1128
- "content": {
1129
- "type": "SYMBOL",
1130
- "name": "_const_expression"
1131
- }
1132
- },
1133
- {
1134
- "type": "FIELD",
1135
- "name": "operator",
1136
- "content": {
1137
- "type": "STRING",
1138
- "value": "*"
1139
- }
1140
- },
1141
- {
1142
- "type": "FIELD",
1143
- "name": "right",
1144
- "content": {
1145
- "type": "SYMBOL",
1146
- "name": "_const_expression"
1147
- }
1148
- }
1149
- ]
1150
- }
1151
- },
1152
- {
1153
- "type": "PREC_LEFT",
1154
- "value": 7,
1155
- "content": {
1156
- "type": "SEQ",
1157
- "members": [
1158
- {
1159
- "type": "FIELD",
1160
- "name": "left",
1161
- "content": {
1162
- "type": "SYMBOL",
1163
- "name": "_const_expression"
1164
- }
1165
- },
1166
- {
1167
- "type": "FIELD",
1168
- "name": "operator",
1169
- "content": {
1170
- "type": "STRING",
1171
- "value": "/"
1172
- }
1173
- },
1174
- {
1175
- "type": "FIELD",
1176
- "name": "right",
1177
- "content": {
1178
- "type": "SYMBOL",
1179
- "name": "_const_expression"
1180
- }
1181
- }
1182
- ]
1183
- }
1184
- },
1185
- {
1186
- "type": "PREC_LEFT",
1187
- "value": 7,
1188
- "content": {
1189
- "type": "SEQ",
1190
- "members": [
1191
- {
1192
- "type": "FIELD",
1193
- "name": "left",
1194
- "content": {
1195
- "type": "SYMBOL",
1196
- "name": "_const_expression"
1197
- }
1198
- },
1199
- {
1200
- "type": "FIELD",
1201
- "name": "operator",
1202
- "content": {
1203
- "type": "STRING",
1204
- "value": "%"
1205
- }
1206
- },
1207
- {
1208
- "type": "FIELD",
1209
- "name": "right",
1210
- "content": {
1211
- "type": "SYMBOL",
1212
- "name": "_const_expression"
1213
- }
1214
- }
1215
- ]
1216
- }
1217
- },
1218
- {
1219
- "type": "PREC_LEFT",
1220
- "value": 7,
1221
- "content": {
1222
- "type": "SEQ",
1223
- "members": [
1224
- {
1225
- "type": "FIELD",
1226
- "name": "left",
1227
- "content": {
1228
- "type": "SYMBOL",
1229
- "name": "_const_expression"
1230
- }
1231
- },
1232
- {
1233
- "type": "FIELD",
1234
- "name": "operator",
1235
- "content": {
1236
- "type": "STRING",
1237
- "value": "<>"
1238
- }
1239
- },
1240
- {
1241
- "type": "FIELD",
1242
- "name": "right",
1243
- "content": {
1244
- "type": "SYMBOL",
1245
- "name": "_const_expression"
1246
- }
1247
- }
1248
- ]
1249
- }
1250
- }
1251
- ]
1252
- },
1253
- "_const_expression_unit": {
1254
- "type": "CHOICE",
1255
- "members": [
1256
- {
1257
- "type": "SYMBOL",
1258
- "name": "string"
1259
- },
1260
- {
1261
- "type": "SYMBOL",
1262
- "name": "integer"
1263
- },
1264
- {
1265
- "type": "SYMBOL",
1266
- "name": "float"
1267
- },
1268
- {
1269
- "type": "SYMBOL",
1270
- "name": "const_record"
1271
- },
1272
- {
1273
- "type": "SYMBOL",
1274
- "name": "const_function_call"
1275
- }
1276
- ]
1277
- },
1278
- "const_record": {
1279
- "type": "SEQ",
1280
- "members": [
1281
- {
1282
- "type": "FIELD",
1283
- "name": "name",
1284
- "content": {
1285
- "type": "CHOICE",
1286
- "members": [
1287
- {
1288
- "type": "SYMBOL",
1289
- "name": "constructor_name"
1290
- },
1291
- {
1292
- "type": "SYMBOL",
1293
- "name": "remote_constructor_name"
1294
- }
1295
- ]
1296
- }
1297
- },
1298
- {
1299
- "type": "CHOICE",
1300
- "members": [
1301
- {
1302
- "type": "FIELD",
1303
- "name": "arguments",
1304
- "content": {
1305
- "type": "SYMBOL",
1306
- "name": "arguments"
1307
- }
1308
- },
1309
- {
1310
- "type": "BLANK"
1311
- }
1312
- ]
1313
- }
1314
- ]
1315
- },
1316
- "const_function_call": {
1317
- "type": "SEQ",
1318
- "members": [
1319
- {
1320
- "type": "FIELD",
1321
- "name": "function",
1322
- "content": {
1323
- "type": "CHOICE",
1324
- "members": [
1325
- {
1326
- "type": "SYMBOL",
1327
- "name": "function_name"
1328
- },
1329
- {
1330
- "type": "SYMBOL",
1331
- "name": "remote_function_identifier"
1332
- }
1333
- ]
1334
- }
1335
- },
1336
- {
1337
- "type": "FIELD",
1338
- "name": "arguments",
1339
- "content": {
1340
- "type": "SYMBOL",
1341
- "name": "const_arguments"
1342
- }
1343
- }
1344
- ]
1345
- },
1346
- "const_arguments": {
1347
- "type": "SEQ",
1348
- "members": [
1349
- {
1350
- "type": "STRING",
1351
- "value": "("
1352
- },
1353
- {
1354
- "type": "CHOICE",
1355
- "members": [
1356
- {
1357
- "type": "SEQ",
1358
- "members": [
1359
- {
1360
- "type": "SYMBOL",
1361
- "name": "const_argument"
1362
- },
1363
- {
1364
- "type": "REPEAT",
1365
- "content": {
1366
- "type": "SEQ",
1367
- "members": [
1368
- {
1369
- "type": "STRING",
1370
- "value": ","
1371
- },
1372
- {
1373
- "type": "SYMBOL",
1374
- "name": "const_argument"
1375
- }
1376
- ]
1377
- }
1378
- },
1379
- {
1380
- "type": "CHOICE",
1381
- "members": [
1382
- {
1383
- "type": "STRING",
1384
- "value": ","
1385
- },
1386
- {
1387
- "type": "BLANK"
1388
- }
1389
- ]
1390
- }
1391
- ]
1392
- },
1393
- {
1394
- "type": "BLANK"
1395
- }
1396
- ]
1397
- },
1398
- {
1399
- "type": "STRING",
1400
- "value": ")"
1401
- }
1402
- ]
1403
- },
1404
- "const_argument": {
1405
- "type": "SEQ",
1406
- "members": [
1407
- {
1408
- "type": "CHOICE",
1409
- "members": [
1410
- {
1411
- "type": "SEQ",
1412
- "members": [
1413
- {
1414
- "type": "FIELD",
1415
- "name": "label",
1416
- "content": {
1417
- "type": "SYMBOL",
1418
- "name": "label"
1419
- }
1420
- },
1421
- {
1422
- "type": "STRING",
1423
- "value": ":"
1424
- }
1425
- ]
1426
- },
1427
- {
1428
- "type": "BLANK"
1429
- }
1430
- ]
1431
- },
1432
- {
1433
- "type": "FIELD",
1434
- "name": "value",
1435
- "content": {
1436
- "type": "SYMBOL",
1437
- "name": "_const_expression"
1438
- }
1439
- }
1440
- ]
1441
- },
1442
- "_name_param": {
1443
- "type": "FIELD",
1444
- "name": "name",
1445
- "content": {
1446
- "type": "SYMBOL",
1447
- "name": "identifier"
1448
- }
1449
- },
1450
- "_statement_seq": {
1451
- "type": "REPEAT1",
1452
- "content": {
1453
- "type": "SYMBOL",
1454
- "name": "_statement"
1455
- }
1456
- },
1457
- "_statement": {
1458
- "type": "CHOICE",
1459
- "members": [
1460
- {
1461
- "type": "SYMBOL",
1462
- "name": "_expression"
1463
- },
1464
- {
1465
- "type": "SYMBOL",
1466
- "name": "let"
1467
- }
1468
- ]
1469
- },
1470
- "_expression": {
1471
- "type": "CHOICE",
1472
- "members": [
1473
- {
1474
- "type": "SYMBOL",
1475
- "name": "_expression_unit"
1476
- },
1477
- {
1478
- "type": "SYMBOL",
1479
- "name": "binary_expression"
1480
- }
1481
- ]
1482
- },
1483
- "binary_expression": {
1484
- "type": "CHOICE",
1485
- "members": [
1486
- {
1487
- "type": "PREC_LEFT",
1488
- "value": 1,
1489
- "content": {
1490
- "type": "SEQ",
1491
- "members": [
1492
- {
1493
- "type": "FIELD",
1494
- "name": "left",
1495
- "content": {
1496
- "type": "SYMBOL",
1497
- "name": "_expression"
1498
- }
1499
- },
1500
- {
1501
- "type": "FIELD",
1502
- "name": "operator",
1503
- "content": {
1504
- "type": "STRING",
1505
- "value": "||"
1506
- }
1507
- },
1508
- {
1509
- "type": "FIELD",
1510
- "name": "right",
1511
- "content": {
1512
- "type": "SYMBOL",
1513
- "name": "_expression"
1514
- }
1515
- }
1516
- ]
1517
- }
1518
- },
1519
- {
1520
- "type": "PREC_LEFT",
1521
- "value": 2,
1522
- "content": {
1523
- "type": "SEQ",
1524
- "members": [
1525
- {
1526
- "type": "FIELD",
1527
- "name": "left",
1528
- "content": {
1529
- "type": "SYMBOL",
1530
- "name": "_expression"
1531
- }
1532
- },
1533
- {
1534
- "type": "FIELD",
1535
- "name": "operator",
1536
- "content": {
1537
- "type": "STRING",
1538
- "value": "&&"
1539
- }
1540
- },
1541
- {
1542
- "type": "FIELD",
1543
- "name": "right",
1544
- "content": {
1545
- "type": "SYMBOL",
1546
- "name": "_expression"
1547
- }
1548
- }
1549
- ]
1550
- }
1551
- },
1552
- {
1553
- "type": "PREC_LEFT",
1554
- "value": 3,
1555
- "content": {
1556
- "type": "SEQ",
1557
- "members": [
1558
- {
1559
- "type": "FIELD",
1560
- "name": "left",
1561
- "content": {
1562
- "type": "SYMBOL",
1563
- "name": "_expression"
1564
- }
1565
- },
1566
- {
1567
- "type": "FIELD",
1568
- "name": "operator",
1569
- "content": {
1570
- "type": "STRING",
1571
- "value": "=="
1572
- }
1573
- },
1574
- {
1575
- "type": "FIELD",
1576
- "name": "right",
1577
- "content": {
1578
- "type": "SYMBOL",
1579
- "name": "_expression"
1580
- }
1581
- }
1582
- ]
1583
- }
1584
- },
1585
- {
1586
- "type": "PREC_LEFT",
1587
- "value": 3,
1588
- "content": {
1589
- "type": "SEQ",
1590
- "members": [
1591
- {
1592
- "type": "FIELD",
1593
- "name": "left",
1594
- "content": {
1595
- "type": "SYMBOL",
1596
- "name": "_expression"
1597
- }
1598
- },
1599
- {
1600
- "type": "FIELD",
1601
- "name": "operator",
1602
- "content": {
1603
- "type": "STRING",
1604
- "value": "!="
1605
- }
1606
- },
1607
- {
1608
- "type": "FIELD",
1609
- "name": "right",
1610
- "content": {
1611
- "type": "SYMBOL",
1612
- "name": "_expression"
1613
- }
1614
- }
1615
- ]
1616
- }
1617
- },
1618
- {
1619
- "type": "PREC_LEFT",
1620
- "value": 4,
1621
- "content": {
1622
- "type": "SEQ",
1623
- "members": [
1624
- {
1625
- "type": "FIELD",
1626
- "name": "left",
1627
- "content": {
1628
- "type": "SYMBOL",
1629
- "name": "_expression"
1630
- }
1631
- },
1632
- {
1633
- "type": "FIELD",
1634
- "name": "operator",
1635
- "content": {
1636
- "type": "STRING",
1637
- "value": "<"
1638
- }
1639
- },
1640
- {
1641
- "type": "FIELD",
1642
- "name": "right",
1643
- "content": {
1644
- "type": "SYMBOL",
1645
- "name": "_expression"
1646
- }
1647
- }
1648
- ]
1649
- }
1650
- },
1651
- {
1652
- "type": "PREC_LEFT",
1653
- "value": 4,
1654
- "content": {
1655
- "type": "SEQ",
1656
- "members": [
1657
- {
1658
- "type": "FIELD",
1659
- "name": "left",
1660
- "content": {
1661
- "type": "SYMBOL",
1662
- "name": "_expression"
1663
- }
1664
- },
1665
- {
1666
- "type": "FIELD",
1667
- "name": "operator",
1668
- "content": {
1669
- "type": "STRING",
1670
- "value": "<="
1671
- }
1672
- },
1673
- {
1674
- "type": "FIELD",
1675
- "name": "right",
1676
- "content": {
1677
- "type": "SYMBOL",
1678
- "name": "_expression"
1679
- }
1680
- }
1681
- ]
1682
- }
1683
- },
1684
- {
1685
- "type": "PREC_LEFT",
1686
- "value": 4,
1687
- "content": {
1688
- "type": "SEQ",
1689
- "members": [
1690
- {
1691
- "type": "FIELD",
1692
- "name": "left",
1693
- "content": {
1694
- "type": "SYMBOL",
1695
- "name": "_expression"
1696
- }
1697
- },
1698
- {
1699
- "type": "FIELD",
1700
- "name": "operator",
1701
- "content": {
1702
- "type": "STRING",
1703
- "value": ">"
1704
- }
1705
- },
1706
- {
1707
- "type": "FIELD",
1708
- "name": "right",
1709
- "content": {
1710
- "type": "SYMBOL",
1711
- "name": "_expression"
1712
- }
1713
- }
1714
- ]
1715
- }
1716
- },
1717
- {
1718
- "type": "PREC_LEFT",
1719
- "value": 4,
1720
- "content": {
1721
- "type": "SEQ",
1722
- "members": [
1723
- {
1724
- "type": "FIELD",
1725
- "name": "left",
1726
- "content": {
1727
- "type": "SYMBOL",
1728
- "name": "_expression"
1729
- }
1730
- },
1731
- {
1732
- "type": "FIELD",
1733
- "name": "operator",
1734
- "content": {
1735
- "type": "STRING",
1736
- "value": ">="
1737
- }
1738
- },
1739
- {
1740
- "type": "FIELD",
1741
- "name": "right",
1742
- "content": {
1743
- "type": "SYMBOL",
1744
- "name": "_expression"
1745
- }
1746
- }
1747
- ]
1748
- }
1749
- },
1750
- {
1751
- "type": "PREC_LEFT",
1752
- "value": 5,
1753
- "content": {
1754
- "type": "SEQ",
1755
- "members": [
1756
- {
1757
- "type": "FIELD",
1758
- "name": "left",
1759
- "content": {
1760
- "type": "SYMBOL",
1761
- "name": "_expression"
1762
- }
1763
- },
1764
- {
1765
- "type": "FIELD",
1766
- "name": "operator",
1767
- "content": {
1768
- "type": "STRING",
1769
- "value": "|>"
1770
- }
1771
- },
1772
- {
1773
- "type": "FIELD",
1774
- "name": "right",
1775
- "content": {
1776
- "type": "SYMBOL",
1777
- "name": "_expression"
1778
- }
1779
- }
1780
- ]
1781
- }
1782
- },
1783
- {
1784
- "type": "PREC_LEFT",
1785
- "value": 6,
1786
- "content": {
1787
- "type": "SEQ",
1788
- "members": [
1789
- {
1790
- "type": "FIELD",
1791
- "name": "left",
1792
- "content": {
1793
- "type": "SYMBOL",
1794
- "name": "_expression"
1795
- }
1796
- },
1797
- {
1798
- "type": "FIELD",
1799
- "name": "operator",
1800
- "content": {
1801
- "type": "STRING",
1802
- "value": "+"
1803
- }
1804
- },
1805
- {
1806
- "type": "FIELD",
1807
- "name": "right",
1808
- "content": {
1809
- "type": "SYMBOL",
1810
- "name": "_expression"
1811
- }
1812
- }
1813
- ]
1814
- }
1815
- },
1816
- {
1817
- "type": "PREC_LEFT",
1818
- "value": 6,
1819
- "content": {
1820
- "type": "SEQ",
1821
- "members": [
1822
- {
1823
- "type": "FIELD",
1824
- "name": "left",
1825
- "content": {
1826
- "type": "SYMBOL",
1827
- "name": "_expression"
1828
- }
1829
- },
1830
- {
1831
- "type": "FIELD",
1832
- "name": "operator",
1833
- "content": {
1834
- "type": "STRING",
1835
- "value": "-"
1836
- }
1837
- },
1838
- {
1839
- "type": "FIELD",
1840
- "name": "right",
1841
- "content": {
1842
- "type": "SYMBOL",
1843
- "name": "_expression"
1844
- }
1845
- }
1846
- ]
1847
- }
1848
- },
1849
- {
1850
- "type": "PREC_LEFT",
1851
- "value": 7,
1852
- "content": {
1853
- "type": "SEQ",
1854
- "members": [
1855
- {
1856
- "type": "FIELD",
1857
- "name": "left",
1858
- "content": {
1859
- "type": "SYMBOL",
1860
- "name": "_expression"
1861
- }
1862
- },
1863
- {
1864
- "type": "FIELD",
1865
- "name": "operator",
1866
- "content": {
1867
- "type": "STRING",
1868
- "value": "*"
1869
- }
1870
- },
1871
- {
1872
- "type": "FIELD",
1873
- "name": "right",
1874
- "content": {
1875
- "type": "SYMBOL",
1876
- "name": "_expression"
1877
- }
1878
- }
1879
- ]
1880
- }
1881
- },
1882
- {
1883
- "type": "PREC_LEFT",
1884
- "value": 7,
1885
- "content": {
1886
- "type": "SEQ",
1887
- "members": [
1888
- {
1889
- "type": "FIELD",
1890
- "name": "left",
1891
- "content": {
1892
- "type": "SYMBOL",
1893
- "name": "_expression"
1894
- }
1895
- },
1896
- {
1897
- "type": "FIELD",
1898
- "name": "operator",
1899
- "content": {
1900
- "type": "STRING",
1901
- "value": "/"
1902
- }
1903
- },
1904
- {
1905
- "type": "FIELD",
1906
- "name": "right",
1907
- "content": {
1908
- "type": "SYMBOL",
1909
- "name": "_expression"
1910
- }
1911
- }
1912
- ]
1913
- }
1914
- },
1915
- {
1916
- "type": "PREC_LEFT",
1917
- "value": 7,
1918
- "content": {
1919
- "type": "SEQ",
1920
- "members": [
1921
- {
1922
- "type": "FIELD",
1923
- "name": "left",
1924
- "content": {
1925
- "type": "SYMBOL",
1926
- "name": "_expression"
1927
- }
1928
- },
1929
- {
1930
- "type": "FIELD",
1931
- "name": "operator",
1932
- "content": {
1933
- "type": "STRING",
1934
- "value": "%"
1935
- }
1936
- },
1937
- {
1938
- "type": "FIELD",
1939
- "name": "right",
1940
- "content": {
1941
- "type": "SYMBOL",
1942
- "name": "_expression"
1943
- }
1944
- }
1945
- ]
1946
- }
1947
- },
1948
- {
1949
- "type": "PREC_LEFT",
1950
- "value": 7,
1951
- "content": {
1952
- "type": "SEQ",
1953
- "members": [
1954
- {
1955
- "type": "FIELD",
1956
- "name": "left",
1957
- "content": {
1958
- "type": "SYMBOL",
1959
- "name": "_expression"
1960
- }
1961
- },
1962
- {
1963
- "type": "FIELD",
1964
- "name": "operator",
1965
- "content": {
1966
- "type": "STRING",
1967
- "value": "<>"
1968
- }
1969
- },
1970
- {
1971
- "type": "FIELD",
1972
- "name": "right",
1973
- "content": {
1974
- "type": "SYMBOL",
1975
- "name": "_expression"
1976
- }
1977
- }
1978
- ]
1979
- }
1980
- }
1981
- ]
1982
- },
1983
- "_expression_unit": {
1984
- "type": "CHOICE",
1985
- "members": [
1986
- {
1987
- "type": "SYMBOL",
1988
- "name": "string"
1989
- },
1990
- {
1991
- "type": "SYMBOL",
1992
- "name": "integer"
1993
- },
1994
- {
1995
- "type": "SYMBOL",
1996
- "name": "float"
1997
- },
1998
- {
1999
- "type": "SYMBOL",
2000
- "name": "record"
2001
- },
2002
- {
2003
- "type": "SYMBOL",
2004
- "name": "identifier"
2005
- },
2006
- {
2007
- "type": "SYMBOL",
2008
- "name": "anonymous_function"
2009
- },
2010
- {
2011
- "type": "SYMBOL",
2012
- "name": "expression_group"
2013
- },
2014
- {
2015
- "type": "SYMBOL",
2016
- "name": "if"
2017
- },
2018
- {
2019
- "type": "SYMBOL",
2020
- "name": "when"
2021
- },
2022
- {
2023
- "type": "SYMBOL",
2024
- "name": "negation"
2025
- },
2026
- {
2027
- "type": "SYMBOL",
2028
- "name": "record_update"
2029
- },
2030
- {
2031
- "type": "SYMBOL",
2032
- "name": "field_access"
2033
- },
2034
- {
2035
- "type": "SYMBOL",
2036
- "name": "function_call"
2037
- }
2038
- ]
2039
- },
2040
- "record": {
2041
- "type": "SEQ",
2042
- "members": [
2043
- {
2044
- "type": "FIELD",
2045
- "name": "name",
2046
- "content": {
2047
- "type": "SYMBOL",
2048
- "name": "constructor_name"
2049
- }
2050
- },
2051
- {
2052
- "type": "CHOICE",
2053
- "members": [
2054
- {
2055
- "type": "FIELD",
2056
- "name": "arguments",
2057
- "content": {
2058
- "type": "SYMBOL",
2059
- "name": "arguments"
2060
- }
2061
- },
2062
- {
2063
- "type": "BLANK"
2064
- }
2065
- ]
2066
- }
2067
- ]
2068
- },
2069
- "list": {
2070
- "type": "SEQ",
2071
- "members": [
2072
- {
2073
- "type": "STRING",
2074
- "value": "["
2075
- },
2076
- {
2077
- "type": "CHOICE",
2078
- "members": [
2079
- {
2080
- "type": "SEQ",
2081
- "members": [
2082
- {
2083
- "type": "SYMBOL",
2084
- "name": "_expression"
2085
- },
2086
- {
2087
- "type": "CHOICE",
2088
- "members": [
2089
- {
2090
- "type": "REPEAT",
2091
- "content": {
2092
- "type": "SEQ",
2093
- "members": [
2094
- {
2095
- "type": "STRING",
2096
- "value": ","
2097
- },
2098
- {
2099
- "type": "SYMBOL",
2100
- "name": "_expression"
2101
- }
2102
- ]
2103
- }
2104
- },
2105
- {
2106
- "type": "BLANK"
2107
- }
2108
- ]
2109
- },
2110
- {
2111
- "type": "CHOICE",
2112
- "members": [
2113
- {
2114
- "type": "STRING",
2115
- "value": ","
2116
- },
2117
- {
2118
- "type": "BLANK"
2119
- }
2120
- ]
2121
- },
2122
- {
2123
- "type": "CHOICE",
2124
- "members": [
2125
- {
2126
- "type": "SEQ",
2127
- "members": [
2128
- {
2129
- "type": "STRING",
2130
- "value": ".."
2131
- },
2132
- {
2133
- "type": "FIELD",
2134
- "name": "spread",
2135
- "content": {
2136
- "type": "SYMBOL",
2137
- "name": "_expression"
2138
- }
2139
- }
2140
- ]
2141
- },
2142
- {
2143
- "type": "BLANK"
2144
- }
2145
- ]
2146
- }
2147
- ]
2148
- },
2149
- {
2150
- "type": "BLANK"
2151
- }
2152
- ]
2153
- },
2154
- {
2155
- "type": "STRING",
2156
- "value": "]"
2157
- }
2158
- ]
2159
- },
2160
- "anonymous_function": {
2161
- "type": "SEQ",
2162
- "members": [
2163
- {
2164
- "type": "STRING",
2165
- "value": "fn"
2166
- },
2167
- {
2168
- "type": "FIELD",
2169
- "name": "parameters",
2170
- "content": {
2171
- "type": "ALIAS",
2172
- "content": {
2173
- "type": "SYMBOL",
2174
- "name": "anonymous_function_parameters"
2175
- },
2176
- "named": true,
2177
- "value": "function_parameters"
2178
- }
2179
- },
2180
- {
2181
- "type": "CHOICE",
2182
- "members": [
2183
- {
2184
- "type": "SEQ",
2185
- "members": [
2186
- {
2187
- "type": "STRING",
2188
- "value": "->"
2189
- },
2190
- {
2191
- "type": "FIELD",
2192
- "name": "return_type",
2193
- "content": {
2194
- "type": "SYMBOL",
2195
- "name": "_type"
2196
- }
2197
- }
2198
- ]
2199
- },
2200
- {
2201
- "type": "BLANK"
2202
- }
2203
- ]
2204
- },
2205
- {
2206
- "type": "STRING",
2207
- "value": "{"
2208
- },
2209
- {
2210
- "type": "FIELD",
2211
- "name": "body",
2212
- "content": {
2213
- "type": "ALIAS",
2214
- "content": {
2215
- "type": "SYMBOL",
2216
- "name": "_statement_seq"
2217
- },
2218
- "named": true,
2219
- "value": "function_body"
2220
- }
2221
- },
2222
- {
2223
- "type": "STRING",
2224
- "value": "}"
2225
- }
2226
- ]
2227
- },
2228
- "anonymous_function_parameters": {
2229
- "type": "SEQ",
2230
- "members": [
2231
- {
2232
- "type": "STRING",
2233
- "value": "("
2234
- },
2235
- {
2236
- "type": "CHOICE",
2237
- "members": [
2238
- {
2239
- "type": "SEQ",
2240
- "members": [
2241
- {
2242
- "type": "ALIAS",
2243
- "content": {
2244
- "type": "SYMBOL",
2245
- "name": "anonymous_function_parameter"
2246
- },
2247
- "named": true,
2248
- "value": "function_parameter"
2249
- },
2250
- {
2251
- "type": "REPEAT",
2252
- "content": {
2253
- "type": "SEQ",
2254
- "members": [
2255
- {
2256
- "type": "STRING",
2257
- "value": ","
2258
- },
2259
- {
2260
- "type": "ALIAS",
2261
- "content": {
2262
- "type": "SYMBOL",
2263
- "name": "anonymous_function_parameter"
2264
- },
2265
- "named": true,
2266
- "value": "function_parameter"
2267
- }
2268
- ]
2269
- }
2270
- },
2271
- {
2272
- "type": "CHOICE",
2273
- "members": [
2274
- {
2275
- "type": "STRING",
2276
- "value": ","
2277
- },
2278
- {
2279
- "type": "BLANK"
2280
- }
2281
- ]
2282
- }
2283
- ]
2284
- },
2285
- {
2286
- "type": "BLANK"
2287
- }
2288
- ]
2289
- },
2290
- {
2291
- "type": "STRING",
2292
- "value": ")"
2293
- }
2294
- ]
2295
- },
2296
- "_discard_param": {
2297
- "type": "FIELD",
2298
- "name": "name",
2299
- "content": {
2300
- "type": "SYMBOL",
2301
- "name": "discard"
2302
- }
2303
- },
2304
- "anonymous_function_parameter": {
2305
- "type": "SEQ",
2306
- "members": [
2307
- {
2308
- "type": "CHOICE",
2309
- "members": [
2310
- {
2311
- "type": "SYMBOL",
2312
- "name": "_discard_param"
2313
- },
2314
- {
2315
- "type": "SYMBOL",
2316
- "name": "_name_param"
2317
- }
2318
- ]
2319
- },
2320
- {
2321
- "type": "CHOICE",
2322
- "members": [
2323
- {
2324
- "type": "SYMBOL",
2325
- "name": "_type_annotation"
2326
- },
2327
- {
2328
- "type": "BLANK"
2329
- }
2330
- ]
2331
- }
2332
- ]
2333
- },
2334
- "expression_group": {
2335
- "type": "SEQ",
2336
- "members": [
2337
- {
2338
- "type": "STRING",
2339
- "value": "{"
2340
- },
2341
- {
2342
- "type": "SYMBOL",
2343
- "name": "_statement_seq"
2344
- },
2345
- {
2346
- "type": "STRING",
2347
- "value": "}"
2348
- }
2349
- ]
2350
- },
2351
- "when": {
2352
- "type": "SEQ",
2353
- "members": [
2354
- {
2355
- "type": "STRING",
2356
- "value": "when"
2357
- },
2358
- {
2359
- "type": "CHOICE",
2360
- "members": [
2361
- {
2362
- "type": "SYMBOL",
2363
- "name": "_expression"
2364
- },
2365
- {
2366
- "type": "BLANK"
2367
- }
2368
- ]
2369
- },
2370
- {
2371
- "type": "STRING",
2372
- "value": "{"
2373
- },
2374
- {
2375
- "type": "REPEAT",
2376
- "content": {
2377
- "type": "SYMBOL",
2378
- "name": "when_entry"
2379
- }
2380
- },
2381
- {
2382
- "type": "STRING",
2383
- "value": "}"
2384
- }
2385
- ]
2386
- },
2387
- "if": {
2388
- "type": "SEQ",
2389
- "members": [
2390
- {
2391
- "type": "STRING",
2392
- "value": "if"
2393
- },
2394
- {
2395
- "type": "SYMBOL",
2396
- "name": "_expression"
2397
- },
2398
- {
2399
- "type": "STRING",
2400
- "value": "{"
2401
- },
2402
- {
2403
- "type": "REPEAT",
2404
- "content": {
2405
- "type": "SYMBOL",
2406
- "name": "_expression"
2407
- }
2408
- },
2409
- {
2410
- "type": "STRING",
2411
- "value": "}"
2412
- }
2413
- ]
2414
- },
2415
- "when_entry": {
2416
- "type": "SEQ",
2417
- "members": [
2418
- {
2419
- "type": "CHOICE",
2420
- "members": [
2421
- {
2422
- "type": "SYMBOL",
2423
- "name": "_expression"
2424
- },
2425
- {
2426
- "type": "STRING",
2427
- "value": "_"
2428
- }
2429
- ]
2430
- },
2431
- {
2432
- "type": "STRING",
2433
- "value": "->"
2434
- },
2435
- {
2436
- "type": "SYMBOL",
2437
- "name": "_expression"
2438
- }
2439
- ]
2440
- },
2441
- "_maybe_record_expression": {
2442
- "type": "CHOICE",
2443
- "members": [
2444
- {
2445
- "type": "SYMBOL",
2446
- "name": "record"
2447
- },
2448
- {
2449
- "type": "SYMBOL",
2450
- "name": "identifier"
2451
- },
2452
- {
2453
- "type": "SYMBOL",
2454
- "name": "function_call"
2455
- },
2456
- {
2457
- "type": "SYMBOL",
2458
- "name": "expression_group"
2459
- },
2460
- {
2461
- "type": "SYMBOL",
2462
- "name": "if"
2463
- },
2464
- {
2465
- "type": "SYMBOL",
2466
- "name": "when"
2467
- },
2468
- {
2469
- "type": "SYMBOL",
2470
- "name": "field_access"
2471
- }
2472
- ]
2473
- },
2474
- "_maybe_function_expression": {
2475
- "type": "CHOICE",
2476
- "members": [
2477
- {
2478
- "type": "SYMBOL",
2479
- "name": "identifier"
2480
- },
2481
- {
2482
- "type": "SYMBOL",
2483
- "name": "anonymous_function"
2484
- },
2485
- {
2486
- "type": "SYMBOL",
2487
- "name": "expression_group"
2488
- },
2489
- {
2490
- "type": "SYMBOL",
2491
- "name": "if"
2492
- },
2493
- {
2494
- "type": "SYMBOL",
2495
- "name": "when"
2496
- },
2497
- {
2498
- "type": "SYMBOL",
2499
- "name": "field_access"
2500
- },
2501
- {
2502
- "type": "SYMBOL",
2503
- "name": "function_call"
2504
- }
2505
- ]
2506
- },
2507
- "field_access": {
2508
- "type": "PREC_LEFT",
2509
- "value": 0,
2510
- "content": {
2511
- "type": "SEQ",
2512
- "members": [
2513
- {
2514
- "type": "FIELD",
2515
- "name": "record",
2516
- "content": {
2517
- "type": "SYMBOL",
2518
- "name": "_maybe_record_expression"
2519
- }
2520
- },
2521
- {
2522
- "type": "STRING",
2523
- "value": "."
2524
- },
2525
- {
2526
- "type": "FIELD",
2527
- "name": "field",
2528
- "content": {
2529
- "type": "SYMBOL",
2530
- "name": "label"
2531
- }
2532
- }
2533
- ]
2534
- }
2535
- },
2536
- "arguments": {
2537
- "type": "SEQ",
2538
- "members": [
2539
- {
2540
- "type": "STRING",
2541
- "value": "("
2542
- },
2543
- {
2544
- "type": "CHOICE",
2545
- "members": [
2546
- {
2547
- "type": "SEQ",
2548
- "members": [
2549
- {
2550
- "type": "SYMBOL",
2551
- "name": "argument"
2552
- },
2553
- {
2554
- "type": "REPEAT",
2555
- "content": {
2556
- "type": "SEQ",
2557
- "members": [
2558
- {
2559
- "type": "STRING",
2560
- "value": ","
2561
- },
2562
- {
2563
- "type": "SYMBOL",
2564
- "name": "argument"
2565
- }
2566
- ]
2567
- }
2568
- },
2569
- {
2570
- "type": "CHOICE",
2571
- "members": [
2572
- {
2573
- "type": "STRING",
2574
- "value": ","
2575
- },
2576
- {
2577
- "type": "BLANK"
2578
- }
2579
- ]
2580
- }
2581
- ]
2582
- },
2583
- {
2584
- "type": "BLANK"
2585
- }
2586
- ]
2587
- },
2588
- {
2589
- "type": "STRING",
2590
- "value": ")"
2591
- }
2592
- ]
2593
- },
2594
- "argument": {
2595
- "type": "SEQ",
2596
- "members": [
2597
- {
2598
- "type": "CHOICE",
2599
- "members": [
2600
- {
2601
- "type": "SEQ",
2602
- "members": [
2603
- {
2604
- "type": "FIELD",
2605
- "name": "label",
2606
- "content": {
2607
- "type": "SYMBOL",
2608
- "name": "label"
2609
- }
2610
- },
2611
- {
2612
- "type": "STRING",
2613
- "value": ":"
2614
- }
2615
- ]
2616
- },
2617
- {
2618
- "type": "BLANK"
2619
- }
2620
- ]
2621
- },
2622
- {
2623
- "type": "FIELD",
2624
- "name": "value",
2625
- "content": {
2626
- "type": "CHOICE",
2627
- "members": [
2628
- {
2629
- "type": "SYMBOL",
2630
- "name": "hole"
2631
- },
2632
- {
2633
- "type": "SYMBOL",
2634
- "name": "_expression"
2635
- }
2636
- ]
2637
- }
2638
- }
2639
- ]
2640
- },
2641
- "hole": {
2642
- "type": "SYMBOL",
2643
- "name": "_discard_name"
2644
- },
2645
- "function_call": {
2646
- "type": "SEQ",
2647
- "members": [
2648
- {
2649
- "type": "FIELD",
2650
- "name": "function",
2651
- "content": {
2652
- "type": "SYMBOL",
2653
- "name": "_maybe_function_expression"
2654
- }
2655
- },
2656
- {
2657
- "type": "FIELD",
2658
- "name": "arguments",
2659
- "content": {
2660
- "type": "SYMBOL",
2661
- "name": "arguments"
2662
- }
2663
- }
2664
- ]
2665
- },
2666
- "negation": {
2667
- "type": "SEQ",
2668
- "members": [
2669
- {
2670
- "type": "STRING",
2671
- "value": "!"
2672
- },
2673
- {
2674
- "type": "SYMBOL",
2675
- "name": "_expression_unit"
2676
- }
2677
- ]
2678
- },
2679
- "let": {
2680
- "type": "SEQ",
2681
- "members": [
2682
- {
2683
- "type": "STRING",
2684
- "value": "let"
2685
- },
2686
- {
2687
- "type": "SYMBOL",
2688
- "name": "_assignment"
2689
- }
2690
- ]
2691
- },
2692
- "_assignment": {
2693
- "type": "SEQ",
2694
- "members": [
2695
- {
2696
- "type": "FIELD",
2697
- "name": "pattern",
2698
- "content": {
2699
- "type": "SYMBOL",
2700
- "name": "_pattern_expression"
2701
- }
2702
- },
2703
- {
2704
- "type": "STRING",
2705
- "value": "="
2706
- },
2707
- {
2708
- "type": "FIELD",
2709
- "name": "value",
2710
- "content": {
2711
- "type": "SYMBOL",
2712
- "name": "_expression"
2713
- }
2714
- }
2715
- ]
2716
- },
2717
- "record_update": {
2718
- "type": "SEQ",
2719
- "members": [
2720
- {
2721
- "type": "FIELD",
2722
- "name": "constructor",
2723
- "content": {
2724
- "type": "SYMBOL",
2725
- "name": "constructor_name"
2726
- }
2727
- },
2728
- {
2729
- "type": "STRING",
2730
- "value": "("
2731
- },
2732
- {
2733
- "type": "STRING",
2734
- "value": ".."
2735
- },
2736
- {
2737
- "type": "FIELD",
2738
- "name": "spread",
2739
- "content": {
2740
- "type": "SYMBOL",
2741
- "name": "_expression"
2742
- }
2743
- },
2744
- {
2745
- "type": "STRING",
2746
- "value": ","
2747
- },
2748
- {
2749
- "type": "FIELD",
2750
- "name": "arguments",
2751
- "content": {
2752
- "type": "SYMBOL",
2753
- "name": "record_update_arguments"
2754
- }
2755
- },
2756
- {
2757
- "type": "STRING",
2758
- "value": ")"
2759
- }
2760
- ]
2761
- },
2762
- "record_update_arguments": {
2763
- "type": "SEQ",
2764
- "members": [
2765
- {
2766
- "type": "SYMBOL",
2767
- "name": "record_update_argument"
2768
- },
2769
- {
2770
- "type": "REPEAT",
2771
- "content": {
2772
- "type": "SEQ",
2773
- "members": [
2774
- {
2775
- "type": "STRING",
2776
- "value": ","
2777
- },
2778
- {
2779
- "type": "SYMBOL",
2780
- "name": "record_update_argument"
2781
- }
2782
- ]
2783
- }
2784
- },
2785
- {
2786
- "type": "CHOICE",
2787
- "members": [
2788
- {
2789
- "type": "STRING",
2790
- "value": ","
2791
- },
2792
- {
2793
- "type": "BLANK"
2794
- }
2795
- ]
2796
- }
2797
- ]
2798
- },
2799
- "record_update_argument": {
2800
- "type": "SEQ",
2801
- "members": [
2802
- {
2803
- "type": "FIELD",
2804
- "name": "label",
2805
- "content": {
2806
- "type": "SYMBOL",
2807
- "name": "label"
2808
- }
2809
- },
2810
- {
2811
- "type": "STRING",
2812
- "value": ":"
2813
- },
2814
- {
2815
- "type": "FIELD",
2816
- "name": "value",
2817
- "content": {
2818
- "type": "SYMBOL",
2819
- "name": "_expression"
2820
- }
2821
- }
2822
- ]
2823
- },
2824
- "_pattern_expression": {
2825
- "type": "CHOICE",
2826
- "members": [
2827
- {
2828
- "type": "SYMBOL",
2829
- "name": "identifier"
2830
- },
2831
- {
2832
- "type": "SYMBOL",
2833
- "name": "discard"
2834
- },
2835
- {
2836
- "type": "SYMBOL",
2837
- "name": "record_pattern"
2838
- },
2839
- {
2840
- "type": "SYMBOL",
2841
- "name": "string"
2842
- },
2843
- {
2844
- "type": "SYMBOL",
2845
- "name": "integer"
2846
- },
2847
- {
2848
- "type": "SYMBOL",
2849
- "name": "float"
2850
- }
2851
- ]
2852
- },
2853
- "record_pattern": {
2854
- "type": "SEQ",
2855
- "members": [
2856
- {
2857
- "type": "FIELD",
2858
- "name": "name",
2859
- "content": {
2860
- "type": "SYMBOL",
2861
- "name": "constructor_name"
2862
- }
2863
- },
2864
- {
2865
- "type": "CHOICE",
2866
- "members": [
2867
- {
2868
- "type": "FIELD",
2869
- "name": "arguments",
2870
- "content": {
2871
- "type": "SYMBOL",
2872
- "name": "record_pattern_arguments"
2873
- }
2874
- },
2875
- {
2876
- "type": "BLANK"
2877
- }
2878
- ]
2879
- }
2880
- ]
2881
- },
2882
- "record_pattern_arguments": {
2883
- "type": "SEQ",
2884
- "members": [
2885
- {
2886
- "type": "STRING",
2887
- "value": "("
2888
- },
2889
- {
2890
- "type": "CHOICE",
2891
- "members": [
2892
- {
2893
- "type": "SEQ",
2894
- "members": [
2895
- {
2896
- "type": "SYMBOL",
2897
- "name": "record_pattern_argument"
2898
- },
2899
- {
2900
- "type": "REPEAT",
2901
- "content": {
2902
- "type": "SEQ",
2903
- "members": [
2904
- {
2905
- "type": "STRING",
2906
- "value": ","
2907
- },
2908
- {
2909
- "type": "SYMBOL",
2910
- "name": "record_pattern_argument"
2911
- }
2912
- ]
2913
- }
2914
- },
2915
- {
2916
- "type": "CHOICE",
2917
- "members": [
2918
- {
2919
- "type": "STRING",
2920
- "value": ","
2921
- },
2922
- {
2923
- "type": "BLANK"
2924
- }
2925
- ]
2926
- }
2927
- ]
2928
- },
2929
- {
2930
- "type": "BLANK"
2931
- }
2932
- ]
2933
- },
2934
- {
2935
- "type": "CHOICE",
2936
- "members": [
2937
- {
2938
- "type": "SYMBOL",
2939
- "name": "pattern_spread"
2940
- },
2941
- {
2942
- "type": "BLANK"
2943
- }
2944
- ]
2945
- },
2946
- {
2947
- "type": "STRING",
2948
- "value": ")"
2949
- }
2950
- ]
2951
- },
2952
- "record_pattern_argument": {
2953
- "type": "SEQ",
2954
- "members": [
2955
- {
2956
- "type": "CHOICE",
2957
- "members": [
2958
- {
2959
- "type": "SEQ",
2960
- "members": [
2961
- {
2962
- "type": "FIELD",
2963
- "name": "label",
2964
- "content": {
2965
- "type": "SYMBOL",
2966
- "name": "label"
2967
- }
2968
- },
2969
- {
2970
- "type": "STRING",
2971
- "value": ":"
2972
- }
2973
- ]
2974
- },
2975
- {
2976
- "type": "BLANK"
2977
- }
2978
- ]
2979
- },
2980
- {
2981
- "type": "FIELD",
2982
- "name": "pattern",
2983
- "content": {
2984
- "type": "SYMBOL",
2985
- "name": "_pattern_expression"
2986
- }
2987
- }
2988
- ]
2989
- },
2990
- "pattern_spread": {
2991
- "type": "SEQ",
2992
- "members": [
2993
- {
2994
- "type": "STRING",
2995
- "value": ".."
2996
- },
2997
- {
2998
- "type": "CHOICE",
2999
- "members": [
3000
- {
3001
- "type": "STRING",
3002
- "value": ","
3003
- },
3004
- {
3005
- "type": "BLANK"
3006
- }
3007
- ]
3008
- }
3009
- ]
3010
- },
3011
- "field": {
3012
- "type": "SEQ",
3013
- "members": [
3014
- {
3015
- "type": "FIELD",
3016
- "name": "name",
3017
- "content": {
3018
- "type": "SYMBOL",
3019
- "name": "identifier"
3020
- }
3021
- },
3022
- {
3023
- "type": "STRING",
3024
- "value": ":"
3025
- },
3026
- {
3027
- "type": "FIELD",
3028
- "name": "type",
3029
- "content": {
3030
- "type": "SYMBOL",
3031
- "name": "_type"
3032
- }
3033
- }
3034
- ]
3035
- },
3036
- "function_type": {
3037
- "type": "SEQ",
3038
- "members": [
3039
- {
3040
- "type": "STRING",
3041
- "value": "fn"
3042
- },
3043
- {
3044
- "type": "CHOICE",
3045
- "members": [
3046
- {
3047
- "type": "FIELD",
3048
- "name": "parameter_types",
3049
- "content": {
3050
- "type": "SYMBOL",
3051
- "name": "function_parameter_types"
3052
- }
3053
- },
3054
- {
3055
- "type": "BLANK"
3056
- }
3057
- ]
3058
- },
3059
- {
3060
- "type": "CHOICE",
3061
- "members": [
3062
- {
3063
- "type": "SYMBOL",
3064
- "name": "return_type"
3065
- },
3066
- {
3067
- "type": "BLANK"
3068
- }
3069
- ]
3070
- }
3071
- ]
3072
- },
3073
- "function_parameter_types": {
3074
- "type": "SEQ",
3075
- "members": [
3076
- {
3077
- "type": "STRING",
3078
- "value": "("
3079
- },
3080
- {
3081
- "type": "CHOICE",
3082
- "members": [
3083
- {
3084
- "type": "SEQ",
3085
- "members": [
3086
- {
3087
- "type": "SYMBOL",
3088
- "name": "_type"
3089
- },
3090
- {
3091
- "type": "REPEAT",
3092
- "content": {
3093
- "type": "SEQ",
3094
- "members": [
3095
- {
3096
- "type": "STRING",
3097
- "value": ","
3098
- },
3099
- {
3100
- "type": "SYMBOL",
3101
- "name": "_type"
3102
- }
3103
- ]
3104
- }
3105
- },
3106
- {
3107
- "type": "CHOICE",
3108
- "members": [
3109
- {
3110
- "type": "STRING",
3111
- "value": ","
3112
- },
3113
- {
3114
- "type": "BLANK"
3115
- }
3116
- ]
3117
- }
3118
- ]
3119
- },
3120
- {
3121
- "type": "BLANK"
3122
- }
3123
- ]
3124
- },
3125
- {
3126
- "type": "STRING",
3127
- "value": ")"
3128
- }
3129
- ]
3130
- },
3131
- "type": {
3132
- "type": "SEQ",
3133
- "members": [
3134
- {
3135
- "type": "FIELD",
3136
- "name": "name",
3137
- "content": {
3138
- "type": "SYMBOL",
3139
- "name": "type_identifier"
3140
- }
3141
- },
3142
- {
3143
- "type": "CHOICE",
3144
- "members": [
3145
- {
3146
- "type": "FIELD",
3147
- "name": "arguments",
3148
- "content": {
3149
- "type": "SYMBOL",
3150
- "name": "type_arguments"
3151
- }
3152
- },
3153
- {
3154
- "type": "BLANK"
3155
- }
3156
- ]
3157
- }
3158
- ]
3159
- },
3160
- "type_arguments": {
3161
- "type": "SEQ",
3162
- "members": [
3163
- {
3164
- "type": "STRING",
3165
- "value": "("
3166
- },
3167
- {
3168
- "type": "CHOICE",
3169
- "members": [
3170
- {
3171
- "type": "SEQ",
3172
- "members": [
3173
- {
3174
- "type": "SYMBOL",
3175
- "name": "type_argument"
3176
- },
3177
- {
3178
- "type": "REPEAT",
3179
- "content": {
3180
- "type": "SEQ",
3181
- "members": [
3182
- {
3183
- "type": "STRING",
3184
- "value": ","
3185
- },
3186
- {
3187
- "type": "SYMBOL",
3188
- "name": "type_argument"
3189
- }
3190
- ]
3191
- }
3192
- },
3193
- {
3194
- "type": "CHOICE",
3195
- "members": [
3196
- {
3197
- "type": "STRING",
3198
- "value": ","
3199
- },
3200
- {
3201
- "type": "BLANK"
3202
- }
3203
- ]
3204
- }
3205
- ]
3206
- },
3207
- {
3208
- "type": "BLANK"
3209
- }
3210
- ]
3211
- },
3212
- {
3213
- "type": "STRING",
3214
- "value": ")"
3215
- }
3216
- ]
3217
- },
3218
- "type_argument": {
3219
- "type": "SYMBOL",
3220
- "name": "_type"
3221
- },
3222
- "return_type": {
3223
- "type": "SEQ",
3224
- "members": [
3225
- {
3226
- "type": "STRING",
3227
- "value": "->"
3228
- },
3229
- {
3230
- "type": "FIELD",
3231
- "name": "return_type",
3232
- "content": {
3233
- "type": "SYMBOL",
3234
- "name": "_type"
3235
- }
3236
- }
3237
- ]
3238
- },
3239
- "generics": {
3240
- "type": "SEQ",
3241
- "members": [
3242
- {
3243
- "type": "STRING",
3244
- "value": "("
3245
- },
3246
- {
3247
- "type": "SEQ",
3248
- "members": [
3249
- {
3250
- "type": "SYMBOL",
3251
- "name": "generic"
3252
- },
3253
- {
3254
- "type": "REPEAT",
3255
- "content": {
3256
- "type": "SEQ",
3257
- "members": [
3258
- {
3259
- "type": "STRING",
3260
- "value": ","
3261
- },
3262
- {
3263
- "type": "SYMBOL",
3264
- "name": "generic"
3265
- }
3266
- ]
3267
- }
3268
- },
3269
- {
3270
- "type": "CHOICE",
3271
- "members": [
3272
- {
3273
- "type": "STRING",
3274
- "value": ","
3275
- },
3276
- {
3277
- "type": "BLANK"
3278
- }
3279
- ]
3280
- }
3281
- ]
3282
- },
3283
- {
3284
- "type": "STRING",
3285
- "value": ")"
3286
- }
3287
- ]
3288
- },
3289
- "generic": {
3290
- "type": "PATTERN",
3291
- "value": "[a-z][a-z]*"
3292
- },
3293
- "visibility_modifier": {
3294
- "type": "STRING",
3295
- "value": "pub"
3296
- },
3297
- "float": {
3298
- "type": "PATTERN",
3299
- "value": "-?[0-9]+\\.[0-9]*"
3300
- },
3301
- "integer": {
3302
- "type": "SEQ",
3303
- "members": [
3304
- {
3305
- "type": "CHOICE",
3306
- "members": [
3307
- {
3308
- "type": "STRING",
3309
- "value": "-"
3310
- },
3311
- {
3312
- "type": "BLANK"
3313
- }
3314
- ]
3315
- },
3316
- {
3317
- "type": "CHOICE",
3318
- "members": [
3319
- {
3320
- "type": "SYMBOL",
3321
- "name": "_hex"
3322
- },
3323
- {
3324
- "type": "SYMBOL",
3325
- "name": "_decimal"
3326
- },
3327
- {
3328
- "type": "SYMBOL",
3329
- "name": "_octal"
3330
- },
3331
- {
3332
- "type": "SYMBOL",
3333
- "name": "_binary"
3334
- }
3335
- ]
3336
- }
3337
- ]
3338
- },
3339
- "string": {
3340
- "type": "SEQ",
3341
- "members": [
3342
- {
3343
- "type": "STRING",
3344
- "value": "\""
3345
- },
3346
- {
3347
- "type": "REPEAT",
3348
- "content": {
3349
- "type": "CHOICE",
3350
- "members": [
3351
- {
3352
- "type": "SYMBOL",
3353
- "name": "escape_sequence"
3354
- },
3355
- {
3356
- "type": "SYMBOL",
3357
- "name": "quoted_content"
3358
- }
3359
- ]
3360
- }
3361
- },
3362
- {
3363
- "type": "IMMEDIATE_TOKEN",
3364
- "content": {
3365
- "type": "STRING",
3366
- "value": "\""
3367
- }
3368
- }
3369
- ]
3370
- },
3371
- "_hex": {
3372
- "type": "PATTERN",
3373
- "value": "0[xX][0-9a-fA-F_]+"
3374
- },
3375
- "_decimal": {
3376
- "type": "PATTERN",
3377
- "value": "[0-9][0-9_]*"
3378
- },
3379
- "_octal": {
3380
- "type": "PATTERN",
3381
- "value": "0[oO][0-7_]+"
3382
- },
3383
- "_binary": {
3384
- "type": "PATTERN",
3385
- "value": "0[bB][0-1_]+"
3386
- },
3387
- "_interpolation": {
3388
- "type": "CHOICE",
3389
- "members": [
3390
- {
3391
- "type": "SEQ",
3392
- "members": [
3393
- {
3394
- "type": "STRING",
3395
- "value": "{"
3396
- },
3397
- {
3398
- "type": "SYMBOL",
3399
- "name": "identifier"
3400
- },
3401
- {
3402
- "type": "STRING",
3403
- "value": "}"
3404
- }
3405
- ]
3406
- }
3407
- ]
3408
- },
3409
- "escape_sequence": {
3410
- "type": "IMMEDIATE_TOKEN",
3411
- "content": {
3412
- "type": "PATTERN",
3413
- "value": "\\\\[efnrt\\\"\\\\]"
3414
- }
3415
- },
3416
- "identifier": {
3417
- "type": "PATTERN",
3418
- "value": "[_a-z][_0-9a-z]*"
3419
- },
3420
- "label": {
3421
- "type": "SYMBOL",
3422
- "name": "_name"
3423
- },
3424
- "discard": {
3425
- "type": "SYMBOL",
3426
- "name": "_discard_name"
3427
- },
3428
- "type_identifier": {
3429
- "type": "SYMBOL",
3430
- "name": "_upname"
3431
- },
3432
- "constructor_name": {
3433
- "type": "SYMBOL",
3434
- "name": "_upname"
3435
- },
3436
- "function_name": {
3437
- "type": "SYMBOL",
3438
- "name": "_name"
3439
- },
3440
- "remote_function_identifier": {
3441
- "type": "SEQ",
3442
- "members": [
3443
- {
3444
- "type": "FIELD",
3445
- "name": "module",
3446
- "content": {
3447
- "type": "SYMBOL",
3448
- "name": "identifier"
3449
- }
3450
- },
3451
- {
3452
- "type": "STRING",
3453
- "value": "."
3454
- },
3455
- {
3456
- "type": "FIELD",
3457
- "name": "name",
3458
- "content": {
3459
- "type": "SYMBOL",
3460
- "name": "identifier"
3461
- }
3462
- }
3463
- ]
3464
- },
3465
- "remote_constructor_name": {
3466
- "type": "SEQ",
3467
- "members": [
3468
- {
3469
- "type": "FIELD",
3470
- "name": "module",
3471
- "content": {
3472
- "type": "SYMBOL",
3473
- "name": "identifier"
3474
- }
3475
- },
3476
- {
3477
- "type": "STRING",
3478
- "value": "."
3479
- },
3480
- {
3481
- "type": "FIELD",
3482
- "name": "name",
3483
- "content": {
3484
- "type": "SYMBOL",
3485
- "name": "type_identifier"
3486
- }
3487
- }
3488
- ]
3489
- },
3490
- "_type_annotation": {
3491
- "type": "SEQ",
3492
- "members": [
3493
- {
3494
- "type": "STRING",
3495
- "value": ":"
3496
- },
3497
- {
3498
- "type": "FIELD",
3499
- "name": "type",
3500
- "content": {
3501
- "type": "SYMBOL",
3502
- "name": "_type"
3503
- }
3504
- }
3505
- ]
3506
- },
3507
- "_type": {
3508
- "type": "CHOICE",
3509
- "members": [
3510
- {
3511
- "type": "SYMBOL",
3512
- "name": "type"
3513
- },
3514
- {
3515
- "type": "SYMBOL",
3516
- "name": "generic"
3517
- },
3518
- {
3519
- "type": "SYMBOL",
3520
- "name": "function_type"
3521
- }
3522
- ]
3523
- },
3524
- "_discard_name": {
3525
- "type": "PATTERN",
3526
- "value": "_[_0-9a-z]*"
3527
- },
3528
- "_name": {
3529
- "type": "PATTERN",
3530
- "value": "[_a-z][_0-9a-z]*"
3531
- },
3532
- "_upname": {
3533
- "type": "PATTERN",
3534
- "value": "[A-Z][0-9a-zA-Z]*"
3535
- }
3536
- },
3537
- "extras": [
3538
- {
3539
- "type": "PATTERN",
3540
- "value": "\\r?\\n"
3541
- },
3542
- {
3543
- "type": "PATTERN",
3544
- "value": "\\s"
3545
- },
3546
- {
3547
- "type": "SYMBOL",
3548
- "name": "module_comment"
3549
- },
3550
- {
3551
- "type": "SYMBOL",
3552
- "name": "statement_comment"
3553
- },
3554
- {
3555
- "type": "SYMBOL",
3556
- "name": "comment"
3557
- }
3558
- ],
3559
- "conflicts": [],
3560
- "precedences": [],
3561
- "externals": [
3562
- {
3563
- "type": "SYMBOL",
3564
- "name": "quoted_content"
3565
- }
3566
- ],
3567
- "inline": [],
3568
- "supertypes": []
3569
- }
3570
-
src/language/main-browser.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { EmptyFileSystem, startLanguageServer } from 'langium';
2
+ import { BrowserMessageReader, BrowserMessageWriter, createConnection } from 'vscode-languageserver/browser.js';
3
+ import { createPalmServices } from './palm-module.js';
4
+
5
+ declare const self: DedicatedWorkerGlobalScope;
6
+
7
+ const messageReader = new BrowserMessageReader(self);
8
+ const messageWriter = new BrowserMessageWriter(self);
9
+
10
+ const connection = createConnection(messageReader, messageWriter);
11
+
12
+ const { shared } = createPalmServices({ connection, ...EmptyFileSystem });
13
+
14
+ startLanguageServer(shared);
src/language/main.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { startLanguageServer } from 'langium';
2
+ import { NodeFileSystem } from 'langium/node';
3
+ import { createConnection, ProposedFeatures } from 'vscode-languageserver/node.js';
4
+ import { createPalmServices } from './palm-module.js';
5
+
6
+ // Create a connection to the client
7
+ const connection = createConnection(ProposedFeatures.all);
8
+
9
+ // Inject the shared services and language-specific services
10
+ const { shared } = createPalmServices({ connection, ...NodeFileSystem });
11
+
12
+ // Start the language server with the shared services
13
+ startLanguageServer(shared);
src/language/palm-module.ts ADDED
@@ -0,0 +1,63 @@
1
+ import type { DefaultSharedModuleContext, LangiumServices, LangiumSharedServices, Module, PartialLangiumServices } from 'langium';
2
+ import { createDefaultModule, createDefaultSharedModule, inject } from 'langium';
3
+ import { PalmGeneratedModule, PalmGeneratedSharedModule } from './generated/module.js';
4
+ import { PalmValidator, registerValidationChecks } from './palm-validator.js';
5
+
6
+ /**
7
+ * Declaration of custom services - add your own service classes here.
8
+ */
9
+ export type PalmAddedServices = {
10
+ validation: {
11
+ PalmValidator: PalmValidator
12
+ }
13
+ }
14
+
15
+ /**
16
+ * Union of Langium default services and your custom services - use this as constructor parameter
17
+ * of custom service classes.
18
+ */
19
+ export type PalmServices = LangiumServices & PalmAddedServices
20
+
21
+ /**
22
+ * Dependency injection module that overrides Langium default services and contributes the
23
+ * declared custom services. The Langium defaults can be partially specified to override only
24
+ * selected services, while the custom services must be fully specified.
25
+ */
26
+ export const PalmModule: Module<PalmServices, PartialLangiumServices & PalmAddedServices> = {
27
+ validation: {
28
+ PalmValidator: () => new PalmValidator()
29
+ }
30
+ };
31
+
32
+ /**
33
+ * Create the full set of services required by Langium.
34
+ *
35
+ * First inject the shared services by merging two modules:
36
+ * - Langium default shared services
37
+ * - Services generated by langium-cli
38
+ *
39
+ * Then inject the language-specific services by merging three modules:
40
+ * - Langium default language-specific services
41
+ * - Services generated by langium-cli
42
+ * - Services specified in this file
43
+ *
44
+ * @param context Optional module context with the LSP connection
45
+ * @returns An object wrapping the shared services and the language-specific services
46
+ */
47
+ export function createPalmServices(context: DefaultSharedModuleContext): {
48
+ shared: LangiumSharedServices,
49
+ Palm: PalmServices
50
+ } {
51
+ const shared = inject(
52
+ createDefaultSharedModule(context),
53
+ PalmGeneratedSharedModule
54
+ );
55
+ const Palm = inject(
56
+ createDefaultModule({ shared }),
57
+ PalmGeneratedModule,
58
+ PalmModule
59
+ );
60
+ shared.ServiceRegistry.register(Palm);
61
+ registerValidationChecks(Palm);
62
+ return { shared, Palm };
63
+ }
src/language/palm-validator.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { ValidationAcceptor, ValidationChecks } from "langium";
2
+ import type { PalmAstType, Type } from "./generated/ast.js";
3
+ import type { PalmServices } from "./palm-module.js";
4
+
5
+ /**
6
+ * Register custom validation checks.
7
+ */
8
+ export function registerValidationChecks(services: PalmServices) {
9
+ const registry = services.validation.ValidationRegistry;
10
+ const validator = services.validation.PalmValidator;
11
+ const checks: ValidationChecks<PalmAstType> = {
12
+ Type: validator.checkPersonStartsWithCapital,
13
+ };
14
+ registry.register(checks, validator);
15
+ }
16
+
17
+ /**
18
+ * Implementation of custom validations.
19
+ */
20
+ export class PalmValidator {
21
+ checkPersonStartsWithCapital(t: Type, accept: ValidationAcceptor): void {
22
+ if (t.name) {
23
+ const firstChar = t.name.substring(0, 1);
24
+ if (firstChar.toUpperCase() !== firstChar) {
25
+ accept("warning", "Person name should start with a capital.", {
26
+ node: t,
27
+ property: "name",
28
+ });
29
+ }
30
+ }
31
+ }
32
+ }
src/language/palm.langium ADDED
@@ -0,0 +1,109 @@
1
+ grammar Palm
2
+
3
+ entry Program:
4
+ Module (types+=Type | functions+=FunctionDefinition<false, false>)*;
5
+
6
+ Module:
7
+ 'module' name=ID;
8
+
9
+ Type:
10
+ Primitive | Enum | Trait | Entity | Extension;
11
+
12
+ Primitive:
13
+ 'primitive' name=ID '{'
14
+ (methods+=FunctionDefinition<true, false>)*
15
+ '}';
16
+
17
+ Enum:
18
+ 'enum' name=ID Generics '{'
19
+ (fields+=EnumField)*
20
+ (methods+=FunctionDefinition<true, false>)*
21
+ '}';
22
+
23
+ EnumField:
24
+ name=ID;
25
+
26
+ Trait:
27
+ 'trait' name=ID Generics '{'
28
+ (methods+=FunctionDefinition<true, true>)*
29
+ '}';
30
+
31
+ Extension:
32
+ 'extension' name=ID 'on' type=[Entity] '{'
33
+ (methods+=FunctionDefinition<true, false>)*
34
+ '}';
35
+
36
+ Entity:
37
+ 'entity' name=ID Generics '{'
38
+ (fields+=Field)*
39
+ (methods+=FunctionDefinition<true, false>)*
40
+ '}';
41
+
42
+ Field:
43
+ names+=ID ((',' names+=ID)*)? ':' type=[Type:ID];
44
+
45
+ fragment Generics:
46
+ ('<' generics+=GENERIC_ID (',' generics+=GENERIC_ID)* '>')?;
47
+
48
+ QualifiedName returns string:
49
+ ID ('.' ID)*;
50
+
51
+ type AbstractDefinition = FunctionDefinition | Param;
52
+
53
+ FunctionDefinition<isMethod, isTrait>:
54
+ (<isMethod> static?='static')?
55
+ 'fn' name=ID '(' (params+=Param (',' params+=Param)*)? ')' ('->' returns+=ReturnType (',' returns+=ReturnType)*)? (<!isTrait> Block);
56
+
57
+ ParamType:
58
+ type=[Type] (nilable?='?')?;
59
+
60
+ Param:
61
+ name=ID ':' type=ParamType;
62
+
63
+ fragment Block:
64
+ '{' body+=Stmt* '}';
65
+
66
+ ReturnType:
67
+ type=[Type] (nilable?='?')? (throws?='!')?;
68
+
69
+ Stmt: Assignment | FnCall;
70
+
71
+ Assignment:
72
+ 'const' name=ID '=' rhs=(FnCall|STRING|INT|NUMBER);
73
+
74
+ FnCall:
75
+ fnName=[FunctionDefinition:ID] '(' (args+=Expression (',' args+=Expression)*)? ')';
76
+
77
+ Expression:
78
+ Addition;
79
+
80
+ Addition infers Expression:
81
+ Multiplication ({infer BinaryExpression.left=current} operator=('+' | '-') right=Multiplication)*;
82
+
83
+ Multiplication infers Expression:
84
+ Exponentiation ({infer BinaryExpression.left=current} operator=('*' | '/') right=Exponentiation)*;
85
+
86
+ Exponentiation infers Expression:
87
+ Modulo ({infer BinaryExpression.left=current} operator='^' right=Modulo)*;
88
+
89
+ Modulo infers Expression:
90
+ PrimaryExpression ({infer BinaryExpression.left=current} operator='%' right=PrimaryExpression)*;
91
+
92
+ PrimaryExpression infers Expression:
93
+ '(' Expression ')' |
94
+ {infer NumberLiteral} value=NUMBER |
95
+ {infer StringLiteral} value=STRING |
96
+ {infer ReferenceLiteral} value=[Param:QualifiedName] ('(' args+=Expression (',' args+=Expression)* ')')?;
97
+ // {infer FunctionCall} func=[FunctionDefinition:ID] ('(' args+=Expression (',' args+=Expression)* ')')?;
98
+
99
+ terminal ID: /[_a-zA-Z][\w_]*/;
100
+ terminal GENERIC_ID: /(a|b|c)/;
101
+ terminal VAR_ID: /[_a-z][\w_]*/;
102
+ terminal INT returns number: /[0-9]+/;
103
+ terminal STRING: /"(\\.|[^"\\])*"|'(\\.|[^'\\])*'/;
104
+ terminal HEX: /#(\d|[a-fA-F])+/;
105
+ terminal NUMBER returns number: /[0-9]+(\.[0-9]*)?[a-z]*/;
106
+
107
+ hidden terminal WS: /\s+/;
108
+ hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
109
+ hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;
src/node-types.json DELETED
@@ -1,2488 +0,0 @@
1
- [
2
- {
3
- "type": "anonymous_function",
4
- "named": true,
5
- "fields": {
6
- "body": {
7
- "multiple": false,
8
- "required": true,
9
- "types": [
10
- {
11
- "type": "function_body",
12
- "named": true
13
- }
14
- ]
15
- },
16
- "parameters": {
17
- "multiple": false,
18
- "required": true,
19
- "types": [
20
- {
21
- "type": "function_parameters",
22
- "named": true
23
- }
24
- ]
25
- },
26
- "return_type": {
27
- "multiple": false,
28
- "required": false,
29
- "types": [
30
- {
31
- "type": "function_type",
32
- "named": true
33
- },
34
- {
35
- "type": "generic",
36
- "named": true
37
- },
38
- {
39
- "type": "type",
40
- "named": true
41
- }
42
- ]
43
- }
44
- }
45
- },
46
- {
47
- "type": "argument",
48
- "named": true,
49
- "fields": {
50
- "label": {
51
- "multiple": false,
52
- "required": false,
53
- "types": [
54
- {
55
- "type": "label",
56
- "named": true
57
- }
58
- ]
59
- },
60
- "value": {
61
- "multiple": false,
62
- "required": true,
63
- "types": [
64
- {
65
- "type": "anonymous_function",
66
- "named": true
67
- },
68
- {
69
- "type": "binary_expression",
70
- "named": true
71
- },
72
- {
73
- "type": "expression_group",
74
- "named": true
75
- },
76
- {
77
- "type": "field_access",
78
- "named": true
79
- },
80
- {
81
- "type": "float",
82
- "named": true
83
- },
84
- {
85
- "type": "function_call",
86
- "named": true
87
- },
88
- {
89
- "type": "hole",
90
- "named": true
91
- },
92
- {
93
- "type": "identifier",
94
- "named": true
95
- },
96
- {
97
- "type": "if",
98
- "named": true
99
- },
100
- {
101
- "type": "integer",
102
- "named": true
103
- },
104
- {
105
- "type": "negation",
106
- "named": true
107
- },
108
- {
109
- "type": "record",
110
- "named": true
111
- },
112
- {
113
- "type": "record_update",
114
- "named": true
115
- },
116
- {
117
- "type": "string",
118
- "named": true
119
- },
120
- {
121
- "type": "when",
122
- "named": true
123
- }
124
- ]
125
- }
126
- }
127
- },
128
- {
129
- "type": "arguments",
130
- "named": true,
131
- "fields": {},
132
- "children": {
133
- "multiple": true,
134
- "required": false,
135
- "types": [
136
- {
137
- "type": "argument",
138
- "named": true
139
- }
140
- ]
141
- }
142
- },
143
- {
144
- "type": "binary_expression",
145
- "named": true,
146
- "fields": {
147
- "left": {
148
- "multiple": false,
149
- "required": true,
150
- "types": [
151
- {
152
- "type": "anonymous_function",
153
- "named": true
154
- },
155
- {
156
- "type": "binary_expression",
157
- "named": true
158
- },
159
- {
160
- "type": "expression_group",
161
- "named": true
162
- },
163
- {
164
- "type": "field_access",
165
- "named": true
166
- },
167
- {
168
- "type": "float",
169
- "named": true
170
- },
171
- {
172
- "type": "function_call",
173
- "named": true
174
- },
175
- {
176
- "type": "identifier",
177
- "named": true
178
- },
179
- {
180
- "type": "if",
181
- "named": true
182
- },
183
- {
184
- "type": "integer",
185
- "named": true
186
- },
187
- {
188
- "type": "negation",
189
- "named": true
190
- },
191
- {
192
- "type": "record",
193
- "named": true
194
- },
195
- {
196
- "type": "record_update",
197
- "named": true
198
- },
199
- {
200
- "type": "string",
201
- "named": true
202
- },
203
- {
204
- "type": "when",
205
- "named": true
206
- }
207
- ]
208
- },
209
- "operator": {
210
- "multiple": false,
211
- "required": true,
212
- "types": [
213
- {
214
- "type": "!=",
215
- "named": false
216
- },
217
- {
218
- "type": "%",
219
- "named": false
220
- },
221
- {
222
- "type": "&&",
223
- "named": false
224
- },
225
- {
226
- "type": "*",
227
- "named": false
228
- },
229
- {
230
- "type": "+",
231
- "named": false
232
- },
233
- {
234
- "type": "-",
235
- "named": false
236
- },
237
- {
238
- "type": "/",
239
- "named": false
240
- },
241
- {
242
- "type": "<",
243
- "named": false
244
- },
245
- {
246
- "type": "<=",
247
- "named": false
248
- },
249
- {
250
- "type": "<>",
251
- "named": false
252
- },
253
- {
254
- "type": "==",
255
- "named": false
256
- },
257
- {
258
- "type": ">",
259
- "named": false
260
- },
261
- {
262
- "type": ">=",
263
- "named": false
264
- },
265
- {
266
- "type": "|>",
267
- "named": false
268
- },
269
- {
270
- "type": "||",
271
- "named": false
272
- }
273
- ]
274
- },
275
- "right": {
276
- "multiple": false,
277
- "required": true,
278
- "types": [
279
- {
280
- "type": "anonymous_function",
281
- "named": true
282
- },
283
- {
284
- "type": "binary_expression",
285
- "named": true
286
- },
287
- {
288
- "type": "expression_group",
289
- "named": true
290
- },
291
- {
292
- "type": "field_access",
293
- "named": true
294
- },
295
- {
296
- "type": "float",
297
- "named": true
298
- },
299
- {
300
- "type": "function_call",
301
- "named": true
302
- },
303
- {
304
- "type": "identifier",
305
- "named": true
306
- },
307
- {
308
- "type": "if",
309
- "named": true
310
- },
311
- {
312
- "type": "integer",
313
- "named": true
314
- },
315
- {
316
- "type": "negation",
317
- "named": true
318
- },
319
- {
320
- "type": "record",
321
- "named": true
322
- },
323
- {
324
- "type": "record_update",
325
- "named": true
326
- },
327
- {
328
- "type": "string",
329
- "named": true
330
- },
331
- {
332
- "type": "when",
333
- "named": true
334
- }
335
- ]
336
- }
337
- }
338
- },
339
- {
340
- "type": "const",
341
- "named": true,
342
- "fields": {
343
- "value": {
344
- "multiple": false,
345
- "required": true,
346
- "types": [
347
- {
348
- "type": "const_binary_expression",
349
- "named": true
350
- },
351
- {
352
- "type": "const_function_call",
353
- "named": true
354
- },
355
- {
356
- "type": "const_record",
357
- "named": true
358
- },
359
- {
360
- "type": "float",
361
- "named": true
362
- },
363
- {
364
- "type": "integer",
365
- "named": true
366
- },
367
- {
368
- "type": "string",
369
- "named": true
370
- }
371
- ]
372
- }
373
- },
374
- "children": {
375
- "multiple": false,
376
- "required": true,
377
- "types": [
378
- {
379
- "type": "identifier",
380
- "named": true
381
- }
382
- ]
383
- }
384
- },
385
- {
386
- "type": "const_argument",
387
- "named": true,
388
- "fields": {
389
- "label": {
390
- "multiple": false,
391
- "required": false,
392
- "types": [
393
- {
394
- "type": "label",
395
- "named": true
396
- }
397
- ]
398
- },
399
- "value": {
400
- "multiple": false,
401
- "required": true,
402
- "types": [
403
- {
404
- "type": "const_binary_expression",
405
- "named": true
406
- },
407
- {
408
- "type": "const_function_call",
409
- "named": true
410
- },
411
- {
412
- "type": "const_record",
413
- "named": true
414
- },
415
- {
416
- "type": "float",
417
- "named": true
418
- },
419
- {
420
- "type": "integer",
421
- "named": true
422
- },
423
- {
424
- "type": "string",
425
- "named": true
426
- }
427
- ]
428
- }
429
- }
430
- },
431
- {
432
- "type": "const_arguments",
433
- "named": true,
434
- "fields": {},
435
- "children": {
436
- "multiple": true,
437
- "required": false,
438
- "types": [
439
- {
440
- "type": "const_argument",
441
- "named": true
442
- }
443
- ]
444
- }
445
- },
446
- {
447
- "type": "const_binary_expression",
448
- "named": true,
449
- "fields": {
450
- "left": {
451
- "multiple": false,
452
- "required": true,
453
- "types": [
454
- {
455
- "type": "const_binary_expression",
456
- "named": true
457
- },
458
- {
459
- "type": "const_function_call",
460
- "named": true
461
- },
462
- {
463
- "type": "const_record",
464
- "named": true
465
- },
466
- {
467
- "type": "float",
468
- "named": true
469
- },
470
- {
471
- "type": "integer",
472
- "named": true
473
- },
474
- {
475
- "type": "string",
476
- "named": true
477
- }
478
- ]
479
- },
480
- "operator": {
481
- "multiple": false,
482
- "required": true,
483
- "types": [
484
- {
485
- "type": "!=",
486
- "named": false
487
- },
488
- {
489
- "type": "%",
490
- "named": false
491
- },
492
- {
493
- "type": "&&",
494
- "named": false
495
- },
496
- {
497
- "type": "*",
498
- "named": false
499
- },
500
- {
501
- "type": "+",
502
- "named": false
503
- },
504
- {
505
- "type": "-",
506
- "named": false
507
- },
508
- {
509
- "type": "/",
510
- "named": false
511
- },
512
- {
513
- "type": "<",
514
- "named": false
515
- },
516
- {
517
- "type": "<=",
518
- "named": false
519
- },
520
- {
521
- "type": "<>",
522
- "named": false
523
- },
524
- {
525
- "type": "==",
526
- "named": false
527
- },
528
- {
529
- "type": ">",
530
- "named": false
531
- },
532
- {
533
- "type": ">=",
534
- "named": false
535
- },
536
- {
537
- "type": "|>",
538
- "named": false
539
- },
540
- {
541
- "type": "||",
542
- "named": false
543
- }
544
- ]
545
- },
546
- "right": {
547
- "multiple": false,
548
- "required": true,
549
- "types": [
550
- {
551
- "type": "const_binary_expression",
552
- "named": true
553
- },
554
- {
555
- "type": "const_function_call",
556
- "named": true
557
- },
558
- {
559
- "type": "const_record",
560
- "named": true
561
- },
562
- {
563
- "type": "float",
564
- "named": true
565
- },
566
- {
567
- "type": "integer",
568
- "named": true
569
- },
570
- {
571
- "type": "string",
572
- "named": true
573
- }
574
- ]
575
- }
576
- }
577
- },
578
- {
579
- "type": "const_function_call",
580
- "named": true,
581
- "fields": {
582
- "arguments": {
583
- "multiple": false,
584
- "required": true,
585
- "types": [
586
- {
587
- "type": "const_arguments",
588
- "named": true
589
- }
590
- ]
591
- },
592
- "function": {
593
- "multiple": false,
594
- "required": true,
595
- "types": [
596
- {
597
- "type": "function_name",
598
- "named": true
599
- },
600
- {
601
- "type": "remote_function_identifier",
602
- "named": true
603
- }
604
- ]
605
- }
606
- }
607
- },
608
- {
609
- "type": "const_record",
610
- "named": true,
611
- "fields": {
612
- "arguments": {
613
- "multiple": false,
614
- "required": false,
615
- "types": [
616
- {
617
- "type": "arguments",
618
- "named": true
619
- }
620
- ]
621
- },
622
- "name": {
623
- "multiple": false,
624
- "required": true,
625
- "types": [
626
- {
627
- "type": "constructor_name",
628
- "named": true
629
- },
630
- {
631
- "type": "remote_constructor_name",
632
- "named": true
633
- }
634
- ]
635
- }
636
- }
637
- },
638
- {
639
- "type": "constructor_name",
640
- "named": true,
641
- "fields": {}
642
- },
643
- {
644
- "type": "discard",
645
- "named": true,
646
- "fields": {}
647
- },
648
- {
649
- "type": "enum",
650
- "named": true,
651
- "fields": {
652
- "fields": {
653
- "multiple": true,
654
- "required": true,
655
- "types": [
656
- {
657
- "type": "(",
658
- "named": false
659
- },
660
- {
661
- "type": ")",
662
- "named": false
663
- },
664
- {
665
- "type": ",",
666
- "named": false
667
- },
668
- {
669
- "type": "field",
670
- "named": true
671
- },
672
- {
673
- "type": "identifier",
674
- "named": true
675
- },
676
- {
677
- "type": "type_identifier",
678
- "named": true
679
- },
680
- {
681
- "type": "{",
682
- "named": false
683
- },
684
- {
685
- "type": "}",
686
- "named": false
687
- }
688
- ]
689
- },
690
- "generics": {
691
- "multiple": false,
692
- "required": false,
693
- "types": [
694
- {
695
- "type": "generics",
696
- "named": true
697
- }
698
- ]
699
- },
700
- "name": {
701
- "multiple": true,
702
- "required": true,
703
- "types": [
704
- {
705
- "type": "type_identifier",
706
- "named": true
707
- }
708
- ]
709
- }
710
- },
711
- "children": {
712
- "multiple": false,
713
- "required": false,
714
- "types": [
715
- {
716
- "type": "visibility_modifier",
717
- "named": true
718
- }
719
- ]
720
- }
721
- },
722
- {
723
- "type": "expression_group",
724
- "named": true,
725
- "fields": {},
726
- "children": {
727
- "multiple": true,
728
- "required": false,
729
- "types": [
730
- {
731
- "type": "anonymous_function",
732
- "named": true
733
- },
734
- {
735
- "type": "binary_expression",
736
- "named": true
737
- },
738
- {
739
- "type": "expression_group",
740
- "named": true
741
- },
742
- {
743
- "type": "field_access",
744
- "named": true
745
- },
746
- {
747
- "type": "float",
748
- "named": true
749
- },
750
- {
751
- "type": "function_call",
752
- "named": true
753
- },
754
- {
755
- "type": "identifier",
756
- "named": true
757
- },
758
- {
759
- "type": "if",
760
- "named": true
761
- },
762
- {
763
- "type": "integer",
764
- "named": true
765
- },
766
- {
767
- "type": "let",
768
- "named": true
769
- },
770
- {
771
- "type": "negation",
772
- "named": true
773
- },
774
- {
775
- "type": "record",
776
- "named": true
777
- },
778
- {
779
- "type": "record_update",
780
- "named": true
781
- },
782
- {
783
- "type": "string",
784
- "named": true
785
- },
786
- {
787
- "type": "when",
788
- "named": true
789
- }
790
- ]
791
- }
792
- },
793
- {
794
- "type": "field",
795
- "named": true,
796
- "fields": {
797
- "name": {
798
- "multiple": false,
799
- "required": true,
800
- "types": [
801
- {
802
- "type": "identifier",
803
- "named": true
804
- }
805
- ]
806
- },
807
- "type": {
808
- "multiple": false,
809
- "required": true,
810
- "types": [
811
- {
812
- "type": "function_type",
813
- "named": true
814
- },
815
- {
816
- "type": "generic",
817
- "named": true
818
- },
819
- {
820
- "type": "type",
821
- "named": true
822
- }
823
- ]
824
- }
825
- }
826
- },
827
- {
828
- "type": "field_access",
829
- "named": true,
830
- "fields": {
831
- "field": {
832
- "multiple": false,
833
- "required": true,
834
- "types": [
835
- {
836
- "type": "label",
837
- "named": true
838
- }
839
- ]
840
- },
841
- "record": {
842
- "multiple": false,
843
- "required": true,
844
- "types": [
845
- {
846
- "type": "expression_group",
847
- "named": true
848
- },
849
- {
850
- "type": "field_access",
851
- "named": true
852
- },
853
- {
854
- "type": "function_call",
855
- "named": true
856
- },
857
- {
858
- "type": "identifier",
859
- "named": true
860
- },
861
- {
862
- "type": "if",
863
- "named": true
864
- },
865
- {
866
- "type": "record",
867
- "named": true
868
- },
869
- {
870
- "type": "when",
871
- "named": true
872
- }
873
- ]
874
- }
875
- }
876
- },
877
- {
878
- "type": "function",
879
- "named": true,
880
- "fields": {
881
- "body": {
882
- "multiple": true,
883
- "required": true,
884
- "types": [
885
- {
886
- "type": "anonymous_function",
887
- "named": true
888
- },
889
- {
890
- "type": "binary_expression",
891
- "named": true
892
- },
893
- {
894
- "type": "expression_group",
895
- "named": true
896
- },
897
- {
898
- "type": "field_access",
899
- "named": true
900
- },
901
- {
902
- "type": "float",
903
- "named": true
904
- },
905
- {
906
- "type": "function_call",
907
- "named": true
908
- },
909
- {
910
- "type": "identifier",
911
- "named": true
912
- },
913
- {
914
- "type": "if",
915
- "named": true
916
- },
917
- {
918
- "type": "integer",
919
- "named": true
920
- },
921
- {
922
- "type": "let",
923
- "named": true
924
- },
925
- {
926
- "type": "negation",
927
- "named": true
928
- },
929
- {
930
- "type": "record",
931
- "named": true
932
- },
933
- {
934
- "type": "record_update",
935
- "named": true
936
- },
937
- {
938
- "type": "string",
939
- "named": true
940
- },
941
- {
942
- "type": "when",
943
- "named": true
944
- },
945
- {
946
- "type": "{",
947
- "named": false
948
- },
949
- {
950
- "type": "}",
951
- "named": false
952
- }
953
- ]
954
- },
955
- "name": {
956
- "multiple": false,
957
- "required": true,
958
- "types": [
959
- {
960
- "type": "identifier",
961
- "named": true
962
- }
963
- ]
964
- },
965
- "params": {
966
- "multiple": true,
967
- "required": true,
968
- "types": [
969
- {
970
- "type": "(",
971
- "named": false
972
- },
973
- {
974
- "type": ")",
975
- "named": false
976
- },
977
- {
978
- "type": ",",
979
- "named": false
980
- },
981
- {
982
- "type": "field",
983
- "named": true
984
- }
985
- ]
986
- },
987
- "return": {
988
- "multiple": false,
989
- "required": false,
990
- "types": [
991
- {
992
- "type": "return_type",
993
- "named": true
994
- }
995
- ]
996
- }
997
- },
998
- "children": {
999
- "multiple": false,
1000
- "required": false,
1001
- "types": [
1002
- {
1003
- "type": "visibility_modifier",
1004
- "named": true
1005
- }
1006
- ]
1007
- }
1008
- },
1009
- {
1010
- "type": "function_body",
1011
- "named": true,
1012
- "fields": {},
1013
- "children": {
1014
- "multiple": true,
1015
- "required": false,
1016
- "types": [
1017
- {
1018
- "type": "anonymous_function",
1019
- "named": true
1020
- },
1021
- {
1022
- "type": "binary_expression",
1023
- "named": true
1024
- },
1025
- {
1026
- "type": "expression_group",
1027
- "named": true
1028
- },
1029
- {
1030
- "type": "field_access",
1031
- "named": true
1032
- },
1033
- {
1034
- "type": "float",
1035
- "named": true
1036
- },
1037
- {
1038
- "type": "function_call",
1039
- "named": true
1040
- },
1041
- {
1042
- "type": "identifier",
1043
- "named": true
1044
- },
1045
- {
1046
- "type": "if",
1047
- "named": true
1048
- },
1049
- {
1050
- "type": "integer",
1051
- "named": true
1052
- },
1053
- {
1054
- "type": "let",
1055
- "named": true
1056
- },
1057
- {
1058
- "type": "negation",
1059
- "named": true
1060
- },
1061
- {
1062
- "type": "record",
1063
- "named": true
1064
- },
1065
- {
1066
- "type": "record_update",
1067
- "named": true
1068
- },
1069
- {
1070
- "type": "string",
1071
- "named": true
1072
- },
1073
- {
1074
- "type": "when",
1075
- "named": true
1076
- }
1077
- ]
1078
- }
1079
- },
1080
- {
1081
- "type": "function_call",
1082
- "named": true,
1083
- "fields": {
1084
- "arguments": {
1085
- "multiple": false,
1086
- "required": true,
1087
- "types": [
1088
- {
1089
- "type": "arguments",
1090
- "named": true
1091
- }
1092
- ]
1093
- },
1094
- "function": {
1095
- "multiple": false,
1096
- "required": true,
1097
- "types": [
1098
- {
1099
- "type": "anonymous_function",
1100
- "named": true
1101
- },
1102
- {
1103
- "type": "expression_group",
1104
- "named": true
1105
- },
1106
- {
1107
- "type": "field_access",
1108
- "named": true
1109
- },
1110
- {
1111
- "type": "function_call",
1112
- "named": true
1113
- },
1114
- {
1115
- "type": "identifier",
1116
- "named": true
1117
- },
1118
- {
1119
- "type": "if",
1120
- "named": true
1121
- },
1122
- {
1123
- "type": "when",
1124
- "named": true
1125
- }
1126
- ]
1127
- }
1128
- }
1129
- },
1130
- {
1131
- "type": "function_name",
1132
- "named": true,
1133
- "fields": {}
1134
- },
1135
- {
1136
- "type": "function_parameter",
1137
- "named": true,
1138
- "fields": {
1139
- "name": {
1140
- "multiple": false,
1141
- "required": true,
1142
- "types": [
1143
- {
1144
- "type": "discard",
1145
- "named": true
1146
- },
1147
- {
1148
- "type": "identifier",
1149
- "named": true
1150
- }
1151
- ]
1152
- },
1153
- "type": {
1154
- "multiple": false,
1155
- "required": false,
1156
- "types": [
1157
- {
1158
- "type": "function_type",
1159
- "named": true
1160
- },
1161
- {
1162
- "type": "generic",
1163
- "named": true
1164
- },
1165
- {
1166
- "type": "type",
1167
- "named": true
1168
- }
1169
- ]
1170
- }
1171
- }
1172
- },
1173
- {
1174
- "type": "function_parameter_types",
1175
- "named": true,
1176
- "fields": {},
1177
- "children": {
1178
- "multiple": true,
1179
- "required": false,
1180
- "types": [
1181
- {
1182
- "type": "function_type",
1183
- "named": true
1184
- },
1185
- {
1186
- "type": "generic",
1187
- "named": true
1188
- },
1189
- {
1190
- "type": "type",
1191
- "named": true
1192
- }
1193
- ]
1194
- }
1195
- },
1196
- {
1197
- "type": "function_parameters",
1198
- "named": true,
1199
- "fields": {},
1200
- "children": {
1201
- "multiple": true,
1202
- "required": false,
1203
- "types": [
1204
- {
1205
- "type": "function_parameter",
1206
- "named": true
1207
- }
1208
- ]
1209
- }
1210
- },
1211
- {
1212
- "type": "function_type",
1213
- "named": true,
1214
- "fields": {
1215
- "parameter_types": {
1216
- "multiple": false,
1217
- "required": false,
1218
- "types": [
1219
- {
1220
- "type": "function_parameter_types",
1221
- "named": true
1222
- }
1223
- ]
1224
- }
1225
- },
1226
- "children": {
1227
- "multiple": false,
1228
- "required": false,
1229
- "types": [
1230
- {
1231
- "type": "return_type",
1232
- "named": true
1233
- }
1234
- ]
1235
- }
1236
- },
1237
- {
1238
- "type": "generics",
1239
- "named": true,
1240
- "fields": {},
1241
- "children": {
1242
- "multiple": true,
1243
- "required": true,
1244
- "types": [
1245
- {
1246
- "type": "generic",
1247
- "named": true
1248
- }
1249
- ]
1250
- }
1251
- },
1252
- {
1253
- "type": "hole",
1254
- "named": true,
1255
- "fields": {}
1256
- },
1257
- {
1258
- "type": "identifier",
1259
- "named": true,
1260
- "fields": {}
1261
- },
1262
- {
1263
- "type": "if",
1264
- "named": true,
1265
- "fields": {},
1266
- "children": {
1267
- "multiple": true,
1268
- "required": true,
1269
- "types": [
1270
- {
1271
- "type": "anonymous_function",
1272
- "named": true
1273
- },
1274
- {
1275
- "type": "binary_expression",
1276
- "named": true
1277
- },
1278
- {
1279
- "type": "expression_group",
1280
- "named": true
1281
- },
1282
- {
1283
- "type": "field_access",
1284
- "named": true
1285
- },
1286
- {
1287
- "type": "float",
1288
- "named": true
1289
- },
1290
- {
1291
- "type": "function_call",
1292
- "named": true
1293
- },
1294
- {
1295
- "type": "identifier",
1296
- "named": true
1297
- },
1298
- {
1299
- "type": "if",
1300
- "named": true
1301
- },
1302
- {
1303
- "type": "integer",
1304
- "named": true
1305
- },
1306
- {
1307
- "type": "negation",
1308
- "named": true
1309
- },
1310
- {
1311
- "type": "record",
1312
- "named": true
1313
- },
1314
- {
1315
- "type": "record_update",
1316
- "named": true
1317
- },
1318
- {
1319
- "type": "string",
1320
- "named": true
1321
- },
1322
- {
1323
- "type": "when",
1324
- "named": true
1325
- }
1326
- ]
1327
- }
1328
- },
1329
- {
1330
- "type": "import",
1331
- "named": true,
1332
- "fields": {
1333
- "alias": {
1334
- "multiple": false,
1335
- "required": false,
1336
- "types": [
1337
- {
1338
- "type": "identifier",
1339
- "named": true
1340
- }
1341
- ]
1342
- },
1343
- "imports": {
1344
- "multiple": false,
1345
- "required": false,
1346
- "types": [
1347
- {
1348
- "type": "unqualified_imports",
1349
- "named": true
1350
- }
1351
- ]
1352
- },
1353
- "module": {
1354
- "multiple": false,
1355
- "required": true,
1356
- "types": [
1357
- {
1358
- "type": "module_name",
1359
- "named": true
1360
- }
1361
- ]
1362
- }
1363
- }
1364
- },
1365
- {
1366
- "type": "integer",
1367
- "named": true,
1368
- "fields": {}
1369
- },
1370
- {
1371
- "type": "label",
1372
- "named": true,
1373
- "fields": {}
1374
- },
1375
- {
1376
- "type": "let",
1377
- "named": true,
1378
- "fields": {
1379
- "pattern": {
1380
- "multiple": false,
1381
- "required": true,
1382
- "types": [
1383
- {
1384
- "type": "discard",
1385
- "named": true
1386
- },
1387
- {
1388
- "type": "float",
1389
- "named": true
1390
- },
1391
- {
1392
- "type": "identifier",
1393
- "named": true
1394
- },
1395
- {
1396
- "type": "integer",
1397
- "named": true
1398
- },
1399
- {
1400
- "type": "record_pattern",
1401
- "named": true
1402
- },
1403
- {
1404
- "type": "string",
1405
- "named": true
1406
- }
1407
- ]
1408
- },
1409
- "value": {
1410
- "multiple": false,
1411
- "required": true,
1412
- "types": [
1413
- {
1414
- "type": "anonymous_function",
1415
- "named": true
1416
- },
1417
- {
1418
- "type": "binary_expression",
1419
- "named": true
1420
- },
1421
- {
1422
- "type": "expression_group",
1423
- "named": true
1424
- },
1425
- {
1426
- "type": "field_access",
1427
- "named": true
1428
- },
1429
- {
1430
- "type": "float",
1431
- "named": true
1432
- },
1433
- {
1434
- "type": "function_call",
1435
- "named": true
1436
- },
1437
- {
1438
- "type": "identifier",
1439
- "named": true
1440
- },
1441
- {
1442
- "type": "if",
1443
- "named": true
1444
- },
1445
- {
1446
- "type": "integer",
1447
- "named": true
1448
- },
1449
- {
1450
- "type": "negation",
1451
- "named": true
1452
- },
1453
- {
1454
- "type": "record",
1455
- "named": true
1456
- },
1457
- {
1458
- "type": "record_update",
1459
- "named": true
1460
- },
1461
- {
1462
- "type": "string",
1463
- "named": true
1464
- },
1465
- {
1466
- "type": "when",
1467
- "named": true
1468
- }
1469
- ]
1470
- }
1471
- }
1472
- },
1473
- {
1474
- "type": "module",
1475
- "named": true,
1476
- "fields": {
1477
- "module": {
1478
- "multiple": false,
1479
- "required": true,
1480
- "types": [
1481
- {
1482
- "type": "module_name",
1483
- "named": true
1484
- }
1485
- ]
1486
- }
1487
- }
1488
- },
1489
- {
1490
- "type": "module_name",
1491
- "named": true,
1492
- "fields": {}
1493
- },
1494
- {
1495
- "type": "negation",
1496
- "named": true,
1497
- "fields": {},
1498
- "children": {
1499
- "multiple": false,
1500
- "required": true,
1501
- "types": [
1502
- {
1503
- "type": "anonymous_function",
1504
- "named": true
1505
- },
1506
- {
1507
- "type": "expression_group",
1508
- "named": true
1509
- },
1510
- {
1511
- "type": "field_access",
1512
- "named": true
1513
- },
1514
- {
1515
- "type": "float",
1516
- "named": true
1517
- },
1518
- {
1519
- "type": "function_call",
1520
- "named": true
1521
- },
1522
- {
1523
- "type": "identifier",
1524
- "named": true
1525
- },
1526
- {
1527
- "type": "if",
1528
- "named": true
1529
- },
1530
- {
1531
- "type": "integer",
1532
- "named": true
1533
- },
1534
- {
1535
- "type": "negation",
1536
- "named": true
1537
- },
1538
- {
1539
- "type": "record",
1540
- "named": true
1541
- },
1542
- {
1543
- "type": "record_update",
1544
- "named": true
1545
- },
1546
- {
1547
- "type": "string",
1548
- "named": true
1549
- },
1550
- {
1551
- "type": "when",
1552
- "named": true
1553
- }
1554
- ]
1555
- }
1556
- },
1557
- {
1558
- "type": "pattern_spread",
1559
- "named": true,
1560
- "fields": {}
1561
- },
1562
- {
1563
- "type": "record",
1564
- "named": true,
1565
- "fields": {
1566
- "arguments": {
1567
- "multiple": false,
1568
- "required": false,
1569
- "types": [
1570
- {
1571
- "type": "arguments",
1572
- "named": true
1573
- }
1574
- ]
1575
- },
1576
- "name": {
1577
- "multiple": false,
1578
- "required": true,
1579
- "types": [
1580
- {
1581
- "type": "constructor_name",
1582
- "named": true
1583
- }
1584
- ]
1585
- }
1586
- }
1587
- },
1588
- {
1589
- "type": "record_pattern",
1590
- "named": true,
1591
- "fields": {
1592
- "arguments": {
1593
- "multiple": false,
1594
- "required": false,
1595
- "types": [
1596
- {
1597
- "type": "record_pattern_arguments",
1598
- "named": true
1599
- }
1600
- ]
1601
- },
1602
- "name": {
1603
- "multiple": false,
1604
- "required": true,
1605
- "types": [
1606
- {
1607
- "type": "constructor_name",
1608
- "named": true
1609
- }
1610
- ]
1611
- }
1612
- }
1613
- },
1614
- {
1615
- "type": "record_pattern_argument",
1616
- "named": true,
1617
- "fields": {
1618
- "label": {
1619
- "multiple": false,
1620
- "required": false,
1621
- "types": [
1622
- {
1623
- "type": "label",
1624
- "named": true
1625
- }
1626
- ]
1627
- },
1628
- "pattern": {
1629
- "multiple": false,
1630
- "required": true,
1631
- "types": [
1632
- {
1633
- "type": "discard",
1634
- "named": true
1635
- },
1636
- {
1637
- "type": "float",
1638
- "named": true
1639
- },
1640
- {
1641
- "type": "identifier",
1642
- "named": true
1643
- },
1644
- {
1645
- "type": "integer",
1646
- "named": true
1647
- },
1648
- {
1649
- "type": "record_pattern",
1650
- "named": true
1651
- },
1652
- {
1653
- "type": "string",
1654
- "named": true
1655
- }
1656
- ]
1657
- }
1658
- }
1659
- },
1660
- {
1661
- "type": "record_pattern_arguments",
1662
- "named": true,
1663
- "fields": {},
1664
- "children": {
1665
- "multiple": true,
1666
- "required": false,
1667
- "types": [
1668
- {
1669
- "type": "pattern_spread",
1670
- "named": true
1671
- },
1672
- {
1673
- "type": "record_pattern_argument",
1674
- "named": true
1675
- }
1676
- ]
1677
- }
1678
- },
1679
- {
1680
- "type": "record_update",
1681
- "named": true,
1682
- "fields": {
1683
- "arguments": {
1684
- "multiple": false,
1685
- "required": true,
1686
- "types": [
1687
- {
1688
- "type": "record_update_arguments",
1689
- "named": true
1690
- }
1691
- ]
1692
- },
1693
- "constructor": {
1694
- "multiple": false,
1695
- "required": true,
1696
- "types": [
1697
- {
1698
- "type": "constructor_name",
1699
- "named": true
1700
- }
1701
- ]
1702
- },
1703
- "spread": {
1704
- "multiple": false,
1705
- "required": true,
1706
- "types": [
1707
- {
1708
- "type": "anonymous_function",
1709
- "named": true
1710
- },
1711
- {
1712
- "type": "binary_expression",
1713
- "named": true
1714
- },
1715
- {
1716
- "type": "expression_group",
1717
- "named": true
1718
- },
1719
- {
1720
- "type": "field_access",
1721
- "named": true
1722
- },
1723
- {
1724
- "type": "float",
1725
- "named": true
1726
- },
1727
- {
1728
- "type": "function_call",
1729
- "named": true
1730
- },
1731
- {
1732
- "type": "identifier",
1733
- "named": true
1734
- },
1735
- {
1736
- "type": "if",
1737
- "named": true
1738
- },
1739
- {
1740
- "type": "integer",
1741
- "named": true
1742
- },
1743
- {
1744
- "type": "negation",
1745
- "named": true
1746
- },
1747
- {
1748
- "type": "record",
1749
- "named": true
1750
- },
1751
- {
1752
- "type": "record_update",
1753
- "named": true
1754
- },
1755
- {
1756
- "type": "string",
1757
- "named": true
1758
- },
1759
- {
1760
- "type": "when",
1761
- "named": true
1762
- }
1763
- ]
1764
- }
1765
- }
1766
- },
1767
- {
1768
- "type": "record_update_argument",
1769
- "named": true,
1770
- "fields": {
1771
- "label": {
1772
- "multiple": false,
1773
- "required": true,
1774
- "types": [
1775
- {
1776
- "type": "label",
1777
- "named": true
1778
- }
1779
- ]
1780
- },
1781
- "value": {
1782
- "multiple": false,
1783
- "required": true,
1784
- "types": [
1785
- {
1786
- "type": "anonymous_function",
1787
- "named": true
1788
- },
1789
- {
1790
- "type": "binary_expression",
1791
- "named": true
1792
- },
1793
- {
1794
- "type": "expression_group",
1795
- "named": true
1796
- },
1797
- {
1798
- "type": "field_access",
1799
- "named": true
1800
- },
1801
- {
1802
- "type": "float",
1803
- "named": true
1804
- },
1805
- {
1806
- "type": "function_call",
1807
- "named": true
1808
- },
1809
- {
1810
- "type": "identifier",
1811
- "named": true
1812
- },
1813
- {
1814
- "type": "if",
1815
- "named": true
1816
- },
1817
- {
1818
- "type": "integer",
1819
- "named": true
1820
- },
1821
- {
1822
- "type": "negation",
1823
- "named": true
1824
- },
1825
- {
1826
- "type": "record",
1827
- "named": true
1828
- },
1829
- {
1830
- "type": "record_update",
1831
- "named": true
1832
- },
1833
- {
1834
- "type": "string",
1835
- "named": true
1836
- },
1837
- {
1838
- "type": "when",
1839
- "named": true
1840
- }
1841
- ]
1842
- }
1843
- }
1844
- },
1845
- {
1846
- "type": "record_update_arguments",
1847
- "named": true,
1848
- "fields": {},
1849
- "children": {
1850
- "multiple": true,
1851
- "required": true,
1852
- "types": [
1853
- {
1854
- "type": "record_update_argument",
1855
- "named": true
1856
- }
1857
- ]
1858
- }
1859
- },
1860
- {
1861
- "type": "remote_constructor_name",
1862
- "named": true,
1863
- "fields": {
1864
- "module": {
1865
- "multiple": false,
1866
- "required": true,
1867
- "types": [
1868
- {
1869
- "type": "identifier",
1870
- "named": true
1871
- }
1872
- ]
1873
- },
1874
- "name": {
1875
- "multiple": false,
1876
- "required": true,
1877
- "types": [
1878
- {
1879
- "type": "type_identifier",
1880
- "named": true
1881
- }
1882
- ]
1883
- }
1884
- }
1885
- },
1886
- {
1887
- "type": "remote_function_identifier",
1888
- "named": true,
1889
- "fields": {
1890
- "module": {
1891
- "multiple": false,
1892
- "required": true,
1893
- "types": [
1894
- {
1895
- "type": "identifier",
1896
- "named": true
1897
- }
1898
- ]
1899
- },
1900
- "name": {
1901
- "multiple": false,
1902
- "required": true,
1903
- "types": [
1904
- {
1905
- "type": "identifier",
1906
- "named": true
1907
- }
1908
- ]
1909
- }
1910
- }
1911
- },
1912
- {
1913
- "type": "return_type",
1914
- "named": true,
1915
- "fields": {
1916
- "return_type": {
1917
- "multiple": false,
1918
- "required": true,
1919
- "types": [
1920
- {
1921
- "type": "function_type",
1922
- "named": true
1923
- },
1924
- {
1925
- "type": "generic",
1926
- "named": true
1927
- },
1928
- {
1929
- "type": "type",
1930
- "named": true
1931
- }
1932
- ]
1933
- }
1934
- }
1935
- },
1936
- {
1937
- "type": "source_file",
1938
- "named": true,
1939
- "fields": {},
1940
- "children": {
1941
- "multiple": true,
1942
- "required": true,
1943
- "types": [
1944
- {
1945
- "type": "const",
1946
- "named": true
1947
- },
1948
- {
1949
- "type": "enum",
1950
- "named": true
1951
- },
1952
- {
1953
- "type": "function",
1954
- "named": true
1955
- },
1956
- {
1957
- "type": "import",
1958
- "named": true
1959
- },
1960
- {
1961
- "type": "module",
1962
- "named": true
1963
- },
1964
- {
1965
- "type": "struct",
1966
- "named": true
1967
- }
1968
- ]
1969
- }
1970
- },
1971
- {
1972
- "type": "string",
1973
- "named": true,
1974
- "fields": {},
1975
- "children": {
1976
- "multiple": true,
1977
- "required": false,
1978
- "types": [
1979
- {
1980
- "type": "escape_sequence",
1981
- "named": true
1982
- },
1983
- {
1984
- "type": "quoted_content",
1985
- "named": true
1986
- }
1987
- ]
1988
- }
1989
- },
1990
- {
1991
- "type": "struct",
1992
- "named": true,
1993
- "fields": {
1994
- "fields": {
1995
- "multiple": true,
1996
- "required": true,
1997
- "types": [
1998
- {
1999
- "type": "(",
2000
- "named": false
2001
- },
2002
- {
2003
- "type": ")",
2004
- "named": false
2005
- },
2006
- {
2007
- "type": "field",
2008
- "named": true
2009
- }
2010
- ]
2011
- },
2012
- "generics": {
2013
- "multiple": false,
2014
- "required": false,
2015
- "types": [
2016
- {
2017
- "type": "generics",
2018
- "named": true
2019
- }
2020
- ]
2021
- },
2022
- "name": {
2023
- "multiple": false,
2024
- "required": true,
2025
- "types": [
2026
- {
2027
- "type": "type_identifier",
2028
- "named": true
2029
- }
2030
- ]
2031
- }
2032
- },
2033
- "children": {
2034
- "multiple": false,
2035
- "required": false,
2036
- "types": [
2037
- {
2038
- "type": "visibility_modifier",
2039
- "named": true
2040
- }
2041
- ]
2042
- }
2043
- },
2044
- {
2045
- "type": "type",
2046
- "named": true,
2047
- "fields": {
2048
- "arguments": {
2049
- "multiple": false,
2050
- "required": false,
2051
- "types": [
2052
- {
2053
- "type": "type_arguments",
2054
- "named": true
2055
- }
2056
- ]
2057
- },
2058
- "name": {
2059
- "multiple": false,
2060
- "required": true,
2061
- "types": [
2062
- {
2063
- "type": "type_identifier",
2064
- "named": true
2065
- }
2066
- ]
2067
- }
2068
- }
2069
- },
2070
- {
2071
- "type": "type_argument",
2072
- "named": true,
2073
- "fields": {},
2074
- "children": {
2075
- "multiple": false,
2076
- "required": true,
2077
- "types": [
2078
- {
2079
- "type": "function_type",
2080
- "named": true
2081
- },
2082
- {
2083
- "type": "generic",
2084
- "named": true
2085
- },
2086
- {
2087
- "type": "type",
2088
- "named": true
2089
- }
2090
- ]
2091
- }
2092
- },
2093
- {
2094
- "type": "type_arguments",
2095
- "named": true,
2096
- "fields": {},
2097
- "children": {
2098
- "multiple": true,
2099
- "required": false,
2100
- "types": [
2101
- {
2102
- "type": "type_argument",
2103
- "named": true
2104
- }
2105
- ]
2106
- }
2107
- },
2108
- {
2109
- "type": "type_identifier",
2110
- "named": true,
2111
- "fields": {}
2112
- },
2113
- {
2114
- "type": "unqualified_import",
2115
- "named": true,
2116
- "fields": {
2117
- "alias": {
2118
- "multiple": false,
2119
- "required": false,
2120
- "types": [
2121
- {
2122
- "type": "identifier",
2123
- "named": true
2124
- },
2125
- {
2126
- "type": "type_identifier",
2127
- "named": true
2128
- }
2129
- ]
2130
- },
2131
- "name": {
2132
- "multiple": false,
2133
- "required": true,
2134
- "types": [
2135
- {
2136
- "type": "identifier",
2137
- "named": true
2138
- },
2139
- {
2140
- "type": "type_identifier",
2141
- "named": true
2142
- }
2143
- ]
2144
- }
2145
- }
2146
- },
2147
- {
2148
- "type": "unqualified_imports",
2149
- "named": true,
2150
- "fields": {},
2151
- "children": {
2152
- "multiple": true,
2153
- "required": false,
2154
- "types": [
2155
- {
2156
- "type": "unqualified_import",
2157
- "named": true
2158
- }
2159
- ]
2160
- }
2161
- },
2162
- {
2163
- "type": "when",
2164
- "named": true,
2165
- "fields": {},
2166
- "children": {
2167
- "multiple": true,
2168
- "required": false,
2169
- "types": [
2170
- {
2171
- "type": "anonymous_function",
2172
- "named": true
2173
- },
2174
- {
2175
- "type": "binary_expression",
2176
- "named": true
2177
- },
2178
- {
2179
- "type": "expression_group",
2180
- "named": true
2181
- },
2182
- {
2183
- "type": "field_access",
2184
- "named": true
2185
- },
2186
- {
2187
- "type": "float",
2188
- "named": true
2189
- },
2190
- {
2191
- "type": "function_call",
2192
- "named": true
2193
- },
2194
- {
2195
- "type": "identifier",
2196
- "named": true
2197
- },
2198
- {
2199
- "type": "if",
2200
- "named": true
2201
- },
2202
- {
2203
- "type": "integer",
2204
- "named": true
2205
- },
2206
- {
2207
- "type": "negation",
2208
- "named": true
2209
- },
2210
- {
2211
- "type": "record",
2212
- "named": true
2213
- },
2214
- {
2215
- "type": "record_update",
2216
- "named": true
2217
- },
2218
- {
2219
- "type": "string",
2220
- "named": true
2221
- },
2222
- {
2223
- "type": "when",
2224
- "named": true
2225
- },
2226
- {
2227
- "type": "when_entry",
2228
- "named": true
2229
- }
2230
- ]
2231
- }
2232
- },
2233
- {
2234
- "type": "when_entry",
2235
- "named": true,
2236
- "fields": {},
2237
- "children": {
2238
- "multiple": true,
2239
- "required": true,
2240
- "types": [
2241
- {
2242
- "type": "anonymous_function",
2243
- "named": true
2244
- },
2245
- {
2246
- "type": "binary_expression",
2247
- "named": true
2248
- },
2249
- {
2250
- "type": "expression_group",
2251
- "named": true
2252
- },
2253
- {
2254
- "type": "field_access",
2255
- "named": true
2256
- },
2257
- {
2258
- "type": "float",
2259
- "named": true
2260
- },
2261
- {
2262
- "type": "function_call",
2263
- "named": true
2264
- },
2265
- {
2266
- "type": "identifier",
2267
- "named": true
2268
- },
2269
- {
2270
- "type": "if",
2271
- "named": true
2272
- },
2273
- {
2274
- "type": "integer",
2275
- "named": true
2276
- },
2277
- {
2278
- "type": "negation",
2279
- "named": true
2280
- },
2281
- {
2282
- "type": "record",
2283
- "named": true
2284
- },
2285
- {
2286
- "type": "record_update",
2287
- "named": true
2288
- },
2289
- {
2290
- "type": "string",
2291
- "named": true
2292
- },
2293
- {
2294
- "type": "when",
2295
- "named": true
2296
- }
2297
- ]
2298
- }
2299
- },
2300
- {
2301
- "type": "!",
2302
- "named": false
2303
- },
2304
- {
2305
- "type": "!=",
2306
- "named": false
2307
- },
2308
- {
2309
- "type": "\"",
2310
- "named": false
2311
- },
2312
- {
2313
- "type": "%",
2314
- "named": false
2315
- },
2316
- {
2317
- "type": "&&",
2318
- "named": false
2319
- },
2320
- {
2321
- "type": "(",
2322
- "named": false
2323
- },
2324
- {
2325
- "type": ")",
2326
- "named": false
2327
- },
2328
- {
2329
- "type": "*",
2330
- "named": false
2331
- },
2332
- {
2333
- "type": "+",
2334
- "named": false
2335
- },
2336
- {
2337
- "type": ",",
2338
- "named": false
2339
- },
2340
- {
2341
- "type": "-",
2342
- "named": false
2343
- },
2344
- {
2345
- "type": "->",
2346
- "named": false
2347
- },
2348
- {
2349
- "type": ".",
2350
- "named": false
2351
- },
2352
- {
2353
- "type": "..",
2354
- "named": false
2355
- },
2356
- {
2357
- "type": "/",
2358
- "named": false
2359
- },
2360
- {
2361
- "type": ":",
2362
- "named": false
2363
- },
2364
- {
2365
- "type": "<",
2366
- "named": false
2367
- },
2368
- {
2369
- "type": "<=",
2370
- "named": false
2371
- },
2372
- {
2373
- "type": "<>",
2374
- "named": false
2375
- },
2376
- {
2377
- "type": "=",
2378
- "named": false
2379
- },
2380
- {
2381
- "type": "==",
2382
- "named": false
2383
- },
2384
- {
2385
- "type": ">",
2386
- "named": false
2387
- },
2388
- {
2389
- "type": ">=",
2390
- "named": false
2391
- },
2392
- {
2393
- "type": "[",
2394
- "named": false
2395
- },
2396
- {
2397
- "type": "]",
2398
- "named": false
2399
- },
2400
- {
2401
- "type": "_",
2402
- "named": false
2403
- },
2404
- {
2405
- "type": "as",
2406
- "named": false
2407
- },
2408
- {
2409
- "type": "comment",
2410
- "named": true
2411
- },
2412
- {
2413
- "type": "const",
2414
- "named": false
2415
- },
2416
- {
2417
- "type": "escape_sequence",
2418
- "named": true
2419
- },
2420
- {
2421
- "type": "float",
2422
- "named": true
2423
- },
2424
- {
2425
- "type": "fn",
2426
- "named": false
2427
- },
2428
- {
2429
- "type": "generic",
2430
- "named": true
2431
- },
2432
- {
2433
- "type": "if",
2434
- "named": false
2435
- },
2436
- {
2437
- "type": "import",
2438
- "named": false
2439
- },
2440
- {
2441
- "type": "let",
2442
- "named": false
2443
- },
2444
- {
2445
- "type": "module",
2446
- "named": false
2447
- },
2448
- {
2449
- "type": "module_comment",
2450
- "named": true
2451
- },
2452
- {
2453
- "type": "quoted_content",
2454
- "named": true
2455
- },
2456
- {
2457
- "type": "statement_comment",
2458
- "named": true
2459
- },
2460
- {
2461
- "type": "type",
2462
- "named": false
2463
- },
2464
- {
2465
- "type": "visibility_modifier",
2466
- "named": true
2467
- },
2468
- {
2469
- "type": "when",
2470
- "named": false
2471
- },
2472
- {
2473
- "type": "{",
2474
- "named": false
2475
- },
2476
- {
2477
- "type": "|>",
2478
- "named": false
2479
- },
2480
- {
2481
- "type": "||",
2482
- "named": false
2483
- },
2484
- {
2485
- "type": "}",
2486
- "named": false
2487
- }
2488
- ]
src/scanner.c DELETED
@@ -1,29 +0,0 @@
1
- #include <tree_sitter/parser.h>
2
-
3
- enum TokenType {
4
- QUOTED_CONTENT
5
- };
6
-
7
- void * tree_sitter_palm_external_scanner_create() {return NULL;}
8
- void tree_sitter_palm_external_scanner_destroy(void * payload) {}
9
- unsigned tree_sitter_palm_external_scanner_serialize(void * payload, char * buffer) {return 0;}
10
- void tree_sitter_palm_external_scanner_deserialize(void * payload, const char * buffer, unsigned length) {}
11
-
12
- bool tree_sitter_palm_external_scanner_scan(void * payload, TSLexer *lexer, const bool * valid_symbols) {
13
- if (valid_symbols[QUOTED_CONTENT]) {
14
- bool has_content = false;
15
-
16
- while (true) {
17
- if (lexer->lookahead == '\"' || lexer->lookahead == '\\') {
18
- break;
19
- } else if (lexer->lookahead == 0) {
20
- return false;
21
- }
22
- has_content = true;
23
- lexer->advance(lexer, false);
24
- }
25
- lexer->result_symbol = QUOTED_CONTENT;
26
- return has_content;
27
- }
28
- return false;
29
- }
src/tree_sitter/parser.h DELETED
@@ -1,224 +0,0 @@
1
- #ifndef TREE_SITTER_PARSER_H_
2
- #define TREE_SITTER_PARSER_H_
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #include <stdbool.h>
9
- #include <stdint.h>
10
- #include <stdlib.h>
11
-
12
- #define ts_builtin_sym_error ((TSSymbol)-1)
13
- #define ts_builtin_sym_end 0
14
- #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
15
-
16
- typedef uint16_t TSStateId;
17
-
18
- #ifndef TREE_SITTER_API_H_
19
- typedef uint16_t TSSymbol;
20
- typedef uint16_t TSFieldId;
21
- typedef struct TSLanguage TSLanguage;
22
- #endif
23
-
24
- typedef struct {
25
- TSFieldId field_id;
26
- uint8_t child_index;
27
- bool inherited;
28
- } TSFieldMapEntry;
29
-
30
- typedef struct {
31
- uint16_t index;
32
- uint16_t length;
33
- } TSFieldMapSlice;
34
-
35
- typedef struct {
36
- bool visible;
37
- bool named;
38
- bool supertype;
39
- } TSSymbolMetadata;
40
-
41
- typedef struct TSLexer TSLexer;
42
-
43
- struct TSLexer {
44
- int32_t lookahead;
45
- TSSymbol result_symbol;
46
- void (*advance)(TSLexer *, bool);
47
- void (*mark_end)(TSLexer *);
48
- uint32_t (*get_column)(TSLexer *);
49
- bool (*is_at_included_range_start)(const TSLexer *);
50
- bool (*eof)(const TSLexer *);
51
- };
52
-
53
- typedef enum {
54
- TSParseActionTypeShift,
55
- TSParseActionTypeReduce,
56
- TSParseActionTypeAccept,
57
- TSParseActionTypeRecover,
58
- } TSParseActionType;
59
-
60
- typedef union {
61
- struct {
62
- uint8_t type;
63
- TSStateId state;
64
- bool extra;
65
- bool repetition;
66
- } shift;
67
- struct {
68
- uint8_t type;
69
- uint8_t child_count;
70
- TSSymbol symbol;
71
- int16_t dynamic_precedence;
72
- uint16_t production_id;
73
- } reduce;
74
- uint8_t type;
75
- } TSParseAction;
76
-
77
- typedef struct {
78
- uint16_t lex_state;
79
- uint16_t external_lex_state;
80
- } TSLexMode;
81
-
82
- typedef union {
83
- TSParseAction action;
84
- struct {
85
- uint8_t count;
86
- bool reusable;
87
- } entry;
88
- } TSParseActionEntry;
89
-
90
- struct TSLanguage {
91
- uint32_t version;
92
- uint32_t symbol_count;
93
- uint32_t alias_count;
94
- uint32_t token_count;
95
- uint32_t external_token_count;
96
- uint32_t state_count;
97
- uint32_t large_state_count;
98
- uint32_t production_id_count;
99
- uint32_t field_count;
100
- uint16_t max_alias_sequence_length;
101
- const uint16_t *parse_table;
102
- const uint16_t *small_parse_table;
103
- const uint32_t *small_parse_table_map;
104
- const TSParseActionEntry *parse_actions;
105
- const char * const *symbol_names;
106
- const char * const *field_names;
107
- const TSFieldMapSlice *field_map_slices;
108
- const TSFieldMapEntry *field_map_entries;
109
- const TSSymbolMetadata *symbol_metadata;
110
- const TSSymbol *public_symbol_map;
111
- const uint16_t *alias_map;
112
- const TSSymbol *alias_sequences;
113
- const TSLexMode *lex_modes;
114
- bool (*lex_fn)(TSLexer *, TSStateId);
115
- bool (*keyword_lex_fn)(TSLexer *, TSStateId);
116
- TSSymbol keyword_capture_token;
117
- struct {
118
- const bool *states;
119
- const TSSymbol *symbol_map;
120
- void *(*create)(void);
121
- void (*destroy)(void *);
122
- bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
123
- unsigned (*serialize)(void *, char *);
124
- void (*deserialize)(void *, const char *, unsigned);
125
- } external_scanner;
126
- const TSStateId *primary_state_ids;
127
- };
128
-
129
- /*
130
- * Lexer Macros
131
- */
132
-
133
- #define START_LEXER() \
134
- bool result = false; \
135
- bool skip = false; \
136
- bool eof = false; \
137
- int32_t lookahead; \
138
- goto start; \
139
- next_state: \
140
- lexer->advance(lexer, skip); \
141
- start: \
142
- skip = false; \
143
- lookahead = lexer->lookahead;
144
-
145
- #define ADVANCE(state_value) \
146
- { \
147
- state = state_value; \
148
- goto next_state; \
149
- }
150
-
151
- #define SKIP(state_value) \
152
- { \
153
- skip = true; \
154
- state = state_value; \
155
- goto next_state; \
156
- }
157
-
158
- #define ACCEPT_TOKEN(symbol_value) \
159
- result = true; \
160
- lexer->result_symbol = symbol_value; \
161
- lexer->mark_end(lexer);
162
-
163
- #define END_STATE() return result;
164
-
165
- /*
166
- * Parse Table Macros
167
- */
168
-
169
- #define SMALL_STATE(id) id - LARGE_STATE_COUNT
170
-
171
- #define STATE(id) id
172
-
173
- #define ACTIONS(id) id
174
-
175
- #define SHIFT(state_value) \
176
- {{ \
177
- .shift = { \
178
- .type = TSParseActionTypeShift, \
179
- .state = state_value \
180
- } \
181
- }}
182
-
183
- #define SHIFT_REPEAT(state_value) \
184
- {{ \
185
- .shift = { \
186
- .type = TSParseActionTypeShift, \
187
- .state = state_value, \
188
- .repetition = true \
189
- } \
190
- }}
191
-
192
- #define SHIFT_EXTRA() \
193
- {{ \
194
- .shift = { \
195
- .type = TSParseActionTypeShift, \
196
- .extra = true \
197
- } \
198
- }}
199
-
200
- #define REDUCE(symbol_val, child_count_val, ...) \
201
- {{ \
202
- .reduce = { \
203
- .type = TSParseActionTypeReduce, \
204
- .symbol = symbol_val, \
205
- .child_count = child_count_val, \
206
- __VA_ARGS__ \
207
- }, \
208
- }}
209
-
210
- #define RECOVER() \
211
- {{ \
212
- .type = TSParseActionTypeRecover \
213
- }}
214
-
215
- #define ACCEPT_INPUT() \
216
- {{ \
217
- .type = TSParseActionTypeAccept \
218
- }}
219
-
220
- #ifdef __cplusplus
221
- }
222
- #endif
223
-
224
- #endif // TREE_SITTER_PARSER_H_
static/monacoClassic.html ADDED
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <!-- Page & Monaco styling -->
6
+ <link href="styles.css" rel="stylesheet"/>
7
+ <title>Palm in Langium</title>
8
+ </head>
9
+ <body>
10
+ <h1>Palm in Langium</h1>
11
+ <div class="wrapper">
12
+ <b>Monaco-Editor + Monarch</b>
13
+ <!-- Monaco Root -->
14
+ <div id="monaco-editor-root"></div>
15
+ </div>
16
+ <footer>
17
+ <p style="font-style:italic">Powered by</p>
18
+ <img width="125" src="https://langium.org/assets/langium_logo_w_nib.svg" alt="Langium">
19
+ </footer>
20
+ <!-- Monaco Configuration -->
21
+ <script type="module">
22
+ import { executeClassic } from './setupClassic.js';
23
+
24
+ // keep a reference to a promise for when the editor is finished starting, we'll use this to setup the canvas on load
25
+ const startingPromise = executeClassic(document.getElementById('monaco-editor-root'));
26
+ </script>
27
+ </body>
28
+ </html>
static/monacoExtended.html ADDED
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset='utf-8'>
5
+ <!-- Page & Monaco styling -->
6
+ <link href="styles.css" rel="stylesheet"/>
7
+ <title>Palm in Langium</title>
8
+ </head>
9
+ <body>
10
+ <h1>Palm in Langium</h1>
11
+ <div class="wrapper">
12
+ <b>Monaco-Editor + Textmate</b>
13
+ <!-- Monaco Root -->
14
+ <div id="monaco-editor-root"></div>
15
+ </div>
16
+ <footer>
17
+ <p style="font-style:italic">Powered by</p>
18
+ <img width="125" src="https://langium.org/assets/langium_logo_w_nib.svg" alt="Langium">
19
+ </footer>
20
+ <!-- Monaco Configuration -->
21
+ <script type="module">
22
+ import { executeExtended } from './setupExtended.js';
23
+
24
+ // keep a reference to a promise for when the editor is finished starting, we'll use this to setup the canvas on load
25
+ const startingPromise = executeExtended(document.getElementById('monaco-editor-root'));
26
+ </script>
27
+ </body>
28
+ </html>
static/setup.js ADDED
@@ -0,0 +1,18 @@
1
+ import { buildWorkerDefinition } from "./monaco-editor-workers/index.js";
2
+ buildWorkerDefinition('./monaco-editor-workers/workers', new URL('', window.location.href).href, false);
3
+
4
+ export const configureWorker = () => {
5
+ const workerURL = new URL('./worker/palm-server-worker.js', import.meta.url);
6
+ console.log(`Using the following worker URL: ${workerURL.href}`);
7
+ const lsWorker = new Worker(workerURL.href, {
8
+ type: 'classic',
9
+ name: 'Palm Language Server'
10
+ });
11
+
12
+ return {
13
+ options: {
14
+ $type: 'WorkerDirect',
15
+ worker: lsWorker
16
+ }
17
+ }
18
+ };
static/setupClassic.js ADDED
@@ -0,0 +1,32 @@
1
+ import { addMonacoStyles, defineUserServices, MonacoEditorLanguageClientWrapper } from './bundle/index.js';
2
+ import monarchSyntax from "../syntaxes/palm.monarch.js";
3
+ import { configureWorker } from './setup.js';
4
+
5
+ addMonacoStyles('monaco-editor-styles');
6
+
7
+ export const setupConfigClassic = () => {
8
+ return {
9
+ wrapperConfig: {
10
+ serviceConfig: defineUserServices(),
11
+ editorAppConfig: {
12
+ $type: 'classic',
13
+ languageId: 'palm',
14
+ code: `// Palm is running in the web!`,
15
+ useDiffEditor: false,
16
+ languageExtensionConfig: { id: 'langium' },
17
+ languageDef: monarchSyntax,
18
+ editorOptions: {
19
+ 'semanticHighlighting.enabled': true,
20
+ theme: 'vs-dark'
21
+ }
22
+ }
23
+ },
24
+ languageClientConfig: configureWorker()
25
+ };
26
+ };
27
+
28
+ export const executeClassic = async (htmlElement) => {
29
+ const userConfig = setupConfigClassic();
30
+ const wrapper = new MonacoEditorLanguageClientWrapper();
31
+ await wrapper.start(userConfig, htmlElement);
32
+ };
static/setupExtended.js ADDED
@@ -0,0 +1,62 @@
1
+ import { addMonacoStyles, defineUserServices, MonacoEditorLanguageClientWrapper } from './bundle/index.js';
2
+ import { configureWorker } from './setup.js';
3
+
4
+ addMonacoStyles('monaco-editor-styles');
5
+
6
+ export const setupConfigExtended = () => {
7
+ const extensionFilesOrContents = new Map();
8
+ const languageConfigUrl = new URL('../language-configuration.json', window.location.href);
9
+ const textmateConfigUrl = new URL('../syntaxes/palm.tmLanguage.json', window.location.href);
10
+ extensionFilesOrContents.set('/language-configuration.json', languageConfigUrl);
11
+ extensionFilesOrContents.set('/palm-grammar.json', textmateConfigUrl);
12
+
13
+ return {
14
+ wrapperConfig: {
15
+ serviceConfig: defineUserServices(),
16
+ editorAppConfig: {
17
+ $type: 'extended',
18
+ languageId: 'palm',
19
+ code: `// Palm is running in the web!`,
20
+ useDiffEditor: false,
21
+ extensions: [{
22
+ config: {
23
+ name: 'palm-web',
24
+ publisher: 'generator-langium',
25
+ version: '1.0.0',
26
+ engines: {
27
+ vscode: '*'
28
+ },
29
+ contributes: {
30
+ languages: [{
31
+ id: 'palm',
32
+ extensions: [
33
+ '.palm'
34
+ ],
35
+ configuration: './language-configuration.json'
36
+ }],
37
+ grammars: [{
38
+ language: 'palm',
39
+ scopeName: 'source.palm',
40
+ path: './palm-grammar.json'
41
+ }]
42
+ }
43
+ },
44
+ filesOrContents: extensionFilesOrContents,
45
+ }],
46
+ userConfiguration: {
47
+ json: JSON.stringify({
48
+ 'workbench.colorTheme': 'Default Dark Modern',
49
+ 'editor.semanticHighlighting.enabled': true
50
+ })
51
+ }
52
+ }
53
+ },
54
+ languageClientConfig: configureWorker()
55
+ };
56
+ };
57
+
58
+ export const executeExtended = async (htmlElement) => {
59
+ const userConfig = setupConfigExtended();
60
+ const wrapper = new MonacoEditorLanguageClientWrapper();
61
+ await wrapper.start(userConfig, htmlElement);
62
+ };
static/styles.css ADDED
@@ -0,0 +1,28 @@
1
+ html,body {
2
+ background: rgb(33,33,33);
3
+ font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
4
+ color: white;
5
+ margin: 0;
6
+ }
7
+ h1 {
8
+ text-align: center;
9
+ }
10
+ footer {
11
+ text-align: center;
12
+ color: #444;
13
+ font-size: 1.2rem;
14
+ margin-bottom: 0.5rem;
15
+ }
16
+ a:link {
17
+ color: gray;
18
+ }
19
+ a:visited {
20
+ color: lightskyblue;
21
+ }
22
+ /* for monaco */
23
+ .wrapper {
24
+ padding: 0 5%;
25
+ }
26
+ #monaco-editor-root {
27
+ height: calc(100vh - 7.5rem - 70px);
28
+ }
test/corpus/expressions.txt DELETED
@@ -1,140 +0,0 @@
1
- ================================================================================
2
- Pipes
3
- ================================================================================
4
-
5
- module palm
6
-
7
- fn add() {
8
- "hello"
9
- |> iodata.new
10
- |> iodata.reverse
11
- }
12
-
13
- --------------------------------------------------------------------------------
14
-
15
- (source_file
16
- (module
17
- (module_name))
18
- (function
19
- (identifier)
20
- (binary_expression
21
- (binary_expression
22
- (string
23
- (quoted_content))
24
- (field_access
25
- (identifier)
26
- (label)))
27
- (field_access
28
- (identifier)
29
- (label)))))
30
-
31
- ================================================================================
32
- When
33
- ================================================================================
34
-
35
- module palm
36
-
37
- pub fn main() {
38
- when a + 5 + 8 {
39
- 11 -> 123
40
- _ -> 0
41
- }
42
- when b {
43
- 1 -> "Hello"
44
- 2 -> "Game"
45
- 3 || 4 -> "Threes"
46
- { 5 * 1 } && { 5 + 1 } -> "Threes"
47
- _ -> "World"
48
- }
49
- when {
50
- 1 -> 1
51
- _ -> 0
52
- }
53
- }
54
-
55
- --------------------------------------------------------------------------------
56
-
57
- (source_file
58
- (module
59
- (module_name))
60
- (function
61
- (visibility_modifier)
62
- (identifier)
63
- (when
64
- (binary_expression
65
- (binary_expression
66
- (identifier)
67
- (integer))
68
- (integer))
69
- (when_entry
70
- (integer)
71
- (integer))
72
- (when_entry
73
- (integer)))
74
- (when
75
- (identifier)
76
- (when_entry
77
- (integer)
78
- (string
79
- (quoted_content)))
80
- (when_entry
81
- (integer)
82
- (string
83
- (quoted_content)))
84
- (when_entry
85
- (binary_expression
86
- (integer)
87
- (integer))
88
- (string
89
- (quoted_content)))
90
- (when_entry
91
- (binary_expression
92
- (expression_group
93
- (binary_expression
94
- (integer)
95
- (integer)))
96
- (expression_group
97
- (binary_expression
98
- (integer)
99
- (integer))))
100
- (string
101
- (quoted_content)))
102
- (when_entry
103
- (string
104
- (quoted_content))))
105
- (when
106
- (when_entry
107
- (integer)
108
- (integer))
109
- (when_entry
110
- (integer)))))
111
-
112
- ================================================================================
113
- If
114
- ================================================================================
115
-
116
- module palm
117
-
118
- pub fn main() {
119
- if a + 5 > 10 {
120
- 5
121
- }
122
- 1
123
- }
124
-
125
- --------------------------------------------------------------------------------
126
-
127
- (source_file
128
- (module
129
- (module_name))
130
- (function
131
- (visibility_modifier)
132
- (identifier)
133
- (if
134
- (binary_expression
135
- (binary_expression
136
- (identifier)
137
- (integer))
138
- (integer))
139
- (integer))
140
- (integer)))
test/corpus/functions.txt DELETED
@@ -1,85 +0,0 @@
1
- ================================================================================
2
- Function - Simple
3
- ================================================================================
4
-
5
- module palm
6
-
7
- pub fn main() {
8
- let a = "123"
9
- let b = 5
10
- let c = 5.1
11
- dog.bark()
12
- when b {
13
- 1 -> "Hello"
14
- _ -> "World"
15
- }
16
- if c > b {
17
- io.println("Greater")
18
- }
19
- }
20
-
21
- pub fn add(a: Int, b: Int) -> Int {
22
- a + b
23
- }
24
-
25
- --------------------------------------------------------------------------------
26
-
27
- (source_file
28
- (module
29
- (module_name))
30
- (function
31
- (visibility_modifier)
32
- (identifier)
33
- (let
34
- (identifier)
35
- (string
36
- (quoted_content)))
37
- (let
38
- (identifier)
39
- (integer))
40
- (let
41
- (identifier)
42
- (float))
43
- (function_call
44
- (field_access
45
- (identifier)
46
- (label))
47
- (arguments))
48
- (when
49
- (identifier)
50
- (when_entry
51
- (integer)
52
- (string
53
- (quoted_content)))
54
- (when_entry
55
- (string
56
- (quoted_content))))
57
- (if
58
- (binary_expression
59
- (identifier)
60
- (identifier))
61
- (function_call
62
- (field_access
63
- (identifier)
64
- (label))
65
- (arguments
66
- (argument
67
- (string
68
- (quoted_content)))))))
69
- (function
70
- (visibility_modifier)
71
- (identifier)
72
- (field
73
- (identifier)
74
- (type
75
- (type_identifier)))
76
- (field
77
- (identifier)
78
- (type
79
- (type_identifier)))
80
- (return_type
81
- (type
82
- (type_identifier)))
83
- (binary_expression
84
- (identifier)
85
- (identifier))))
test/corpus/statements.txt DELETED
@@ -1,257 +0,0 @@
1
- ================================================================================
2
- Module
3
- ================================================================================
4
-
5
- module palm
6
-
7
- --------------------------------------------------------------------------------
8
-
9
- (source_file
10
- (module
11
- (module_name)))
12
-
13
- ================================================================================
14
- Import
15
- ================================================================================
16
-
17
- module palm/std
18
-
19
- import palm/std/list
20
- import palm/std/list.{List, contains}
21
- import palm/std/bool as boolean
22
- import a
23
- import a/b
24
- import a.{b}
25
- import a/b.{c, d}
26
- import a/b.{c as d, e}
27
- import a/b.{c, D as E}
28
- import a/b.{c as d} as e
29
- import animal/cat as kitty
30
- import animal.{Cat as Kitty} as a
31
- import animal.{}
32
-
33
- --------------------------------------------------------------------------------
34
-
35
- (source_file
36
- (module
37
- (module_name))
38
- (import
39
- (module_name))
40
- (import
41
- (module_name)
42
- (unqualified_imports
43
- (unqualified_import
44
- (type_identifier))
45
- (unqualified_import
46
- (identifier))))
47
- (import
48
- (module_name)
49
- (identifier))
50
- (import
51
- (module_name))
52
- (import
53
- (module_name))
54
- (import
55
- (module_name)
56
- (unqualified_imports
57
- (unqualified_import
58
- (identifier))))
59
- (import
60
- (module_name)
61
- (unqualified_imports
62
- (unqualified_import
63
- (identifier))
64
- (unqualified_import
65
- (identifier))))
66
- (import
67
- (module_name)
68
- (unqualified_imports
69
- (unqualified_import
70
- (identifier)
71
- (identifier))
72
- (unqualified_import
73
- (identifier))))
74
- (import
75
- (module_name)
76
- (unqualified_imports
77
- (unqualified_import
78
- (identifier))
79
- (unqualified_import
80
- (type_identifier)
81
- (type_identifier))))
82
- (import
83
- (module_name)
84
- (unqualified_imports
85
- (unqualified_import
86
- (identifier)
87
- (identifier)))
88
- (identifier))
89
- (import
90
- (module_name)
91
- (identifier))
92
- (import
93
- (module_name)
94
- (unqualified_imports
95
- (unqualified_import
96
- (type_identifier)
97
- (type_identifier)))
98
- (identifier))
99
- (import
100
- (module_name)
101
- (unqualified_imports)))
102
-
103
- ================================================================================
104
- Const
105
- ================================================================================
106
-
107
- module palm
108
-
109
- const name = "John Doe"
110
- const pi = 3.14
111
- const data = Some("Json data")
112
- const sum_of_all = 5 + 5 + 7
113
- const a = 1234
114
- const a = 12.34
115
- // const a = [1, 2]
116
- const a = list.new(1, 2, 3)
117
- const a = Node
118
- const a = Node()
119
- const a = Cat("Ginny", 1950)
120
- const a = Person(name: "Billy", age: 52)
121
- const a = uri.Uri(host: "github.com")
122
- const a = option.Some("Hello, World!")
123
-
124
- --------------------------------------------------------------------------------
125
-
126
- (source_file
127
- (module
128
- (module_name))
129
- (const
130
- (identifier)
131
- (string
132
- (quoted_content)))
133
- (const
134
- (identifier)
135
- (float))
136
- (const
137
- (identifier)
138
- (const_record
139
- (constructor_name)
140
- (arguments
141
- (argument
142
- (string
143
- (quoted_content))))))
144
- (const
145
- (identifier)
146
- (const_binary_expression
147
- (const_binary_expression
148
- (integer)
149
- (integer))
150
- (integer)))
151
- (const
152
- (identifier)
153
- (integer))
154
- (const
155
- (identifier)
156
- (float))
157
- (comment)
158
- (const
159
- (identifier)
160
- (const_function_call
161
- (remote_function_identifier
162
- (identifier)
163
- (identifier))
164
- (const_arguments
165
- (const_argument
166
- (integer))
167
- (const_argument
168
- (integer))
169
- (const_argument
170
- (integer)))))
171
- (const
172
- (identifier)
173
- (const_record
174
- (constructor_name)))
175
- (const
176
- (identifier)
177
- (const_record
178
- (constructor_name)
179
- (arguments)))
180
- (const
181
- (identifier)
182
- (const_record
183
- (constructor_name)
184
- (arguments
185
- (argument
186
- (string
187
- (quoted_content)))
188
- (argument
189
- (integer)))))
190
- (const
191
- (identifier)
192
- (const_record
193
- (constructor_name)
194
- (arguments
195
- (argument
196
- (label)
197
- (string
198
- (quoted_content)))
199
- (argument
200
- (label)
201
- (integer)))))
202
- (const
203
- (identifier)
204
- (const_record
205
- (remote_constructor_name
206
- (identifier)
207
- (type_identifier))
208
- (arguments
209
- (argument
210
- (label)
211
- (string
212
- (quoted_content))))))
213
- (const
214
- (identifier)
215
- (const_record
216
- (remote_constructor_name
217
- (identifier)
218
- (type_identifier))
219
- (arguments
220
- (argument
221
- (string
222
- (quoted_content)))))))
223
-
224
- ================================================================================
225
- Let
226
- ================================================================================
227
-
228
- module palm
229
-
230
- fn main() {
231
- let name = "John Doe"
232
- let pi = 3.14
233
- let data = Some("Json data")
234
- }
235
-
236
- --------------------------------------------------------------------------------
237
-
238
- (source_file
239
- (module
240
- (module_name))
241
- (function
242
- (identifier)
243
- (let
244
- (identifier)
245
- (string
246
- (quoted_content)))
247
- (let
248
- (identifier)
249
- (float))
250
- (let
251
- (identifier)
252
- (record
253
- (constructor_name)
254
- (arguments
255
- (argument
256
- (string
257
- (quoted_content))))))))
test/corpus/types.txt DELETED
@@ -1,129 +0,0 @@
1
- ================================================================================
2
- Types
3
- ================================================================================
4
-
5
- module palm
6
-
7
- type User(a) {
8
- Guest
9
- LoggedIn(name: a, age: Int)
10
- }
11
-
12
- type Result(a, b) {
13
- Ok(a)
14
- Error(b)
15
- }
16
-
17
- struct Cat[a](
18
- firstName: String
19
- middleName: String
20
- lastName: String
21
- age: Int
22
- shape: a
23
- call: fn (String) -> String
24
- )
25
-
26
- fn is_before(year: Int) -> Bool
27
- year < start_year
28
-
29
- fn is_during(year: Int) -> Bool:
30
- start_year <= year && year <= end_year
31
-
32
- var a = arr
33
- .map { it * 2 }
34
- .filter { it > 10 }
35
- .reduce { acc, n -> acc + n}, 0
36
-
37
- Row(
38
- alignment: 1,
39
- Container(
40
- H1("123")
41
- .color(Yellow)
42
- )
43
- )
44
-
45
- <row align={1}>
46
- <h1 color={Yellow}>
47
- 123
48
- </h1>
49
- </row>
50
-
51
- struct Cat[a] {
52
- var firstName: str
53
- var middleName: str
54
- var lastName: str
55
- var age: Int
56
- var shape: a
57
- var call: fn (String) -> String
58
-
59
- fn talk() {
60
- puts("meow")
61
- }
62
-
63
- fn walk() {
64
- puts("walking")
65
- }
66
- }
67
-
68
- --------------------------------------------------------------------------------
69
-
70
- (source_file
71
- (module
72
- (module_name))
73
- (enum
74
- (type_identifier)
75
- (generics
76
- (generic))
77
- (type_identifier)
78
- (type_identifier)
79
- (field
80
- (identifier)
81
- (generic))
82
- (field
83
- (identifier)
84
- (type
85
- (type_identifier))))
86
- (enum
87
- (type_identifier)
88
- (generics
89
- (generic)
90
- (generic))
91
- (type_identifier)
92
- (identifier)
93
- (type_identifier)
94
- (identifier))
95
- (struct
96
- (type_identifier)
97
- (generics
98
- (generic))
99
- (field
100
- (identifier)
101
- (ERROR)
102
- (type
103
- (type_identifier)))
104
- (field
105
- (identifier)
106
- (ERROR)
107
- (type
108
- (type_identifier)))
109
- (field
110
- (identifier)
111
- (ERROR)
112
- (type
113
- (type_identifier)))
114
- (field
115
- (identifier)
116
- (type
117
- (type_identifier)))
118
- (field
119
- (identifier)
120
- (generic))
121
- (field
122
- (identifier)
123
- (function_type
124
- (function_parameter_types
125
- (type
126
- (type_identifier)))
127
- (return_type
128
- (type
129
- (type_identifier)))))))
tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "module": "Node16",
5
+ "lib": ["ESNext", "DOM", "WebWorker"],
6
+ "sourceMap": true,
7
+ "outDir": "out",
8
+ "strict": true,
9
+ "noUnusedLocals": true,
10
+ "noImplicitReturns": true,
11
+ "noImplicitOverride": true,
12
+ "moduleResolution": "Node16",
13
+ "esModuleInterop": true,
14
+ "skipLibCheck": true,
15
+ "forceConsistentCasingInFileNames": true,
16
+ "rootDir": "src"
17
+ },
18
+ "include": [
19
+ "src/**/*.ts"
20
+ ],
21
+ "exclude": [
22
+ "node_modules"
23
+ ]
24
+ }
tsconfig.monarch.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2017",
4
+ "module": "ESNext",
5
+ "sourceMap": true,
6
+ "outDir": "syntaxes",
7
+ "strict": true,
8
+ "noUnusedLocals": true,
9
+ "noImplicitReturns": true,
10
+ "noImplicitOverride": true,
11
+ "moduleResolution": "node",
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true
15
+ },
16
+ "include": [
17
+ "syntaxes/palm.monarch.ts"
18
+ ],
19
+ "exclude": ["out", "node_modules"]
20
+ }
vite.bundle.config.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { defineConfig } from 'vite';
2
+ import path from 'node:path';
3
+
4
+ export default defineConfig({
5
+ build: {
6
+ lib: {
7
+ entry: path.resolve(__dirname, 'scripts', 'bundle.js'),
8
+ name: 'monaco-bundle',
9
+ fileName: () => 'index.js',
10
+ formats: ['es']
11
+ },
12
+ outDir: 'static/bundle',
13
+ assetsDir: 'static/bundle/assets',
14
+ emptyOutDir: true,
15
+ rollupOptions: {
16
+ output: {
17
+ name: 'monaco-bundle',
18
+ exports: 'named',
19
+ sourcemap: true,
20
+ assetFileNames: (assetInfo) => {
21
+ return `assets/${assetInfo.name}`;
22
+ }
23
+ }
24
+ }
25
+ }
26
+ });