plum
git clone https://git.pyrossh.dev/plum
A statically typed, imperative programming language inspired by rust, python
f047082
— Peter John
2026-08-09T18:37:28+05:30
feat(grammar): allow methods nested inside type/enum bodies
tooling/tree-sitter-plum/grammar.js
CHANGED
|
@@ -103,6 +103,7 @@ module.exports = grammar({
|
|
|
103
103
|
"=",
|
|
104
104
|
$._indent,
|
|
105
105
|
field("fields", optional(repeat(alias($.class_field, $.field)))),
|
|
106
|
+
field("methods", optional(repeat($.fn))),
|
|
106
107
|
$._dedent,
|
|
107
108
|
),
|
|
108
109
|
class_field: ($) => seq(field("name", $.var_identifier), ":", field("type", $.type)),
|
|
@@ -149,6 +150,7 @@ module.exports = grammar({
|
|
|
149
150
|
"=",
|
|
150
151
|
$._indent,
|
|
151
152
|
optional(repeat(alias($.enum_field, $.field))),
|
|
153
|
+
field("methods", optional(repeat($.fn))),
|
|
152
154
|
$._dedent,
|
|
153
155
|
),
|
|
154
156
|
|
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/corpus/enum.txt
CHANGED
|
@@ -50,3 +50,48 @@ enum Option =
|
|
|
50
50
|
(generic))
|
|
51
51
|
(field
|
|
52
52
|
(type_identifier))))
|
|
53
|
+
|
|
54
|
+
================================================================================
|
|
55
|
+
enum - nested method declaration
|
|
56
|
+
================================================================================
|
|
57
|
+
|
|
58
|
+
enum Step =
|
|
59
|
+
| ReadMin
|
|
60
|
+
| ReadMax
|
|
61
|
+
|
|
62
|
+
fun toNumber(self) -> Int =
|
|
63
|
+
match self
|
|
64
|
+
ReadMin => 0
|
|
65
|
+
ReadMax => 1
|
|
66
|
+
|
|
67
|
+
--------------------------------------------------------------------------------
|
|
68
|
+
|
|
69
|
+
(source
|
|
70
|
+
(enum
|
|
71
|
+
(type_identifier)
|
|
72
|
+
(field
|
|
73
|
+
(type_identifier))
|
|
74
|
+
(field
|
|
75
|
+
(type_identifier))
|
|
76
|
+
(fn
|
|
77
|
+
(fn_identifier)
|
|
78
|
+
(self)
|
|
79
|
+
(type
|
|
80
|
+
(type_identifier))
|
|
81
|
+
(body
|
|
82
|
+
(match
|
|
83
|
+
(expression
|
|
84
|
+
(primary_expression
|
|
85
|
+
(self)))
|
|
86
|
+
(case
|
|
87
|
+
(case_pattern
|
|
88
|
+
(type_identifier))
|
|
89
|
+
(expression
|
|
90
|
+
(primary_expression
|
|
91
|
+
(integer))))
|
|
92
|
+
(case
|
|
93
|
+
(case_pattern
|
|
94
|
+
(type_identifier))
|
|
95
|
+
(expression
|
|
96
|
+
(primary_expression
|
|
97
|
+
(integer)))))))))
|
tooling/tree-sitter-plum/test/corpus/type.txt
CHANGED
|
@@ -147,3 +147,35 @@ fun toStr<Cat>() -> Str =
|
|
|
147
147
|
(fn_identifier))))
|
|
148
148
|
(string_content)
|
|
149
149
|
(string_end)))))))
|
|
150
|
+
|
|
151
|
+
================================================================================
|
|
152
|
+
type - nested method declaration
|
|
153
|
+
================================================================================
|
|
154
|
+
|
|
155
|
+
type Cat =
|
|
156
|
+
name: Str
|
|
157
|
+
|
|
158
|
+
fun getName(self) -> Str =
|
|
159
|
+
self.name
|
|
160
|
+
|
|
161
|
+
--------------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
(source
|
|
164
|
+
(class
|
|
165
|
+
(type_identifier)
|
|
166
|
+
(field
|
|
167
|
+
(var_identifier)
|
|
168
|
+
(type
|
|
169
|
+
(type_identifier)))
|
|
170
|
+
(fn
|
|
171
|
+
(fn_identifier)
|
|
172
|
+
(self)
|
|
173
|
+
(type
|
|
174
|
+
(type_identifier))
|
|
175
|
+
(body
|
|
176
|
+
(expression
|
|
177
|
+
(primary_expression
|
|
178
|
+
(attribute
|
|
179
|
+
(primary_expression
|
|
180
|
+
(self))
|
|
181
|
+
(fn_identifier))))))))
|