commit 9171150b2dfd483bede012670ac7d28189a6c5d2
parent 084fa357e671fa379ab6b572538f6d33330afb6b
Author: Sebastian <sebastian@sebsite.pw>
Date: Mon, 28 Mar 2022 17:35:54 -0400
parse: allow enums with rune storage
Implements: https://todo.sr.ht/~sircmpwn/hare/368
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/hare/parse/+test/types.ha b/hare/parse/+test/types.ha
@@ -41,5 +41,11 @@ export type bar = enum uint {
Z,
Q,
};
+export type baz = enum rune {
+ X = void,
+ Y = void,
+ Z,
+ Q,
+};
");
};
diff --git a/hare/parse/type.ha b/hare/parse/type.ha
@@ -374,13 +374,19 @@ fn array_slice_type(lexer: *lex::lexer) (ast::_type | error) = {
fn enum_type(lexer: *lex::lexer) (ast::_type | error) = {
let start = want(lexer, ltok::ENUM)?;
- const storage = match (try(lexer, ltok::LBRACE)?) {
+ const storage = match (try(lexer, ltok::LBRACE, ltok::RUNE)?) {
case void =>
let storage = integer_type(lexer)?;
want(lexer, ltok::LBRACE)?;
yield storage;
- case lex::token =>
- yield builtin_type::INT;
+ case let tok: lex::token =>
+ yield switch (tok.0) {
+ case ltok::LBRACE =>
+ yield builtin_type::INT;
+ case ltok::RUNE =>
+ want(lexer, ltok::LBRACE)?;
+ yield builtin_type::RUNE;
+ };
};
let membs: []ast::enum_field = [];