lang: ast: misc formatting and reference fixes
This commit is contained in:
@@ -25,22 +25,23 @@ enum property_flags {
|
||||
|
||||
struct property_parser_state {
|
||||
struct parser_state s_base;
|
||||
enum property_type s_flags;
|
||||
enum property_flags s_flags;
|
||||
|
||||
struct ivy_ast_node *s_prev_node;
|
||||
|
||||
struct ivy_token *s_ident;
|
||||
struct ivy_ast_node *s_get, *s_set;
|
||||
|
||||
/* one of either 0, PROPERTY_GET, or PROPERTY_SET, depending on which part of the
|
||||
* property is currently being parsed. */
|
||||
/* one of either 0, PROPERTY_GET, or PROPERTY_SET, depending on which
|
||||
* part of the property is currently being parsed. */
|
||||
unsigned int s_cur_component;
|
||||
unsigned int s_prev;
|
||||
};
|
||||
|
||||
static void finalise_property(struct property_parser_state *state)
|
||||
{
|
||||
struct ivy_ast_property_node *prop = (struct ivy_ast_property_node *)state->s_base.s_node;
|
||||
struct ivy_ast_property_node *prop
|
||||
= (struct ivy_ast_property_node *)state->s_base.s_node;
|
||||
|
||||
if (state->s_flags & PROPERTY_GET) {
|
||||
prop->n_flags |= IVY_AST_PROPERTY_GET;
|
||||
@@ -53,7 +54,7 @@ static void finalise_property(struct property_parser_state *state)
|
||||
prop->n_ident = state->s_ident;
|
||||
prop->n_get = state->s_get;
|
||||
prop->n_set = state->s_set;
|
||||
|
||||
|
||||
state->s_ident = NULL;
|
||||
state->s_get = NULL;
|
||||
state->s_set = NULL;
|
||||
@@ -62,7 +63,8 @@ static void finalise_property(struct property_parser_state *state)
|
||||
static struct token_parse_result parse_ident(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (state->s_prev != IVY_SYM_DOLLAR) {
|
||||
/* the only ident we're looking for is the property name, which
|
||||
@@ -78,7 +80,8 @@ static struct token_parse_result parse_ident(
|
||||
static struct token_parse_result parse_pipe(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (state->s_prev != IVY_TOK_IDENT) {
|
||||
/* the only pipe we're looking for is the property
|
||||
@@ -103,7 +106,8 @@ static struct token_parse_result parse_pipe(
|
||||
static struct token_parse_result parse_left_paren(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (state->s_prev != IVY_TOK_IDENT) {
|
||||
/* the only left paren we're looking for comes after the
|
||||
@@ -127,8 +131,9 @@ static struct token_parse_result parse_left_paren(
|
||||
static struct token_parse_result parse_right_paren(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) != PROPERTY_AUTO) {
|
||||
/* can only use parenthesis in auto-properties. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
@@ -152,7 +157,8 @@ static struct token_parse_result parse_right_paren(
|
||||
static struct token_parse_result parse_equal_right_arrow(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) != PROPERTY_FULL) {
|
||||
/* this symbol cannot be used in auto-properties. */
|
||||
@@ -166,7 +172,9 @@ static struct token_parse_result parse_equal_right_arrow(
|
||||
|
||||
state->s_prev = IVY_SYM_EQUAL_RIGHT_ANGLE;
|
||||
|
||||
struct expr_parser_state *expr = (struct expr_parser_state *)parser_push_state(ctx, IVY_AST_EXPR, 0);
|
||||
struct expr_parser_state *expr
|
||||
= (struct expr_parser_state *)parser_push_state(
|
||||
ctx, IVY_AST_EXPR, 0);
|
||||
expr->s_terminator = IVY_SYM_COMMA;
|
||||
expr->s_subexpr_depth = 1;
|
||||
|
||||
@@ -176,14 +184,17 @@ static struct token_parse_result parse_equal_right_arrow(
|
||||
static struct token_parse_result parse_comma(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_FULL && state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_FULL
|
||||
&& state->s_prev != IVY_SYM_EQUAL_RIGHT_ANGLE) {
|
||||
/* this symbol can only be used after get or set */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_cur_component != PROPERTY_GET && state->s_cur_component != PROPERTY_SET) {
|
||||
if (state->s_cur_component != PROPERTY_GET
|
||||
&& state->s_cur_component != PROPERTY_SET) {
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
@@ -220,14 +231,16 @@ static struct token_parse_result parse_comma(
|
||||
static struct token_parse_result parse_dot(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) != PROPERTY_FULL) {
|
||||
/* this symbol cannot be used in auto-properties. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (state->s_cur_component != PROPERTY_GET && state->s_cur_component != PROPERTY_SET) {
|
||||
if (state->s_cur_component != PROPERTY_GET
|
||||
&& state->s_cur_component != PROPERTY_SET) {
|
||||
/* not actually parsing a getter or setter */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -264,19 +277,23 @@ static struct token_parse_result parse_dot(
|
||||
static struct token_parse_result parse_get(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (state->s_flags & PROPERTY_GET) {
|
||||
/* property already has getter defined */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_FULL && state->s_prev != IVY_SYM_PIPE && state->s_prev != IVY_SYM_COMMA) {
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_FULL
|
||||
&& state->s_prev != IVY_SYM_PIPE && state->s_prev != IVY_SYM_COMMA) {
|
||||
/* getter is not expected here. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_AUTO && state->s_prev != IVY_SYM_LEFT_PAREN && state->s_prev != IVY_SYM_COMMA) {
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_AUTO
|
||||
&& state->s_prev != IVY_SYM_LEFT_PAREN
|
||||
&& state->s_prev != IVY_SYM_COMMA) {
|
||||
/* getter is not expected here. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -291,19 +308,23 @@ static struct token_parse_result parse_get(
|
||||
static struct token_parse_result parse_set(
|
||||
struct ivy_parser *ctx, struct ivy_token *tok)
|
||||
{
|
||||
struct property_parser_state *state = parser_get_state(ctx, struct property_parser_state);
|
||||
struct property_parser_state *state
|
||||
= parser_get_state(ctx, struct property_parser_state);
|
||||
|
||||
if (state->s_flags & PROPERTY_SET) {
|
||||
/* property already has setter defined */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_FULL && state->s_prev != IVY_SYM_PIPE && state->s_prev != IVY_SYM_COMMA) {
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_FULL
|
||||
&& state->s_prev != IVY_SYM_PIPE && state->s_prev != IVY_SYM_COMMA) {
|
||||
/* setter is not expected here. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_AUTO && state->s_prev != IVY_SYM_LEFT_PAREN && state->s_prev != IVY_SYM_COMMA) {
|
||||
if (PROPERTY_TYPE(state->s_flags) == PROPERTY_AUTO
|
||||
&& state->s_prev != IVY_SYM_LEFT_PAREN
|
||||
&& state->s_prev != IVY_SYM_COMMA) {
|
||||
/* setter is not expected here. */
|
||||
return PARSE_RESULT(IVY_ERR_BAD_SYNTAX, 0);
|
||||
}
|
||||
@@ -318,7 +339,8 @@ static struct token_parse_result parse_set(
|
||||
static enum ivy_status add_child(
|
||||
struct parser_state *parent, struct ivy_ast_node *child)
|
||||
{
|
||||
struct property_parser_state *state = (struct property_parser_state *)parent;
|
||||
struct property_parser_state *state
|
||||
= (struct property_parser_state *)parent;
|
||||
|
||||
if (state->s_prev_node) {
|
||||
return IVY_ERR_BAD_SYNTAX;
|
||||
@@ -353,13 +375,16 @@ static void to_string(struct ivy_ast_node *node, b_string *str)
|
||||
{
|
||||
struct ivy_ast_property_node *prop = (struct ivy_ast_property_node *)node;
|
||||
|
||||
b_string_append_cstrf(str, "%s (%s) [", ivy_ast_node_type_to_string(node->n_type), prop->n_ident->t_str);
|
||||
b_string_append_cstrf(
|
||||
str, "%s (%s) [", ivy_ast_node_type_to_string(node->n_type),
|
||||
prop->n_ident->t_str);
|
||||
|
||||
if (prop->n_flags & IVY_AST_PROPERTY_GET) {
|
||||
b_string_append_cstr(str, "get");
|
||||
}
|
||||
|
||||
if ((prop->n_flags & IVY_AST_PROPERTY_GET) && prop->n_flags & IVY_AST_PROPERTY_SET) {
|
||||
if ((prop->n_flags & IVY_AST_PROPERTY_GET)
|
||||
&& prop->n_flags & IVY_AST_PROPERTY_SET) {
|
||||
b_string_append_cstr(str, ", ");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user