plum

#treesitter#compiler#wasm

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

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


8554271Peter John 2026-08-09T18:45:49+05:30
feat(grammar): add enum discriminant-value declarations
tooling/tree-sitter-plum/grammar.js CHANGED
@@ -147,6 +147,7 @@ module.exports = grammar({
147
147
  seq(
148
148
  "enum",
149
149
  field("name", $.type_identifier),
150
+ field("params", optional(seq("(", commaSep1($.enum_param), ")"))),
150
151
  "=",
151
152
  $._indent,
152
153
  optional(repeat(alias($.enum_field, $.field))),
@@ -154,11 +155,20 @@ module.exports = grammar({
154
155
  $._dedent,
155
156
  ),
156
157
 
158
+ enum_param: ($) =>
159
+ seq(field("name", $.var_identifier), ":", field("type", $.type)),
160
+
157
161
  enum_field: ($) =>
158
162
  seq(
159
163
  "|",
160
164
  field("name", $.type_identifier),
165
+ field(
166
+ "parameters",
167
+ optional(choice(
161
- field("parameters", optional(seq("[", commaSep1(choice($.type_identifier, $.generic)), "]"))),
168
+ seq("[", commaSep1(choice($.type_identifier, $.generic)), "]"), // existing: generic type payload
169
+ seq("(", commaSep1($.expression), ")"), // new: discriminant value literals
170
+ )),
171
+ ),
162
172
  ),
163
173
 
164
174
  fn: ($) =>
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
@@ -95,3 +95,31 @@ enum Step =
95
95
  (expression
96
96
  (primary_expression
97
97
  (integer)))))))))
98
+
99
+ ================================================================================
100
+ enum - discriminant values
101
+ ================================================================================
102
+
103
+ enum Step(n: Int) =
104
+ | ReadMin(0)
105
+ | ReadMax(1)
106
+
107
+ --------------------------------------------------------------------------------
108
+
109
+ (source
110
+ (enum
111
+ (type_identifier)
112
+ (enum_param
113
+ (var_identifier)
114
+ (type
115
+ (type_identifier)))
116
+ (field
117
+ (type_identifier)
118
+ (expression
119
+ (primary_expression
120
+ (integer))))
121
+ (field
122
+ (type_identifier)
123
+ (expression
124
+ (primary_expression
125
+ (integer))))))