~repos /plum
git clone https://pyrossh.dev/repos/plum.git
A statically typed, imperative programming language inspired by rust, python
0d433790
—
pyrossh 11 months ago
improve string
- tooling/tree-sitter-plum/grammar.js +14 -1
- tooling/tree-sitter-plum/package.json +3 -16
- tooling/tree-sitter-plum/src/grammar.json +0 -0
- tooling/tree-sitter-plum/src/node-types.json +0 -0
- tooling/tree-sitter-plum/src/parser.c +0 -0
- tooling/tree-sitter-plum/src/scanner.c +14 -13
- tooling/tree-sitter-plum/src/tree_sitter/alloc.h +4 -4
- tooling/tree-sitter-plum/src/tree_sitter/array.h +2 -1
- tooling/tree-sitter-plum/src/tree_sitter/parser.h +1 -0
- tooling/tree-sitter-plum/test/corpus/type.txt +13 -1
- tooling/tree-sitter-plum/test/highlight/sample.txt +17 -0
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -447,7 +447,20 @@ module.exports = grammar({
|
|
|
447
447
|
|
|
448
448
|
interpolation: $ => seq(
|
|
449
449
|
'{',
|
|
450
|
+
choice(
|
|
451
|
+
$.binary_operator,
|
|
452
|
+
$.self,
|
|
453
|
+
$.identifier,
|
|
454
|
+
$.type_identifier,
|
|
455
|
+
$.string,
|
|
456
|
+
$.integer,
|
|
457
|
+
$.float,
|
|
458
|
+
$.unary_operator,
|
|
459
|
+
$.attribute,
|
|
460
|
+
$.fn_call,
|
|
461
|
+
$.class_call,
|
|
450
|
-
|
|
462
|
+
$.parenthesized_expression,
|
|
463
|
+
),
|
|
451
464
|
'}',
|
|
452
465
|
),
|
|
453
466
|
|
tooling/tree-sitter-plum/package.json
CHANGED
|
@@ -23,30 +23,17 @@
|
|
|
23
23
|
"node-addon-api": "^8.0.0",
|
|
24
24
|
"node-gyp-build": "^4.8.1"
|
|
25
25
|
},
|
|
26
|
-
"peerDependencies": {
|
|
27
|
-
"tree-sitter": "^0.21.0"
|
|
28
|
-
},
|
|
29
|
-
"peerDependenciesMeta": {
|
|
30
|
-
"tree_sitter": {
|
|
31
|
-
"optional": true
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
26
|
"devDependencies": {
|
|
35
27
|
"eslint": "^8.57.0",
|
|
36
28
|
"eslint-config-google": "^0.14.0",
|
|
37
29
|
"prebuildify": "^6.0.0",
|
|
38
|
-
"prettier": "^3.3.3"
|
|
30
|
+
"prettier": "^3.3.3"
|
|
39
|
-
"tree-sitter-cli": "^0.22.6"
|
|
40
31
|
},
|
|
41
32
|
"scripts": {
|
|
42
33
|
"install": "node-gyp-build",
|
|
43
34
|
"prebuildify": "prebuildify --napi --strip",
|
|
44
|
-
"build": "tree-sitter generate",
|
|
45
|
-
"build-wasm": "tree-sitter build --wasm",
|
|
46
35
|
"lint": "eslint grammar.js",
|
|
47
|
-
"format": "prettier -w ."
|
|
36
|
+
"format": "prettier -w ."
|
|
48
|
-
"parse": "tree-sitter parse",
|
|
49
|
-
"test": "tree-sitter test"
|
|
50
37
|
},
|
|
51
38
|
"repository": "https://github.com/pyrossh/plum",
|
|
52
39
|
"eslintConfig": {
|
|
@@ -98,4 +85,4 @@
|
|
|
98
85
|
"injection-regex": "^plum$"
|
|
99
86
|
}
|
|
100
87
|
]
|
|
101
|
-
}
|
|
88
|
+
}
|
tooling/tree-sitter-plum/src/grammar.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/node-types.json
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/parser.c
CHANGED
|
Binary file
|
tooling/tree-sitter-plum/src/scanner.c
CHANGED
|
@@ -302,19 +302,19 @@ bool tree_sitter_plum_external_scanner_scan(void *payload, TSLexer *lexer, const
|
|
|
302
302
|
Delimiter delimiter = new_delimiter();
|
|
303
303
|
|
|
304
304
|
bool has_flags = false;
|
|
305
|
-
while (lexer->lookahead) {
|
|
305
|
+
// while (lexer->lookahead) {
|
|
306
|
-
|
|
306
|
+
// if (lexer->lookahead == 'f' || lexer->lookahead == 'F') {
|
|
307
|
-
|
|
307
|
+
// set_format(&delimiter);
|
|
308
|
-
|
|
308
|
+
// } else if (lexer->lookahead == 'r' || lexer->lookahead == 'R') {
|
|
309
|
-
|
|
309
|
+
// set_raw(&delimiter);
|
|
310
|
-
|
|
310
|
+
// } else if (lexer->lookahead == 'b' || lexer->lookahead == 'B') {
|
|
311
|
-
|
|
311
|
+
// set_bytes(&delimiter);
|
|
312
|
-
|
|
312
|
+
// } else if (lexer->lookahead != 'u' && lexer->lookahead != 'U') {
|
|
313
|
-
|
|
313
|
+
// break;
|
|
314
|
-
|
|
314
|
+
// }
|
|
315
|
-
|
|
315
|
+
// has_flags = true;
|
|
316
|
-
|
|
316
|
+
// advance(lexer);
|
|
317
|
-
}
|
|
317
|
+
// }
|
|
318
318
|
|
|
319
319
|
if (lexer->lookahead == '`') {
|
|
320
320
|
set_end_character(&delimiter, '`');
|
|
@@ -333,6 +333,7 @@ bool tree_sitter_plum_external_scanner_scan(void *payload, TSLexer *lexer, const
|
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
335
|
} else if (lexer->lookahead == '"') {
|
|
336
|
+
set_format(&delimiter);
|
|
336
337
|
set_end_character(&delimiter, '"');
|
|
337
338
|
advance(lexer);
|
|
338
339
|
lexer->mark_end(lexer);
|
tooling/tree-sitter-plum/src/tree_sitter/alloc.h
CHANGED
|
@@ -12,10 +12,10 @@ extern "C" {
|
|
|
12
12
|
// Allow clients to override allocation functions
|
|
13
13
|
#ifdef TREE_SITTER_REUSE_ALLOCATOR
|
|
14
14
|
|
|
15
|
-
extern void *(*ts_current_malloc)(size_t);
|
|
16
|
-
extern void *(*
|
|
15
|
+
extern void *(*ts_current_malloc)(size_t size);
|
|
16
|
+
extern void *(*ts_current_calloc)(size_t count, size_t size);
|
|
17
|
-
extern void *(*ts_current_realloc)(void *, size_t);
|
|
17
|
+
extern void *(*ts_current_realloc)(void *ptr, size_t size);
|
|
18
|
-
extern void (*ts_current_free)(void *);
|
|
18
|
+
extern void (*ts_current_free)(void *ptr);
|
|
19
19
|
|
|
20
20
|
#ifndef ts_malloc
|
|
21
21
|
#define ts_malloc ts_current_malloc
|
tooling/tree-sitter-plum/src/tree_sitter/array.h
CHANGED
|
@@ -14,6 +14,7 @@ extern "C" {
|
|
|
14
14
|
#include <string.h>
|
|
15
15
|
|
|
16
16
|
#ifdef _MSC_VER
|
|
17
|
+
#pragma warning(push)
|
|
17
18
|
#pragma warning(disable : 4101)
|
|
18
19
|
#elif defined(__GNUC__) || defined(__clang__)
|
|
19
20
|
#pragma GCC diagnostic push
|
|
@@ -278,7 +279,7 @@ static inline void _array__splice(Array *self, size_t element_size,
|
|
|
278
279
|
#define _compare_int(a, b) ((int)*(a) - (int)(b))
|
|
279
280
|
|
|
280
281
|
#ifdef _MSC_VER
|
|
281
|
-
#pragma warning(
|
|
282
|
+
#pragma warning(pop)
|
|
282
283
|
#elif defined(__GNUC__) || defined(__clang__)
|
|
283
284
|
#pragma GCC diagnostic pop
|
|
284
285
|
#endif
|
tooling/tree-sitter-plum/src/tree_sitter/parser.h
CHANGED
|
@@ -47,6 +47,7 @@ struct TSLexer {
|
|
|
47
47
|
uint32_t (*get_column)(TSLexer *);
|
|
48
48
|
bool (*is_at_included_range_start)(const TSLexer *);
|
|
49
49
|
bool (*eof)(const TSLexer *);
|
|
50
|
+
void (*log)(const TSLexer *, const char *, ...);
|
|
50
51
|
};
|
|
51
52
|
|
|
52
53
|
typedef enum {
|
tooling/tree-sitter-plum/test/corpus/type.txt
CHANGED
|
@@ -17,7 +17,7 @@ withAge<Cat>(age: Int) -> Cat =
|
|
|
17
17
|
Cat(name: "", age: age)
|
|
18
18
|
|
|
19
19
|
toStr<Cat>() -> Str =
|
|
20
|
-
"Cat({
|
|
20
|
+
"Cat({self.name}, {self.age})"
|
|
21
21
|
|
|
22
22
|
--------------------------------------------------------------------------------
|
|
23
23
|
|
|
@@ -102,4 +102,16 @@ toStr<Cat>() -> Str =
|
|
|
102
102
|
(string
|
|
103
103
|
(string_start)
|
|
104
104
|
(string_content)
|
|
105
|
+
(interpolation
|
|
106
|
+
(attribute
|
|
107
|
+
(primary_expression
|
|
108
|
+
(self))
|
|
109
|
+
(identifier)))
|
|
110
|
+
(string_content)
|
|
111
|
+
(interpolation
|
|
112
|
+
(attribute
|
|
113
|
+
(primary_expression
|
|
114
|
+
(self))
|
|
115
|
+
(identifier)))
|
|
116
|
+
(string_content)
|
|
105
117
|
(string_end))))))
|
tooling/tree-sitter-plum/test/highlight/sample.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module std
|
|
2
|
+
|
|
3
|
+
type Cat(ToStr) =
|
|
4
|
+
name: Str
|
|
5
|
+
age: Int
|
|
6
|
+
|
|
7
|
+
withName<Cat>(name: Str) -> Cat =
|
|
8
|
+
Cat(name: name, age: self.age)
|
|
9
|
+
|
|
10
|
+
withAge<Cat>(age: Int) -> Cat =
|
|
11
|
+
Cat(name: self.name, age: age)
|
|
12
|
+
|
|
13
|
+
toStr<Cat>() -> Str =
|
|
14
|
+
"Cat({self.name}, {self.age})"
|
|
15
|
+
|
|
16
|
+
main() =
|
|
17
|
+
printLn("Hello world")
|