hare

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

commit 27bc1805b31bb31f4552137425b6b6f02517a070
parent a8ea19b4793d0332b5af65e2e7425dc5092313b7
Author: Alexey Yerin <yyp@disroot.org>
Date:   Sun, 18 Apr 2021 21:53:39 +0300

hare/parse,unparse: add size expression

Diffstat:
Mhare/parse/+test/expr.ha | 1+
Mhare/parse/expr.ha | 8+++++++-
Mhare/unparse/expr.ha | 6+++++-
3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -43,6 +43,7 @@ delete(x[..]); free(x); len([1, 2, 3, 4]); + size(u32); }; "); }; diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -147,7 +147,13 @@ fn measurement(lexer: *lex::lexer) (ast::expr | error) = { alloc(e): ast::len_expr; }, - ltok::SIZE => abort(), // TODO + ltok::SIZE => { + want(lexer, ltok::LPAREN)?; + let ty = _type(lexer)?; + want(lexer, ltok::RPAREN)?; + + alloc(ty): ast::size_expr; + }, ltok::OFFSET => abort(), // TODO }; }; diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha @@ -225,7 +225,11 @@ export fn expr( z += expr(out, indent, *e)?; z + fmt::fprint(out, ")")?; }, - e: ast::size_expr => abort(), + e: ast::size_expr => { + let z = fmt::fprint(out, "size(")?; + z += _type(out, indent, *e)?; + z + fmt::fprint(out, ")")?; + }, e: ast::offset_expr => abort(), e: ast::propagate_expr => { let z = expr(out, indent, *e)?;