diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-11-19 19:11:52 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-11-19 19:51:49 +0100 |
commit | a162cf7aadacd08eb11af072bcb9dd041866b579 (patch) | |
tree | e0a829f63600c869268d61d6fecd1663bd65c5ea /parser.y | |
parent | ff441aa908ad48ab5d197f4efd7d6e879fe185a2 (diff) |
treewide: rebrand to ucode
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 108 |
1 files changed, 54 insertions, 54 deletions
@@ -15,7 +15,7 @@ */ %token_type {uint32_t} -%extra_argument {struct ut_state *s} +%extra_argument {struct uc_state *s} %nonassoc T_LEXP T_REXP T_LSTM T_RSTM. @@ -59,32 +59,32 @@ #define YYNOERRORRECOVERY #define new_op(type, val, ...) \ - ut_new_op(s, type, val, ##__VA_ARGS__, UINT32_MAX) + uc_new_op(s, type, val, ##__VA_ARGS__, UINT32_MAX) #define wrap_op(op, ...) \ - ut_wrap_op(s, op, ##__VA_ARGS__, UINT32_MAX) + uc_wrap_op(s, op, ##__VA_ARGS__, UINT32_MAX) #define append_op(op1, op2) \ - ut_append_op(s, op1, op2) + uc_append_op(s, op1, op2) #define no_empty_obj(op) \ - ut_no_empty_obj(s, op) + uc_no_empty_obj(s, op) static inline uint32_t -ut_no_empty_obj(struct ut_state *s, uint32_t off) +uc_no_empty_obj(struct uc_state *s, uint32_t off) { - struct ut_op *op = ut_get_op(s, off); + struct uc_op *op = uc_get_op(s, off); return (!op || op->type != T_LBRACE || op->tree.operand[0]) ? off : 0; } static inline uint32_t -ut_add_else(struct ut_state *s, uint32_t off, uint32_t add) +uc_add_else(struct uc_state *s, uint32_t off, uint32_t add) { - struct ut_op *tail = ut_get_op(s, off); + struct uc_op *tail = uc_get_op(s, off); while (tail && tail->tree.operand[2]) - tail = ut_get_op(s, tail->tree.operand[2]); + tail = uc_get_op(s, tail->tree.operand[2]); tail->tree.operand[2] = add; @@ -92,21 +92,21 @@ ut_add_else(struct ut_state *s, uint32_t off, uint32_t add) } static inline uint32_t -ut_expect_token(struct ut_state *s, uint32_t off, int token) +uc_expect_token(struct uc_state *s, uint32_t off, int token) { uint64_t tokens[(__T_MAX + 63) & -64] = {}; tokens[token / 64] |= ((uint64_t)1 << (token % 64)); - ut_parse_error(s, off, tokens, token); + uc_parse_error(s, off, tokens, token); return 0; } static inline uint32_t -_ut_check_op_seq_types(struct ut_state *s, uint32_t off, ...) +_uc_check_op_seq_types(struct uc_state *s, uint32_t off, ...) { uint64_t tokens[(__T_MAX + 63) & -64] = {}; - struct ut_op *arg = ut_get_op(s, off); + struct uc_op *arg = uc_get_op(s, off); int token, max_token = 0; va_list ap; @@ -121,26 +121,26 @@ _ut_check_op_seq_types(struct ut_state *s, uint32_t off, ...) while (arg) { if (!(tokens[arg->type / 64] & ((uint64_t)1 << (arg->type % 64)))) { - ut_parse_error(s, off, tokens, max_token); + uc_parse_error(s, off, tokens, max_token); return 0; } - arg = ut_get_op(s, arg->tree.next); + arg = uc_get_op(s, arg->tree.next); } return off; } -#define ut_check_op_seq_types(s, off, ...) _ut_check_op_seq_types(s, off, __VA_ARGS__, 0) +#define uc_check_op_seq_types(s, off, ...) _uc_check_op_seq_types(s, off, __VA_ARGS__, 0) static inline uint32_t -ut_reject_local(struct ut_state *s, uint32_t off) +uc_reject_local(struct uc_state *s, uint32_t off) { - struct ut_op *op = ut_get_op(s, off); + struct uc_op *op = uc_get_op(s, off); if (op->type == T_LOCAL) { - ut_new_exception(s, op->off, "Syntax error: Unexpected token\nDeclaration not allowed in this context"); + uc_new_exception(s, op->off, "Syntax error: Unexpected token\nDeclaration not allowed in this context"); return 0; } @@ -149,45 +149,45 @@ ut_reject_local(struct ut_state *s, uint32_t off) } static inline uint32_t -ut_check_for_in(struct ut_state *s, uint32_t off) +uc_check_for_in(struct uc_state *s, uint32_t off) { - struct ut_op *op = ut_get_op(s, off); - struct ut_op *arg; + struct uc_op *op = uc_get_op(s, off); + struct uc_op *arg; uint32_t idx = 0; - arg = (op->type == T_LOCAL) ? ut_get_op(s, op->tree.operand[0]) : op; + arg = (op->type == T_LOCAL) ? uc_get_op(s, op->tree.operand[0]) : op; if (arg->type == T_LABEL) { - idx = ut_get_off(s, arg); + idx = uc_get_off(s, arg); if (!arg->tree.next) { - ut_new_exception(s, arg->off + json_object_get_string_len(arg->val), + uc_new_exception(s, arg->off + json_object_get_string_len(arg->val), "Syntax error: Unexpected token\nExpecting ',' or 'in'"); return 0; } - arg = ut_get_op(s, arg->tree.next); + arg = uc_get_op(s, arg->tree.next); } - if (arg->type != T_IN || arg->tree.next || ut_get_op(s, arg->tree.operand[0])->type != T_LABEL) { + if (arg->type != T_IN || arg->tree.next || uc_get_op(s, arg->tree.operand[0])->type != T_LABEL) { if (arg->type == T_IN && arg->tree.next) - arg = ut_get_op(s, arg->tree.next); + arg = uc_get_op(s, arg->tree.next); - ut_new_exception(s, arg->off, "Syntax error: Invalid for-in expression"); + uc_new_exception(s, arg->off, "Syntax error: Invalid for-in expression"); return 0; } /* transform T_LABEL->T_IN(T_LABEL, ...) into T_IN(T_LABEL->T_LABEL, ...) */ if (idx) { - ut_get_op(s, idx)->tree.next = 0; + uc_get_op(s, idx)->tree.next = 0; arg->tree.operand[0] = append_op(idx, arg->tree.operand[0]); if (op->type == T_LOCAL) - op->tree.operand[0] = ut_get_off(s, arg); + op->tree.operand[0] = uc_get_off(s, arg); else - off = ut_get_off(s, arg); + off = uc_get_off(s, arg); } return off; @@ -206,7 +206,7 @@ ut_check_for_in(struct ut_state *s, uint32_t off) } } - ut_parse_error(s, TOKEN, tokens, max_token); + uc_parse_error(s, TOKEN, tokens, max_token); } @@ -249,13 +249,13 @@ sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN stmt(D) T_ELSE stmt(E). sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN stmt(D). [T_IF] { A = wrap_op(B, C, no_empty_obj(D)); } sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) sel_elifs(E) T_ELSE chunks(F) T_ENDIF. - { A = ut_add_else(s, wrap_op(B, C, D, E), F); } + { A = uc_add_else(s, wrap_op(B, C, D, E), F); } sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) T_ELSE chunks(E) T_ENDIF. { A = wrap_op(B, C, D, E); } sel_stmt(A) ::= T_IF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) T_ENDIF. [T_IF] { A = wrap_op(B, C, D); } -sel_elifs(A) ::= sel_elifs(B) sel_elif(C). { A = ut_add_else(s, B, C); } +sel_elifs(A) ::= sel_elifs(B) sel_elif(C). { A = uc_add_else(s, B, C); } sel_elifs(A) ::= sel_elif(B). { A = B; } sel_elif(A) ::= T_ELIF(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D). @@ -266,9 +266,9 @@ iter_stmt(A) ::= T_WHILE(B) T_LPAREN exp(C) T_RPAREN stmt(D). iter_stmt(A) ::= T_WHILE(B) T_LPAREN exp(C) T_RPAREN T_COLON chunks(D) T_ENDWHILE. { A = wrap_op(B, C, D); } iter_stmt(A) ::= T_FOR(B) paren_exp(C) stmt(D). - { A = wrap_op(B, ut_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); ut_get_op(s, A)->is_for_in = 1; } + { A = wrap_op(B, uc_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); uc_get_op(s, A)->is_for_in = 1; } iter_stmt(A) ::= T_FOR(B) paren_exp(C) T_COLON chunks(D) T_ENDFOR. - { A = wrap_op(B, ut_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); ut_get_op(s, A)->is_for_in = 1; } + { A = wrap_op(B, uc_check_for_in(s, C), NULL, NULL, no_empty_obj(D)); uc_get_op(s, A)->is_for_in = 1; } iter_stmt(A) ::= T_FOR(B) T_LPAREN decl_or_exp(C) exp_stmt(D) T_RPAREN stmt(E). { A = wrap_op(B, C, D, NULL, no_empty_obj(E)); } iter_stmt(A) ::= T_FOR(B) T_LPAREN decl_or_exp(C) exp_stmt(D) exp(E) T_RPAREN stmt(F). @@ -311,8 +311,8 @@ switch_case(A) ::= T_CASE(B) exp(C) T_COLON stmts(D). { A = wrap_op(B, C, D); } switch_case(A) ::= T_CASE(B) exp(C) T_COLON. { A = wrap_op(B, C); } switch_case(A) ::= T_DEFAULT(B) T_COLON stmts(C). { A = wrap_op(B, C); } -args(A) ::= sargs(B) T_COMMA T_ELLIP T_LABEL(C). { A = append_op(B, C); ut_get_op(s, C)->is_ellip = 1; } -args(A) ::= T_ELLIP T_LABEL(B). { A = B; ut_get_op(s, B)->is_ellip = 1; } +args(A) ::= sargs(B) T_COMMA T_ELLIP T_LABEL(C). { A = append_op(B, C); uc_get_op(s, C)->is_ellip = 1; } +args(A) ::= T_ELLIP T_LABEL(B). { A = B; uc_get_op(s, B)->is_ellip = 1; } args(A) ::= sargs(B). { A = B; } sargs(A) ::= sargs(B) T_COMMA T_LABEL(C). { A = append_op(B, C); } @@ -327,7 +327,7 @@ ret_stmt(A) ::= T_RETURN(B) T_SCOL. { A = B; } break_stmt(A) ::= T_BREAK(B) T_SCOL. { A = B; } break_stmt(A) ::= T_CONTINUE(B) T_SCOL. { A = B; } -decl_stmt(A) ::= T_LOCAL(B) decls(C) T_SCOL. { A = wrap_op(B, ut_check_op_seq_types(s, C, T_ASSIGN, T_LABEL)); } +decl_stmt(A) ::= T_LOCAL(B) decls(C) T_SCOL. { A = wrap_op(B, uc_check_op_seq_types(s, C, T_ASSIGN, T_LABEL)); } decls(A) ::= decls(B) T_COMMA decl(C). { A = append_op(B, C); } decls(A) ::= decl(B). { A = B; } @@ -358,13 +358,13 @@ assign_exp(A) ::= unary_exp(B) T_ASBOR arrow_exp(C). { A = new_op(T_BOR, NULL, B assign_exp(A) ::= arrow_exp(B). { A = B; } arrow_exp(A) ::= unary_exp(B) T_ARROW(C) arrowfn_body(D). - { A = wrap_op(C, 0, ut_check_op_seq_types(s, B, T_LABEL), D); } + { A = wrap_op(C, 0, uc_check_op_seq_types(s, B, T_LABEL), D); } arrow_exp(A) ::= T_LPAREN T_RPAREN T_ARROW(C) arrowfn_body(D). { A = wrap_op(C, 0, 0, D); } arrow_exp(A) ::= T_LPAREN T_ELLIP T_LABEL(B) T_RPAREN T_ARROW(C) arrowfn_body(D). - { A = wrap_op(C, 0, B, D); ut_get_op(s, B)->is_ellip = 1; } + { A = wrap_op(C, 0, B, D); uc_get_op(s, B)->is_ellip = 1; } arrow_exp(A) ::= T_LPAREN exp(B) T_COMMA T_ELLIP T_LABEL(C) T_RPAREN T_ARROW(D) arrowfn_body(E). - { A = append_op(B, C); A = wrap_op(D, 0, ut_check_op_seq_types(s, A, T_LABEL), E); ut_get_op(s, C)->is_ellip = 1; } + { A = append_op(B, C); A = wrap_op(D, 0, uc_check_op_seq_types(s, A, T_LABEL), E); uc_get_op(s, C)->is_ellip = 1; } arrow_exp(A) ::= ternary_exp(B). { A = B; } ternary_exp(A) ::= or_exp(B) T_QMARK(C) assign_exp(D) T_COLON ternary_exp(E). @@ -420,14 +420,14 @@ unary_exp(A) ::= T_COMPL(B) unary_exp(C). { A = wrap_op(B, C); } unary_exp(A) ::= T_NOT(B) unary_exp(C). { A = wrap_op(B, C); } unary_exp(A) ::= postfix_exp(B). { A = B; } -postfix_exp(A) ::= unary_exp(B) T_INC(C). { A = wrap_op(C, B); ut_get_op(s, A)->is_postfix = 1; } -postfix_exp(A) ::= unary_exp(B) T_DEC(C). { A = wrap_op(C, B); ut_get_op(s, A)->is_postfix = 1; } +postfix_exp(A) ::= unary_exp(B) T_INC(C). { A = wrap_op(C, B); uc_get_op(s, A)->is_postfix = 1; } +postfix_exp(A) ::= unary_exp(B) T_DEC(C). { A = wrap_op(C, B); uc_get_op(s, A)->is_postfix = 1; } postfix_exp(A) ::= unary_exp(B) T_LPAREN(C) T_RPAREN. { A = wrap_op(C, B); } postfix_exp(A) ::= unary_exp(B) T_LPAREN(C) arg_exps(D) T_RPAREN. { A = wrap_op(C, B, D); } postfix_exp(A) ::= postfix_exp(B) T_DOT(C) T_LABEL(D). { A = wrap_op(C, B, D); } postfix_exp(A) ::= postfix_exp(B) T_LBRACK(C) exp(D) T_RBRACK. - { A = wrap_op(C, B, D); ut_get_op(s, A)->is_postfix = 1; } + { A = wrap_op(C, B, D); uc_get_op(s, A)->is_postfix = 1; } postfix_exp(A) ::= primary_exp(B). { A = B; } primary_exp(A) ::= T_BOOL(B). { A = B; } @@ -440,7 +440,7 @@ primary_exp(A) ::= T_NULL(B). { A = B; } primary_exp(A) ::= T_THIS(B). { A = B; } primary_exp(A) ::= array(B). { A = B; } primary_exp(A) ::= object(B). { A = B; } -primary_exp(A) ::= paren_exp(B). { A = ut_reject_local(s, B); } +primary_exp(A) ::= paren_exp(B). { A = uc_reject_local(s, B); } primary_exp(A) ::= T_FUNC(B) T_LPAREN T_RPAREN empty_object. { A = B; } primary_exp(A) ::= T_FUNC(B) T_LPAREN args(C) T_RPAREN empty_object. @@ -459,8 +459,8 @@ array(A) ::= T_LBRACK(B) items(C) T_RBRACK. { A = wrap_op(B, C); } items(A) ::= items(B) T_COMMA item(C). { A = append_op(B, C); } items(A) ::= item(B). { A = B; } -item(A) ::= T_ELLIP assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; ut_get_op(s, A)->is_ellip = 1; } -item(A) ::= assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; } +item(A) ::= T_ELLIP assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; uc_get_op(s, A)->is_ellip = 1; } +item(A) ::= assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; } object(A) ::= empty_object(B). { A = B; } object(A) ::= T_LBRACE(B) tuples(C) T_RBRACE. { A = wrap_op(B, C); } @@ -474,8 +474,8 @@ tuple(A) ::= T_LABEL(B) T_COLON exp(C). { A = wrap_op(B, C); } tuple(A) ::= T_STRING(B) T_COLON exp(C). { A = wrap_op(B, C); } tuple(A) ::= T_ELLIP(B) assign_exp(C). { A = wrap_op(B, C); } -arg_exps(A) ::= arg_exps(B) T_COMMA arg_exp(C). { A = append_op(B, C); ut_get_op(s, A)->is_list = 1; } -arg_exps(A) ::= arg_exp(B). { A = B; ut_get_op(s, A)->is_list = 1; } +arg_exps(A) ::= arg_exps(B) T_COMMA arg_exp(C). { A = append_op(B, C); uc_get_op(s, A)->is_list = 1; } +arg_exps(A) ::= arg_exp(B). { A = B; uc_get_op(s, A)->is_list = 1; } -arg_exp(A) ::= T_ELLIP assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; ut_get_op(s, A)->is_ellip = 1; } -arg_exp(A) ::= assign_exp(B). { A = ut_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; } +arg_exp(A) ::= T_ELLIP assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; uc_get_op(s, A)->is_ellip = 1; } +arg_exp(A) ::= assign_exp(B). { A = uc_get_op(s, B)->tree.next ? new_op(T_COMMA, NULL, B) : B; } |