hare

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

commit 39d2f22f126ad91ece46cc7f9a6f7f76acf869d5
parent 08d2205c2a48d1157a356c81b08cfaca66b60cfe
Author: Sebastian <sebastian@sebsite.pw>
Date:   Fri, 13 May 2022 23:35:15 -0400

hare::parse: allow static binding in for expression

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

Diffstat:
Mhare/parse/+test/expr.ha | 3+++
Mhare/parse/expr.ha | 10+++++++---
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -191,6 +191,9 @@ for (let x = 10; x < 10; x) { x; }; + for (static let x = 0; x < 10) { + x; + }; }; "); }; diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -628,11 +628,15 @@ fn for_expr(lexer: *lex::lexer) (ast::expr | error) = { want(lexer, ltok::LPAREN)?; const bindings: nullable *ast::expr = - match (peek(lexer, ltok::LET, ltok::CONST)?) { + match (peek(lexer, ltok::LET, ltok::CONST, ltok::STATIC)?) { case void => yield null; - case lex::token => - const bindings = alloc(binding(lexer, false)?); + case let tok: lex::token => + let is_static = if (tok.0 == ltok::STATIC) { + want(lexer, ltok::STATIC)?; + yield true; + } else false; + const bindings = alloc(binding(lexer, is_static)?); want(lexer, ltok::SEMICOLON)?; yield bindings; };