~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
58cc293c
—
pyrossh 11 months ago
finish syntax
- tooling/tree-sitter-plum/Makefile +1 -1
- tooling/tree-sitter-plum/grammar.js +14 -19
- tooling/tree-sitter-plum/queries/plum/highlights.scm +2 -0
- tooling/tree-sitter-plum/queries/plum/indents.scm +28 -0
- tooling/tree-sitter-plum/queries/plum/injections.scm +2 -0
- tooling/tree-sitter-plum/src/grammar.json +0 -0
- tooling/tree-sitter-plum/src/node-types.json +0 -0
- tooling/tree-sitter-plum/src/parser.c +0 -0
- tooling/tree-sitter-plum/test/aa.plum +6 -1
- tooling/tree-sitter-plum/test/corpus/const.txt +115 -0
- tooling/tree-sitter-plum/test/corpus/for.txt +5 -1
- tooling/tree-sitter-plum/tree-sitter.json +3 -0
tooling/tree-sitter-plum/Makefile
CHANGED
|
@@ -4,4 +4,4 @@ build:
|
|
|
4
4
|
|
|
5
5
|
corpus_test:
|
|
6
6
|
tree-sitter generate
|
|
7
|
-
tree-sitter test
|
|
7
|
+
tree-sitter test
|
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -18,10 +18,6 @@ const PREC = {
|
|
|
18
18
|
call: 23,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
// a == 2 ? b : c
|
|
22
|
-
// a ?: b
|
|
23
|
-
|
|
24
|
-
|
|
25
21
|
const DEC_DIGITS = token(sep1(/[0-9]+/, /_+/));
|
|
26
22
|
const HEX_DIGITS = token(sep1(/[0-9a-fA-F]+/, /_+/));
|
|
27
23
|
const BIN_DIGITS = token(sep1(/[01]/, /_+/));
|
|
@@ -62,13 +58,12 @@ module.exports = grammar({
|
|
|
62
58
|
rules: {
|
|
63
59
|
source: ($) =>
|
|
64
60
|
seq(
|
|
65
|
-
optional(
|
|
61
|
+
optional($.module),
|
|
66
62
|
repeat($.import),
|
|
67
|
-
repeat(choice($.class, $.trait, $.enum, $.fn)),
|
|
63
|
+
repeat(choice($.class, $.trait, $.enum, $.fn, $.const)),
|
|
68
64
|
),
|
|
69
65
|
|
|
70
|
-
module: ($) => $.
|
|
66
|
+
module: ($) => seq("module", $.mod_identifier),
|
|
71
|
-
|
|
72
67
|
import: ($) => seq("import", $.url),
|
|
73
68
|
url: () => sep1(/[a-zA-Z_][a-zA-Z_0-9]*/, "/"),
|
|
74
69
|
|
|
@@ -173,6 +168,13 @@ module.exports = grammar({
|
|
|
173
168
|
$.primary_expression
|
|
174
169
|
),
|
|
175
170
|
|
|
171
|
+
const: ($) =>
|
|
172
|
+
seq(
|
|
173
|
+
field("left", commaSep1($.const_identifier)),
|
|
174
|
+
"=",
|
|
175
|
+
field("right", commaSep1($.expression)),
|
|
176
|
+
),
|
|
177
|
+
|
|
176
178
|
assign: ($) =>
|
|
177
179
|
seq(
|
|
178
180
|
field("left", commaSep1($.var_identifier)),
|
|
@@ -371,11 +373,11 @@ module.exports = grammar({
|
|
|
371
373
|
field("function", $.fn_identifier),
|
|
372
374
|
field(
|
|
373
375
|
"arguments",
|
|
374
|
-
$.
|
|
376
|
+
$.fn_argument_list,
|
|
375
377
|
),
|
|
376
378
|
)),
|
|
377
379
|
|
|
378
|
-
|
|
380
|
+
fn_argument_list: ($) =>
|
|
379
381
|
seq(
|
|
380
382
|
"(",
|
|
381
383
|
optional(
|
|
@@ -439,13 +441,6 @@ module.exports = grammar({
|
|
|
439
441
|
'}',
|
|
440
442
|
),
|
|
441
443
|
|
|
442
|
-
// _f_expression: $ => choice(
|
|
443
|
-
// $.expression,
|
|
444
|
-
// $.expression_list,
|
|
445
|
-
// $.pattern_list,
|
|
446
|
-
// $.yield,
|
|
447
|
-
// ),
|
|
448
|
-
|
|
449
444
|
escape_sequence: _ => token.immediate(prec(1, seq(
|
|
450
445
|
'\\',
|
|
451
446
|
choice(
|
|
@@ -479,14 +474,12 @@ module.exports = grammar({
|
|
|
479
474
|
seq(DEC_DIGITS, /[fF]/),
|
|
480
475
|
),
|
|
481
476
|
),
|
|
482
|
-
|
|
483
477
|
integer: ($) =>
|
|
484
478
|
choice(
|
|
485
479
|
token(seq(optional(/[1-9]/), DEC_DIGITS)),
|
|
486
480
|
token(seq("0", /[xX]/, HEX_DIGITS)),
|
|
487
481
|
token(seq("0", /[bB]/, BIN_DIGITS)),
|
|
488
482
|
),
|
|
489
|
-
|
|
490
483
|
self: (_) => /self/,
|
|
491
484
|
comment: _ => token(seq('#', /.*/)),
|
|
492
485
|
identifier: (_) => /[_a-z][_a-zA-Z0-9]*/,
|
|
@@ -495,6 +488,8 @@ module.exports = grammar({
|
|
|
495
488
|
b: (_) => token("b"),
|
|
496
489
|
c: (_) => token("c"),
|
|
497
490
|
d: (_) => token("d"),
|
|
491
|
+
mod_identifier: () => /[a-z]+(_[a-z0-9]+)*/, // lower snake case
|
|
492
|
+
const_identifier: (_) => /[A-Z]+(_[A-Z0-9]+)*/, // upper snake case
|
|
498
493
|
var_identifier: (_) => /[a-z]+(_[a-z0-9]+)*/, // lower snake case
|
|
499
494
|
fn_identifier: (_) => /[a-z][a-zA-Z0-9]*/, // camel case
|
|
500
495
|
type_identifier: (_) => /[A-Z][a-zA-Z0-9]*/, // capital case
|
tooling/tree-sitter-plum/queries/plum/highlights.scm
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
; (mod_identifier) @constant
|
|
1
2
|
(type_identifier) @type
|
|
2
3
|
(fn_identifier) @function
|
|
4
|
+
(const_identifier) @constant
|
|
3
5
|
|
|
4
6
|
(fn
|
|
5
7
|
(fn_identifier) @function)
|
tooling/tree-sitter-plum/queries/plum/indents.scm
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[
|
|
2
|
+
(enum)
|
|
3
|
+
(trait)
|
|
4
|
+
(class)
|
|
5
|
+
(fn)
|
|
6
|
+
(for)
|
|
7
|
+
(while)
|
|
8
|
+
(if)
|
|
9
|
+
(else)
|
|
10
|
+
(else_if)
|
|
11
|
+
(body)
|
|
12
|
+
] @indent
|
|
13
|
+
|
|
14
|
+
[
|
|
15
|
+
(if)
|
|
16
|
+
(for)
|
|
17
|
+
(while)
|
|
18
|
+
(fn)
|
|
19
|
+
(class)
|
|
20
|
+
(enum)
|
|
21
|
+
(trait)
|
|
22
|
+
] @extend
|
|
23
|
+
|
|
24
|
+
[
|
|
25
|
+
(return)
|
|
26
|
+
(break)
|
|
27
|
+
(continue)
|
|
28
|
+
] @extend.prevent-once
|
tooling/tree-sitter-plum/queries/plum/injections.scm
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
((comment) @injection.content
|
|
2
|
+
(#set! injection.language "comment"))
|
tooling/tree-sitter-plum/src/grammar.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/node-types.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/parser.c
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/test/aa.plum
CHANGED
|
@@ -3,7 +3,12 @@ module std
|
|
|
3
3
|
import std/int
|
|
4
4
|
import std/str
|
|
5
5
|
|
|
6
|
+
PI = 3.14
|
|
7
|
+
MSG = "Hello World"
|
|
8
|
+
SUM = 1 + {{2 * 3} / 4}
|
|
9
|
+
ENABLED = !False
|
|
10
|
+
|
|
6
|
-
# Animal is a behavior of every animal
|
|
11
|
+
# Animal is a set of behavior of every animal species
|
|
7
12
|
trait Animal =
|
|
8
13
|
speak() -> Str
|
|
9
14
|
|
tooling/tree-sitter-plum/test/corpus/const.txt
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
================================================================================
|
|
2
|
+
const
|
|
3
|
+
================================================================================
|
|
4
|
+
|
|
5
|
+
PI = 3.14
|
|
6
|
+
MSG = "Hello World"
|
|
7
|
+
SUM = 1 + {{2 * 3} / 4}
|
|
8
|
+
ENABLED = !False
|
|
9
|
+
OPEN = {count > 10} && {enabled == True} || {debug == False}
|
|
10
|
+
COUNTRIES_LIST = listOf("US", "INDIA", "CANADA")
|
|
11
|
+
|
|
12
|
+
--------------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
(source
|
|
15
|
+
(const
|
|
16
|
+
(const_identifier)
|
|
17
|
+
(expression
|
|
18
|
+
(primary_expression
|
|
19
|
+
(float))))
|
|
20
|
+
(const
|
|
21
|
+
(const_identifier)
|
|
22
|
+
(expression
|
|
23
|
+
(primary_expression
|
|
24
|
+
(string
|
|
25
|
+
(string_start)
|
|
26
|
+
(string_content)
|
|
27
|
+
(string_end)))))
|
|
28
|
+
(const
|
|
29
|
+
(const_identifier)
|
|
30
|
+
(expression
|
|
31
|
+
(primary_expression
|
|
32
|
+
(binary_operator
|
|
33
|
+
(primary_expression
|
|
34
|
+
(integer))
|
|
35
|
+
(primary_expression
|
|
36
|
+
(parenthesized_expression
|
|
37
|
+
(expression
|
|
38
|
+
(primary_expression
|
|
39
|
+
(binary_operator
|
|
40
|
+
(primary_expression
|
|
41
|
+
(parenthesized_expression
|
|
42
|
+
(expression
|
|
43
|
+
(primary_expression
|
|
44
|
+
(binary_operator
|
|
45
|
+
(primary_expression
|
|
46
|
+
(integer))
|
|
47
|
+
(primary_expression
|
|
48
|
+
(integer)))))))
|
|
49
|
+
(primary_expression
|
|
50
|
+
(integer)))))))))))
|
|
51
|
+
(const
|
|
52
|
+
(const_identifier)
|
|
53
|
+
(expression
|
|
54
|
+
(not_operator
|
|
55
|
+
(expression
|
|
56
|
+
(primary_expression
|
|
57
|
+
(type_identifier))))))
|
|
58
|
+
(const
|
|
59
|
+
(const_identifier)
|
|
60
|
+
(expression
|
|
61
|
+
(boolean_operator
|
|
62
|
+
(expression
|
|
63
|
+
(boolean_operator
|
|
64
|
+
(expression
|
|
65
|
+
(primary_expression
|
|
66
|
+
(parenthesized_expression
|
|
67
|
+
(expression
|
|
68
|
+
(comparison_operator
|
|
69
|
+
(primary_expression
|
|
70
|
+
(var_identifier))
|
|
71
|
+
(primary_expression
|
|
72
|
+
(integer)))))))
|
|
73
|
+
(expression
|
|
74
|
+
(primary_expression
|
|
75
|
+
(parenthesized_expression
|
|
76
|
+
(expression
|
|
77
|
+
(comparison_operator
|
|
78
|
+
(primary_expression
|
|
79
|
+
(var_identifier))
|
|
80
|
+
(primary_expression
|
|
81
|
+
(type_identifier)))))))))
|
|
82
|
+
(expression
|
|
83
|
+
(primary_expression
|
|
84
|
+
(parenthesized_expression
|
|
85
|
+
(expression
|
|
86
|
+
(comparison_operator
|
|
87
|
+
(primary_expression
|
|
88
|
+
(var_identifier))
|
|
89
|
+
(primary_expression
|
|
90
|
+
(type_identifier))))))))))
|
|
91
|
+
(const
|
|
92
|
+
(const_identifier)
|
|
93
|
+
(expression
|
|
94
|
+
(primary_expression
|
|
95
|
+
(fn_call
|
|
96
|
+
(fn_identifier)
|
|
97
|
+
(argument_list
|
|
98
|
+
(expression
|
|
99
|
+
(primary_expression
|
|
100
|
+
(string
|
|
101
|
+
(string_start)
|
|
102
|
+
(string_content)
|
|
103
|
+
(string_end))))
|
|
104
|
+
(expression
|
|
105
|
+
(primary_expression
|
|
106
|
+
(string
|
|
107
|
+
(string_start)
|
|
108
|
+
(string_content)
|
|
109
|
+
(string_end))))
|
|
110
|
+
(expression
|
|
111
|
+
(primary_expression
|
|
112
|
+
(string
|
|
113
|
+
(string_start)
|
|
114
|
+
(string_content)
|
|
115
|
+
(string_end))))))))))
|
tooling/tree-sitter-plum/test/corpus/for.txt
CHANGED
|
@@ -5,6 +5,8 @@ for
|
|
|
5
5
|
main() =
|
|
6
6
|
for i in 0..10
|
|
7
7
|
printLn("for")
|
|
8
|
+
break
|
|
9
|
+
continue
|
|
8
10
|
|
|
9
11
|
--------------------------------------------------------------------------------
|
|
10
12
|
|
|
@@ -30,4 +32,6 @@ main() =
|
|
|
30
32
|
(string
|
|
31
33
|
(string_start)
|
|
32
34
|
(string_content)
|
|
33
|
-
(string_end)))))))
|
|
35
|
+
(string_end)))))))
|
|
36
|
+
(break)
|
|
37
|
+
(continue))))))
|
tooling/tree-sitter-plum/tree-sitter.json
CHANGED
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"tags": [
|
|
15
15
|
"queries/tags.scm"
|
|
16
16
|
],
|
|
17
|
+
"indents": [
|
|
18
|
+
"queries/indents.scm"
|
|
19
|
+
],
|
|
17
20
|
"injection-regex": "plum"
|
|
18
21
|
}
|
|
19
22
|
],
|