~repos /plum

#treesitter#compiler#wasm

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

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


4aca0b2e pyrossh

11 months ago
improve highlights
test/main.py CHANGED
@@ -2,12 +2,16 @@ class ToStr:
2
2
  pass
3
3
 
4
4
 
5
+ def main(data: str):
6
+ pass
7
+
5
8
  class Int(ToStr):
6
9
  def __init__():
10
+ if a > 4"
7
- pass
11
+ pass
8
12
  format("%d")
9
13
 
10
- def toStr(self):
14
+ def toStr(self, name: Int):
11
15
  return f"Hello {self.name}"
12
16
 
13
17
 
tooling/tree-sitter-plum/Makefile ADDED
@@ -0,0 +1,5 @@
1
+ build:
2
+ tree-sitter build -o grammars/plum.so
3
+
4
+ corpus_test:
5
+ tree-sitter generate && tree-sitter test -i "type"
tooling/tree-sitter-plum/grammar.js CHANGED
@@ -57,8 +57,7 @@ module.exports = grammar({
57
57
  '}',
58
58
  'except',
59
59
  ],
60
- conflicts: ($) => [
60
+ conflicts: ($) => [],
61
- ],
62
61
  inline: ($) => [$.generic_type, $.generic],
63
62
  rules: {
64
63
  source: ($) =>
@@ -206,9 +205,6 @@ module.exports = grammar({
206
205
  seq(choice($.var_identier, $.type_identifier), optional(seq(".", $.identifier))),
207
206
  ),
208
207
 
209
- static_identifier: ($) =>
210
- seq($.type_identifier, "::", $.fn_identifier),
211
-
212
208
  for: ($) =>
213
209
  seq(
214
210
  "for",
@@ -321,7 +317,7 @@ module.exports = grammar({
321
317
  [prec.left, "^", PREC.xor],
322
318
  [prec.left, "<<", PREC.shift],
323
319
  [prec.left, ">>", PREC.shift],
324
- // [prec.left, "..", PREC.range],
320
+ [prec.left, "..", PREC.range],
325
321
  ];
326
322
  // @ts-ignore
327
323
  return choice(
@@ -513,6 +509,7 @@ module.exports = grammar({
513
509
  ),
514
510
 
515
511
  self: (_) => /self/,
512
+ comment: _ => token(seq('#', /.*/)),
516
513
  identifier: (_) => /[_a-z][_a-zA-Z0-9]*/,
517
514
  generic: ($) => choice($.a, $.b, $.c, $.d), // single letter
518
515
  a: (_) => token("a"),
tooling/tree-sitter-plum/queries/plum/highlights.scm CHANGED
@@ -1,26 +1,14 @@
1
- ; Identifier conventions
1
+ (type_identifier) @type
2
2
 
3
- ; Assume all-caps names are constants
4
- ((identifier) @constant
5
- (#match? @constant "^[A-Z][A-Z_]*$"))
6
-
7
- (type_identifier) @constant
8
- (identifier) @variable
9
-
10
- (trait
11
- name: (type_identifier) @type)
12
-
13
- (enum
14
- name: (type_identifier) @type)
15
-
16
- (fn
3
+ (fn
17
- name: (identifier) @function)
4
+ (identifier) @function)
18
5
 
19
- (integer) @number
6
+ (identifier) @variable
7
+ (integer) @constant.numeric.integer
20
- (float) @number
8
+ (float) @constant.numeric.float
21
9
  (comment) @comment
22
10
  (string) @string
23
- (escape_sequence) @escape
11
+ (escape_sequence) @constant.character.escape
24
12
  (self) @variable.builtin
25
13
 
26
14
  [
@@ -29,8 +17,7 @@
29
17
  "["
30
18
  "]"
31
19
  "{"
32
- "}"
20
+ "}"
33
- (module)
34
21
  ] @punctuation.bracket
35
22
 
36
23
  [
@@ -60,8 +47,8 @@
60
47
  "<>"
61
48
  "||"
62
49
  "&&"
63
- "in"
64
50
  "is"
51
+ "..."
65
52
  ] @operator
66
53
 
67
54
  [
@@ -70,3 +57,28 @@
70
57
  "enum"
71
58
  "trait"
72
59
  ] @keyword
60
+
61
+ [
62
+ "for"
63
+ "while"
64
+ "in"
65
+ ] @keyword.control.repeat
66
+
67
+ [
68
+ "if"
69
+ "else"
70
+ ] @keyword.control.conditional
71
+
72
+ [
73
+ ; "try"
74
+ "break"
75
+ "continue"
76
+ "return"
77
+ "assert"
78
+ ; "panic"
79
+ ] @keyword.control.return
80
+
81
+ ; "import" @keyword
82
+ ; "match" @keyword
83
+ ; "as" @keyword
84
+ ; "is" @keyword
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
@@ -1,5 +1,6 @@
1
1
  module std
2
2
 
3
+ # Cat is an animal that meows always
3
4
  type Cat(ToStr) =
4
5
  name: Str
5
6
  age: Int
@@ -11,7 +12,13 @@ withAge<Cat>(age: Int) -> Cat =
11
12
  Cat(name: self.name, age: age)
12
13
 
13
14
  toStr<Cat>() -> Str =
15
+ for i in 0..10
16
+ printLn("delta")
17
+ if dog > 1
18
+ printLn("Hellow")
19
+ else
20
+ printLn("New")
14
- "Cat({self.name}, {self.age})"
21
+ return "Cat({self.name}, {self.age})"
15
22
 
16
23
  main() =
17
24
  printLn("Hello world")
tooling/tree-sitter-plum/test/corpus/for.txt ADDED
@@ -0,0 +1,33 @@
1
+ ================================================================================
2
+ for
3
+ ================================================================================
4
+
5
+ main() =
6
+ for i in 0..10
7
+ printLn("for")
8
+
9
+ --------------------------------------------------------------------------------
10
+
11
+ (source
12
+ (fn
13
+ (identifier)
14
+ (body
15
+ (for
16
+ (identifier)
17
+ (primary_expression
18
+ (binary_operator
19
+ (primary_expression
20
+ (integer))
21
+ (primary_expression
22
+ (integer))))
23
+ (body
24
+ (primary_expression
25
+ (fn_call
26
+ (identifier)
27
+ (argument_list
28
+ (expression
29
+ (primary_expression
30
+ (string
31
+ (string_start)
32
+ (string_content)
33
+ (string_end))))))))))))
tooling/tree-sitter-plum/test/highlight/{sample.txt → sample.plum} RENAMED
File without changes