lang: ast: implement parsing of f-strings
This commit is contained in:
@@ -416,6 +416,29 @@ enum ivy_status expr_finalise_arith(
|
||||
return IVY_OK;
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_fstring(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_type == EXPR_TYPE_STMT) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_prev_component == EXPR_CMP_OPERAND) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
state->s_type = EXPR_TYPE_ARITH;
|
||||
state->s_prev_component = EXPR_CMP_OPERAND;
|
||||
state->s_prev_token = tok->t_type;
|
||||
|
||||
parser_push_state(ctx, IVY_AST_FSTRING, 0);
|
||||
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_operand(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
@@ -601,6 +624,47 @@ struct token_parse_result arith_parse_left_paren(
|
||||
return PARSE_RESULT(IVY_OK, 0);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_right_paren(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_type != EXPR_TYPE_ARITH) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_paren_depth == 0 && state->s_sub_type == EXPR_SUBTYPE_NONE) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_RIGHT_PAREN;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_left_brace(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
|
||||
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_right_brace(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_terminator == IVY_SYM_RIGHT_BRACE) {
|
||||
state->s_prev_token = IVY_SYM_RIGHT_BRACE;
|
||||
struct token_parse_result result = expr_finalise_and_return(ctx, state);
|
||||
result.r_flags = PARSE_REPEAT_TOKEN;
|
||||
return result;
|
||||
}
|
||||
|
||||
return PARSE_RESULT(IVY_ERR_NOT_SUPPORTED, 0);
|
||||
}
|
||||
|
||||
static struct ivy_ast_selector_node *keyword_selector_from_label_list(b_queue *labels)
|
||||
{
|
||||
struct ivy_ast_selector_node *sel
|
||||
@@ -693,24 +757,6 @@ static struct ivy_ast_msg_node *expr_finalise_complex_msg(
|
||||
return msg;
|
||||
}
|
||||
|
||||
struct token_parse_result arith_parse_right_paren(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
= parser_get_state(ctx, struct expr_parser_state);
|
||||
|
||||
if (state->s_type != EXPR_TYPE_ARITH) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_paren_depth == 0 && state->s_sub_type == EXPR_SUBTYPE_NONE) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
state->s_prev_token = IVY_SYM_RIGHT_PAREN;
|
||||
return expr_finalise_and_return(ctx, state);
|
||||
}
|
||||
|
||||
static enum ivy_status begin_cascade_operation(struct ivy_parser *ctx)
|
||||
{
|
||||
struct expr_parser_state *state
|
||||
|
||||
Reference in New Issue
Block a user