#include "ctx.h" #include bool parse_index( struct ivy_parser *parser, struct ivy_ast_node *container, struct ivy_ast_node **out) { if (!parse_symbol(parser, IVY_SYM_LEFT_BRACKET)) { parse_trace(parser, "expected `[` before subscript value"); return false; } struct ivy_ast_node *subscript = NULL; if (!parse_expr(parser, EXPR_PARSE_NORMAL, &subscript)) { parse_trace(parser, "invalid subscript value"); return false; } if (!parse_symbol(parser, IVY_SYM_RIGHT_BRACKET)) { parse_trace(parser, "expected `]` after subscript value"); return false; } struct ivy_ast_op_node *op_node = create_node(IVY_AST_OP); if (!op_node) { return false; } op_node->n_op = ivy_operator_get_by_id(IVY_OP_SUBSCRIPT); op_node->n_left = container; op_node->n_right = subscript; *out = generic_node(op_node); return true; }