hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 0018d3879dc237609aa3bd92ae7984f67e0282da
parent fb1e19477efd75e2018f401929d1bc1074e4c0fb
Author: Sebastian <sebastian@sebsite.pw>
Date:   Thu, 24 Feb 2022 20:47:32 -0500

ast: store location in enum_field

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/ast/type.ha | 1+
Mhare/parse/type.ha | 2++
Mhare/unparse/type.ha | 2++
3 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/hare/ast/type.ha b/hare/ast/type.ha @@ -20,6 +20,7 @@ export type builtin_type = enum { export type enum_field = struct { name: str, value: nullable *expr, + loc: lex::location, }; // enum { FOO = 0, BAR, ... } diff --git a/hare/parse/type.ha b/hare/parse/type.ha @@ -391,6 +391,7 @@ fn enum_type(lexer: *lex::lexer) (ast::_type | error) = { break; }; + const loc = lex::mkloc(lexer); let name = want(lexer, ltok::NAME)?; let value: nullable *ast::expr = if (try(lexer, ltok::EQUAL) is lex::token) @@ -400,6 +401,7 @@ fn enum_type(lexer: *lex::lexer) (ast::_type | error) = { append(membs, ast::enum_field { name = name.1 as str, value = value, + loc = loc, }); switch (want(lexer, ltok::COMMA, ltok::RBRACE)?.0) { diff --git a/hare/unparse/type.ha b/hare/unparse/type.ha @@ -280,10 +280,12 @@ fn type_test(t: ast::_type, expected: str) bool = { ast::enum_field { name = "FOO", value = null, + loc = loc, }, ast::enum_field { name = "BAR", value = &expr_void, + loc = loc, }, ], };