hare

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

commit f7f2a36f95c53698a0ac6849b447f419ac1c3869
parent cc0de6cd70190ac5e17866439b582f56ee314d00
Author: Sebastian <sebastian@sebsite.pw>
Date:   Mon, 28 Mar 2022 17:27:39 -0400

parse: assert that insert object is indexing expr

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

Diffstat:
Mhare/parse/expr.ha | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -205,8 +205,7 @@ fn append_insert_expr( want(lexer, ltok::LPAREN)?; const object = if (tok.0 == ltok::APPEND) objsel(lexer)? - else postfix(lexer, void)?; - // TODO: Assert that this was an indexing expression + else idxexpr(lexer)?; want(lexer, ltok::COMMA)?; let variadic: nullable *ast::expr = null; @@ -708,6 +707,14 @@ fn objsel(lexer: *lex::lexer) (ast::expr | error) = { return expr; }; +fn idxexpr(lexer: *lex::lexer) (ast::expr | error) = { + const expr = postfix(lexer, void)?; + synassert(lex::mkloc(lexer), expr.expr is ast::access_expr + && expr.expr as ast::access_expr is ast::access_index, + "Expected indexing expression")?; + return expr; +}; + fn plain_expression(lexer: *lex::lexer) (ast::expr | error) = { let tok = peek(lexer)? as lex::token; if (tok.0 >= ltok::LIT_U8 && tok.0 <= ltok::LAST_LITERAL) {