lang: ast: implement cascade operator parsing
This commit is contained in:
@@ -23,12 +23,16 @@ enum expr_subtype {
|
||||
EXPR_SUBTYPE_NONE = 0,
|
||||
/* generic parenthesis-enclosed arithmetic expressions */
|
||||
EXPR_SUBTYPE_PAREN,
|
||||
/* any kind of message */
|
||||
EXPR_SUBTYPE_MSG,
|
||||
/* keyword messages */
|
||||
EXPR_SUBTYPE_KEYWORD_MSG,
|
||||
/* expression delimited by labels */
|
||||
EXPR_SUBTYPE_KEYWORD_ARG,
|
||||
/* complex messages */
|
||||
EXPR_SUBTYPE_COMPLEX_MSG,
|
||||
/* message cascade operation */
|
||||
EXPR_SUBTYPE_CASCADE,
|
||||
};
|
||||
|
||||
enum expr_component {
|
||||
@@ -41,6 +45,8 @@ enum expr_component {
|
||||
struct expr_parser_state {
|
||||
struct parser_state s_base;
|
||||
enum expr_type s_type;
|
||||
enum expr_subtype s_sub_type;
|
||||
|
||||
/* for arithmetic expressions, this records whether the previous
|
||||
* component (either a token or parenthesised group of tokens) is an
|
||||
* operator, operand, or message */
|
||||
@@ -52,14 +58,15 @@ struct expr_parser_state {
|
||||
* of parentheses that this sub-expression is at */
|
||||
unsigned int s_paren_depth;
|
||||
|
||||
/* if this expression is parsing a sub-component of a larger expression,
|
||||
* 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;
|
||||
|
||||
/* all sub-expressions (i.e. those conatained within brackets,
|
||||
* keyword-messages and keyword-message args, etc) will have this set/ */
|
||||
enum expr_subtype s_subexpr;
|
||||
|
||||
b_queue s_output_queue;
|
||||
b_queue s_operator_stack;
|
||||
@@ -68,7 +75,13 @@ struct expr_parser_state {
|
||||
struct ivy_ast_node *s_recipient;
|
||||
struct ivy_ast_msg_node *s_msg;
|
||||
b_queue s_labels;
|
||||
b_queue s_args;
|
||||
|
||||
union {
|
||||
/* for keyword-messages, this is a list of arg values. */
|
||||
b_queue s_args;
|
||||
/* for cascade operators, this is a list of messages to send to the recipient. */
|
||||
b_queue s_cascade_msg;
|
||||
};
|
||||
};
|
||||
|
||||
extern void arith_push_operator(
|
||||
@@ -91,6 +104,8 @@ extern struct token_parse_result arith_parse_left_paren(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_right_paren(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_semicolon(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
extern struct token_parse_result arith_parse_dot(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user