lang: ast: implement support for multiple expression terminator tokens

This commit is contained in:
2024-12-07 21:28:25 +00:00
parent 7e3322e2ad
commit e8c30b65b5
12 changed files with 68 additions and 30 deletions

View File

@@ -6,6 +6,8 @@
#include <blue/core/queue.h>
#define EXPR_TERMINATOR_MAX 8
struct ivy_ast_node;
struct ivy_ast_msg_node;
@@ -65,10 +67,11 @@ struct expr_parser_state {
* the depth of the expression is recorded here. */
unsigned int s_subexpr_depth;
/* when this is set, the expression will be terminated when the
* specified token is encountered. the token that terminated the
* expression will not be consumed. */
unsigned int s_terminator;
/* the expression will be terminated when any token in this list
* is encountered. the token that terminated the expression will
* not be consumed. */
unsigned short s_terminators[EXPR_TERMINATOR_MAX];
unsigned short s_nr_terminators;
b_queue s_output_queue;
b_queue s_operator_stack;
@@ -88,6 +91,10 @@ struct expr_parser_state {
/* general functions */
extern void expr_add_terminator(struct expr_parser_state *state, unsigned short tok);
extern void expr_copy_terminators(const struct expr_parser_state *src, struct expr_parser_state *dest);
extern bool expr_terminates_at_token(struct expr_parser_state *state, unsigned short tok);
extern struct token_parse_result expr_finalise(
struct ivy_parser *ctx, struct expr_parser_state *state,
enum ivy_operator_precedence min_precedence, struct ivy_ast_node **expr);