lang: replace stack-based parser with a recursive parser

This commit is contained in:
2026-04-06 18:25:43 +01:00
parent 3a549aa6df
commit b904813cef
77 changed files with 2984 additions and 6499 deletions
+37
View File
@@ -0,0 +1,37 @@
#include "ctx.h"
#include <ivy/lang/ast.h>
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;
}