hare

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

commit 4592f7a388f8667e702e44e466144c8a8759d53e
parent 1753cb5a50af49527349b0f8020acadd226ffc15
Author: Drew DeVault <sir@cmpwn.com>
Date:   Tue, 20 Apr 2021 08:33:00 -0400

hare::parse: implement global prototypes

Diffstat:
Mhare/ast/decl.ha | 2+-
Mhare/parse/decl.ha | 11+++++++----
2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/hare/ast/decl.ha b/hare/ast/decl.ha @@ -7,7 +7,7 @@ export type decl_global = struct { symbol: str, ident: ident, _type: _type, - init: expr, + init: nullable *expr, }; // type foo = int; diff --git a/hare/parse/decl.ha b/hare/parse/decl.ha @@ -38,15 +38,18 @@ fn decl_global( _: lex::token => attr_symbol(lexer)?, }; } else ""; - let ident = ident(lexer)?; + const ident = ident(lexer)?; want(lexer, ltok::COLON)?; let _type = _type(lexer)?; if (tok == ltok::CONST) { _type.flags |= ast::type_flags::CONST; }; - want(lexer, ltok::EQUAL)?; - let init = expression(lexer)?; - let btok = try(lexer, ltok::COMMA)?; + const init: nullable *ast::expr = + match (try(lexer, ltok::EQUAL)?) { + _: lex::token => alloc(expression(lexer)?), + _: void => null, + }; + const btok = try(lexer, ltok::COMMA)?; append(decl, ast::decl_global { is_const = tok == ltok::DEF, symbol = symbol,