tree-sitter-syscript 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/binding.gyp +35 -0
- package/grammar.js +124 -0
- package/package.json +52 -0
- package/queries/brackets.scm +3 -0
- package/queries/highlights.scm +92 -0
- package/queries/indents.scm +2 -0
- package/queries/locals.scm +10 -0
- package/queries/outlines.scm +3 -0
- package/queries/tags.scm +16 -0
- package/src/grammar.json +1748 -0
- package/src/node-types.json +1327 -0
- package/src/parser.c +13021 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter-syscript.wasm +0 -0
- package/tree-sitter.json +38 -0
package/README.md
ADDED
package/binding.gyp
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "tree_sitter_syscript_binding",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
7
|
+
],
|
|
8
|
+
"include_dirs": [
|
|
9
|
+
"src",
|
|
10
|
+
],
|
|
11
|
+
"sources": [
|
|
12
|
+
"bindings/node/binding.cc",
|
|
13
|
+
"src/parser.c",
|
|
14
|
+
],
|
|
15
|
+
"variables": {
|
|
16
|
+
"has_scanner": "<!(node -p \"fs.existsSync('src/scanner.c')\")"
|
|
17
|
+
},
|
|
18
|
+
"conditions": [
|
|
19
|
+
["has_scanner=='true'", {
|
|
20
|
+
"sources+": ["src/scanner.c"],
|
|
21
|
+
}],
|
|
22
|
+
["OS!='win'", {
|
|
23
|
+
"cflags_c": [
|
|
24
|
+
"-std=c11",
|
|
25
|
+
],
|
|
26
|
+
}, { # OS == "win"
|
|
27
|
+
"cflags_c": [
|
|
28
|
+
"/std:c11",
|
|
29
|
+
"/utf-8",
|
|
30
|
+
],
|
|
31
|
+
}],
|
|
32
|
+
],
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
package/grammar.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Syscript grammar for tree-sitter
|
|
3
|
+
* @author Aaron Menadue
|
|
4
|
+
* @license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/// <reference types="tree-sitter-cli/dsl" />
|
|
8
|
+
// @ts-check
|
|
9
|
+
|
|
10
|
+
module.exports = grammar({
|
|
11
|
+
name: "syscript",
|
|
12
|
+
|
|
13
|
+
extras: $ => [/\s/, $.comment],
|
|
14
|
+
|
|
15
|
+
conflicts: $ => [
|
|
16
|
+
[$.code_block, $.struct_literal]
|
|
17
|
+
],
|
|
18
|
+
|
|
19
|
+
rules: {
|
|
20
|
+
source_file: $ => seq(optional($.shebang), repeat(choice($.function, $.declaration, $.structs, $.classes, $.typedef, $.comment))),
|
|
21
|
+
|
|
22
|
+
shebang: $ => seq("#!", /.*/),
|
|
23
|
+
|
|
24
|
+
comment: $ => choice($.single_line_comment, $.documentation_comment, $.multi_line_comment, $.unclosed_multi_line_comment),
|
|
25
|
+
single_line_comment: $ => token(seq("//", /.*/)),
|
|
26
|
+
documentation_comment: $ => prec.left(1, token(seq("/**", /(.*)*(\n.*)*/, "*/"))),
|
|
27
|
+
multi_line_comment: $ => prec.left(1, token(seq("/*", /(.*)*(\n.*)*/, "*/"))),
|
|
28
|
+
|
|
29
|
+
classes: $ =>
|
|
30
|
+
seq("class", field("name", $.identifier), optional(seq("extends", $.identifier)), "{", field("fields", repeat(choice($.field, $.method))), "}"),
|
|
31
|
+
structs: $ => seq("struct", field("name", $.identifier), optional(seq("extends", $.identifier)), "{", field("fields", repeat($.field)), "}"),
|
|
32
|
+
|
|
33
|
+
field: $ => seq($.identifier, ":", $.type_signature, ";"),
|
|
34
|
+
property: $ => seq($.identifier, ":", $.value),
|
|
35
|
+
property_list: $ => seq($.property, repeat(seq(",", $.property))),
|
|
36
|
+
|
|
37
|
+
typedef: $ => seq("typedef", $.identifier, "=", $.type_signature, ";"),
|
|
38
|
+
|
|
39
|
+
function: $ => seq("fn", $.method),
|
|
40
|
+
method: $ => seq(field("name", $.identifier), $.param_list, optional(seq(":", choice($.type_signature, "noreturn"))), $.code_block),
|
|
41
|
+
param_list: $ => seq("(", optional(seq($.parameter, optional(seq(",", $.parameter)))), ")"),
|
|
42
|
+
parameter: $ => seq(optional("..."), $.identifier, ":", $.type_signature),
|
|
43
|
+
code_block: $ => seq("{", repeat($.statement), "}"),
|
|
44
|
+
|
|
45
|
+
declaration: $ => seq(choice($.let_declaration, $.const_declaration), ";"),
|
|
46
|
+
let_declaration: $ => seq("let", field("name", $.identifier), ":", field("type", $.type_signature), optional(seq("=", field("value", $.value)))),
|
|
47
|
+
const_declaration: $ => seq("const", field("name", $.identifier), ":", field("type", $.type_signature), "=", field("value", $.value)),
|
|
48
|
+
|
|
49
|
+
statement: $ => choice($.if_statement, $.while_loop, $.for_loop, $.declaration, seq(choice($.return_statement, $.control_flow, $.value), ";")),
|
|
50
|
+
|
|
51
|
+
return_statement: $ => seq("return", optional($.value)),
|
|
52
|
+
control_flow: $ => choice("break", "continue"),
|
|
53
|
+
|
|
54
|
+
routine: $ => choice($.code_block, $.statement),
|
|
55
|
+
if_statement: $ => prec.right(1, seq("if", field("condition", $.parenthesis_enclosed), $.routine, optional(seq("else", $.routine)))),
|
|
56
|
+
while_loop: $ => seq("while", field("condition", $.parenthesis_enclosed), $.routine),
|
|
57
|
+
|
|
58
|
+
for_loop: $ => seq("for", $.for_loop_def, $.routine),
|
|
59
|
+
for_loop_def: $ =>
|
|
60
|
+
seq(
|
|
61
|
+
"(",
|
|
62
|
+
field("declaration", optional($.let_declaration)),
|
|
63
|
+
";",
|
|
64
|
+
field("condition", optional($.value)),
|
|
65
|
+
";",
|
|
66
|
+
field("mutation", optional($.value)),
|
|
67
|
+
")",
|
|
68
|
+
),
|
|
69
|
+
|
|
70
|
+
value: $ => prec.left(1, seq($.singleton, repeat(seq($.operator, $.singleton)))),
|
|
71
|
+
value_list: $ => seq($.value, repeat(seq(",", $.value))),
|
|
72
|
+
parenthesis_enclosed: $ => seq("(", $.value, ")"),
|
|
73
|
+
|
|
74
|
+
singleton: $ =>
|
|
75
|
+
prec.left(
|
|
76
|
+
1,
|
|
77
|
+
seq(
|
|
78
|
+
optional($.type_cast),
|
|
79
|
+
optional(choice("++", "--", "new", repeat1(choice("!", "-", "~")))),
|
|
80
|
+
choice($.ref_parenthesis_enclosed, $.ref_primitive, $.reference),
|
|
81
|
+
optional(choice("++", "--")),
|
|
82
|
+
),
|
|
83
|
+
),
|
|
84
|
+
|
|
85
|
+
reference: $ => prec.left(1, seq($.identifier, repeat(choice($.accessor, $.func_call)), optional($.sub_reference))),
|
|
86
|
+
ref_parenthesis_enclosed: $ => prec.left(1, seq($.parenthesis_enclosed, repeat(choice($.accessor, $.func_call)), optional($.sub_reference))),
|
|
87
|
+
ref_primitive: $ => prec.left(1, seq($.primitive, repeat(choice($.accessor, $.func_call)), optional($.sub_reference))),
|
|
88
|
+
|
|
89
|
+
accessor: $ => seq("[", $.value, "]"),
|
|
90
|
+
func_call: $ => seq("(", optional($.value_list), ")"),
|
|
91
|
+
|
|
92
|
+
sub_reference: $ => seq(".", $.reference),
|
|
93
|
+
|
|
94
|
+
primitive: $ => choice($.struct_literal, $.array_literal, $.boolean_literal, $.char_literal, $.number_literal, $.string_literal, $.builtin_literal),
|
|
95
|
+
builtin_literal: $ => choice("this", "super", "null"),
|
|
96
|
+
array_literal: $ => seq("[", optional($.value_list), "]"),
|
|
97
|
+
struct_literal: $ => seq("{", optional($.property_list), "}"),
|
|
98
|
+
boolean_literal: $ => choice("true", "false"),
|
|
99
|
+
number_literal: $ => choice($.numeric, $.decimal_number, $.hex_number, $.binary_number),
|
|
100
|
+
|
|
101
|
+
string_literal: $ => seq('"', repeat(choice(/[^"\\\r\n]+/, $.escaped_character)), '"'),
|
|
102
|
+
|
|
103
|
+
char_literal: $ => seq("'", repeat(choice(/[^'\\\r\n]+/, $.escaped_character)), "'"),
|
|
104
|
+
|
|
105
|
+
escaped_character: $ => token(seq("\\", choice(/\r?\n/, /[^xuU0-7]/, /[0-7]{1,3}/, /x[0-9a-fA-F]{2}/, /u[0-9a-fA-F]{4}/, /U[0-9a-fA-F]{8}/))),
|
|
106
|
+
|
|
107
|
+
decimal_number: $ => prec.left(1, seq($.numeric, ".", $.numeric)),
|
|
108
|
+
hex_number: $ => /0x[0-9a-fA-F]*/,
|
|
109
|
+
binary_number: $ => /0b[01]*/,
|
|
110
|
+
|
|
111
|
+
type_signature: $ => choice(seq($.identifier, optional("[]")), "void"),
|
|
112
|
+
type_cast: $ => seq("<", $.type_signature, ">"),
|
|
113
|
+
|
|
114
|
+
operator: $ => choice($.logical_op, $.comparative_op, $.arithmetic_op, $.assignment_op),
|
|
115
|
+
|
|
116
|
+
logical_op: $ => choice("||", "&&"),
|
|
117
|
+
comparative_op: $ => choice("==", "!=", ">=", "<=", ">", "<"),
|
|
118
|
+
arithmetic_op: $ => choice("+", "-", "*", "/", "%", "&", "|", "^", "<<", ">>"),
|
|
119
|
+
assignment_op: $ => choice("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^="),
|
|
120
|
+
|
|
121
|
+
identifier: $ => /([a-zA-Z_][0-9a-zA-Z_]*)/,
|
|
122
|
+
numeric: $ => /([0-9][0-9_]*)/,
|
|
123
|
+
},
|
|
124
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter-syscript",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Syscript grammar for tree-sitter",
|
|
5
|
+
"repository": "https://github.com/tree-sitter/tree-sitter-syscript",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Aaron Menadue"
|
|
9
|
+
},
|
|
10
|
+
"main": "bindings/node",
|
|
11
|
+
"types": "bindings/node",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"incremental",
|
|
14
|
+
"parsing",
|
|
15
|
+
"tree-sitter",
|
|
16
|
+
"syscript"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"grammar.js",
|
|
20
|
+
"tree-sitter.json",
|
|
21
|
+
"binding.gyp",
|
|
22
|
+
"prebuilds/**",
|
|
23
|
+
"bindings/node/*",
|
|
24
|
+
"queries/*",
|
|
25
|
+
"src/**",
|
|
26
|
+
"*.wasm"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"node-addon-api": "^8.5.0",
|
|
30
|
+
"node-gyp-build": "^4.8.4",
|
|
31
|
+
"tree-sitter-syscript": "."
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"prebuildify": "^6.0.1",
|
|
35
|
+
"tree-sitter": "^0.22.4",
|
|
36
|
+
"tree-sitter-cli": "^0.25.10"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"tree-sitter": "^0.22.4"
|
|
40
|
+
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"tree-sitter": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"install": "node-gyp-build",
|
|
48
|
+
"prestart": "tree-sitter build --wasm",
|
|
49
|
+
"start": "tree-sitter playground",
|
|
50
|
+
"test": "node --test bindings/node/*_test.js"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
[
|
|
2
|
+
"if"
|
|
3
|
+
"else"
|
|
4
|
+
"while"
|
|
5
|
+
"for"
|
|
6
|
+
"continue"
|
|
7
|
+
"break"
|
|
8
|
+
"let"
|
|
9
|
+
"const"
|
|
10
|
+
"fn"
|
|
11
|
+
"return"
|
|
12
|
+
"class"
|
|
13
|
+
"struct"
|
|
14
|
+
"typedef"
|
|
15
|
+
"extends"
|
|
16
|
+
"new"
|
|
17
|
+
] @keyword
|
|
18
|
+
|
|
19
|
+
[
|
|
20
|
+
"void"
|
|
21
|
+
"noreturn"
|
|
22
|
+
"null"
|
|
23
|
+
"this"
|
|
24
|
+
"super"
|
|
25
|
+
] @constant.builtin
|
|
26
|
+
|
|
27
|
+
[
|
|
28
|
+
"{"
|
|
29
|
+
"}"
|
|
30
|
+
"("
|
|
31
|
+
")"
|
|
32
|
+
"["
|
|
33
|
+
"]"
|
|
34
|
+
] @puncuation.bracket
|
|
35
|
+
|
|
36
|
+
(type_cast
|
|
37
|
+
"<" @puncuation.bracket
|
|
38
|
+
(type_signature)
|
|
39
|
+
">" @puncuation.bracket)
|
|
40
|
+
|
|
41
|
+
(identifier) @variable
|
|
42
|
+
|
|
43
|
+
(comment) @comment
|
|
44
|
+
(documentation_comment) @comment.doc
|
|
45
|
+
|
|
46
|
+
(const_declaration
|
|
47
|
+
(identifier) @constant)
|
|
48
|
+
|
|
49
|
+
(shebang) @comment
|
|
50
|
+
|
|
51
|
+
(boolean_literal) @boolean
|
|
52
|
+
(number_literal) @number
|
|
53
|
+
[
|
|
54
|
+
(char_literal)
|
|
55
|
+
(string_literal)
|
|
56
|
+
] @string
|
|
57
|
+
|
|
58
|
+
(escaped_character) @string.escape
|
|
59
|
+
|
|
60
|
+
(method
|
|
61
|
+
(identifier) @function)
|
|
62
|
+
(reference
|
|
63
|
+
(identifier) @function
|
|
64
|
+
(func_call))
|
|
65
|
+
(reference
|
|
66
|
+
(identifier) @variable
|
|
67
|
+
(accessor)
|
|
68
|
+
(func_call))
|
|
69
|
+
(singleton
|
|
70
|
+
"new"
|
|
71
|
+
(reference
|
|
72
|
+
(identifier) @type))
|
|
73
|
+
|
|
74
|
+
(operator) @operator
|
|
75
|
+
|
|
76
|
+
(let_declaration (identifier) @variable)
|
|
77
|
+
(const_declaration (identifier) @constant)
|
|
78
|
+
|
|
79
|
+
(field
|
|
80
|
+
(identifier) @property)
|
|
81
|
+
(property
|
|
82
|
+
(identifier) @property)
|
|
83
|
+
|
|
84
|
+
(structs
|
|
85
|
+
(identifier) @type)
|
|
86
|
+
(classes
|
|
87
|
+
(identifier) @type)
|
|
88
|
+
|
|
89
|
+
(type_signature) @type
|
|
90
|
+
(type_signature (identifier) @type) @type
|
|
91
|
+
|
|
92
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
(method) @local.scope
|
|
2
|
+
(for_loop) @local.scope
|
|
3
|
+
(while_loop) @local.scope
|
|
4
|
+
|
|
5
|
+
(parameter (identifier) @local.definition)
|
|
6
|
+
|
|
7
|
+
(let_declaration (identifier) @local.definition)
|
|
8
|
+
(const_declaration (identifier) @local.definition)
|
|
9
|
+
|
|
10
|
+
(singleton (reference (identifier) @local.reference))
|
package/queries/tags.scm
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
(method
|
|
3
|
+
name: (identifier) @name) @definition.function
|
|
4
|
+
(classes
|
|
5
|
+
name: (identifier) @name) @definition.class
|
|
6
|
+
(structs
|
|
7
|
+
name: (identifier) @name) @definition.interface
|
|
8
|
+
|
|
9
|
+
(reference
|
|
10
|
+
((identifier) @name
|
|
11
|
+
(#is? function))) @reference.call
|
|
12
|
+
|
|
13
|
+
(singleton
|
|
14
|
+
"new"
|
|
15
|
+
(reference
|
|
16
|
+
(identifier) @name)) @reference.implementation
|