hare

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

commit 87a80a82b7490f7fad4efb538520a8369cb1b76b
parent 1a7acbf2462917c018759634563432b927c1ea9a
Author: Drew DeVault <sir@cmpwn.com>
Date:   Fri, 16 Apr 2021 09:48:39 -0400

hare::parse: implement error propagation

Diffstat:
Mhare/parse/+test/expr.ha | 4+++-
Mhare/parse/expr.ha | 14+++++++++-----
Mhare/unparse/expr.ha | 5++++-
3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -26,7 +26,9 @@ "export fn main() void = x.y.z.q;\n" "export fn main() void = x().y;\n" "export fn main() void = x.42;\n" - "export fn main() void = x().y.0.q;\n"); + "export fn main() void = x().y.0.q;\n" + "export fn main() void = x?;\n" + "export fn main() void = x()?.y;\n"); }; @test fn unarithm() void = { diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -208,13 +208,17 @@ fn postfix(lexer: *lex::lexer, lvalue: (ast::expr | void)) (ast::expr | error) = ex: ast::expr => ex, }; - lvalue = match (try(lexer, ltok::LPAREN, - ltok::DOT, ltok::LBRACKET, ltok::QUESTION)) { + match (try(lexer, ltok::LPAREN, ltok::DOT, ltok::LBRACKET, ltok::QUESTION)) { tok: lex::token => switch (tok.0) { - ltok::LPAREN => call(lexer, lvalue)?, - ltok::DOT => postfix_dot(lexer, lvalue)?, + ltok::LPAREN => lvalue = call(lexer, lvalue)?, + ltok::DOT => lvalue = postfix_dot(lexer, lvalue)?, ltok::LBRACKET => abort(), // TODO: Indexing - ltok::QUESTION => abort(), // TODO: Propagation + ltok::QUESTION => { + // Crappy workaround for harec bug + // https://todo.sr.ht/~sircmpwn/hare/377 + let new = alloc(lvalue): ast::propagate_expr; + lvalue = new; + }, * => abort(), }, void => return lvalue, diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha @@ -92,7 +92,10 @@ export fn expr( e: ast::len_expr => abort(), e: ast::size_expr => abort(), e: ast::offset_expr => abort(), - e: ast::propagate_expr => abort(), + e: ast::propagate_expr => { + let z = expr(out, indent, *e)?; + z + fmt::fprintf(out, "?")?; + }, e: ast::return_expr => abort(), e: ast::slice_expr => abort(), e: ast::switch_expr => abort(),