X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser_proc.y;h=5813b42912815c963d9c1496b553952f7b17a3a7;hp=409987729a8a1dca3f20f46a8ce3df03aebe14d6;hb=3fa287dfd76814b2ec54991c0208a019845a3dc0;hpb=04a60b34fc18ea3a2638893eaf24514177692eeb diff --git a/src/parser_proc.y b/src/parser_proc.y index 4099877..5813b42 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -1,4 +1,10 @@ %include { +#ifdef HAVE_CONFIG_H +# include "config.h" +#else +# include "php_config.h" +#endif + #include #include #include @@ -7,14 +13,13 @@ #include "parser.h" } -%include { void psi_error(int, const char *, int, const char *, ...); } -%name PSI_ParserProc +%name psi_parser_proc_ %token_prefix PSI_T_ -%token_type {PSI_Token *} +%token_type {struct psi_token *} %token_destructor {free($$);} %default_destructor {(void)P;} -%extra_argument {PSI_Parser *P} -%syntax_error { ++P->errors; if (TOKEN && TOKEN->type != PSI_T_EOF) { psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s'", TOKEN->text); } else { psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input"); } } +%extra_argument {struct psi_parser *P} +%syntax_error { ++P->errors; if (TOKEN && TOKEN->type != PSI_T_EOF) { psi_error(PSI_WARNING, TOKEN->file, TOKEN->line, "PSI syntax error: Unexpected token '%s' at pos %u", TOKEN->text, TOKEN->col); } else { psi_error(PSI_WARNING, P->psi.file.fn, P->line, "PSI syntax error: Unexpected end of input"); } } %nonassoc NAME. %left PLUS MINUS. %left SLASH ASTERISK. @@ -112,6 +117,8 @@ %destructor callback_args {free_set_values($$);} %type let_val {let_val*} %destructor let_val {free_let_val($$);} +%type let_vals {let_vals*} +%destructor let_vals {free_let_vals($$);} %type set_stmt {set_stmt*} %destructor set_stmt {free_set_stmt($$);} %type set_value {set_value*} @@ -197,8 +204,8 @@ enum_name(n) ::= ENUM(E) optional_name(N). { free(E); } else { char digest[17]; - PSI_TokenHash(E, digest); - n = PSI_TokenTranslit(PSI_TokenAppend(E, 1, digest), " ", "@"); + psi_token_hash(E, digest); + n = psi_token_translit(psi_token_append(E, 1, digest), " ", "@"); } } decl_enum(e) ::= enum_name(N) LBRACE decl_enum_items(list) RBRACE. { @@ -225,8 +232,8 @@ union_name(n) ::= UNION(U) optional_name(N). { free(U); } else { char digest[17]; - PSI_TokenHash(U, digest); - n = PSI_TokenTranslit(PSI_TokenAppend(U, 1, digest), " ", "@"); + psi_token_hash(U, digest); + n = psi_token_translit(psi_token_append(U, 1, digest), " ", "@"); } } struct_name(n) ::= STRUCT(S) optional_name(N). { @@ -235,8 +242,8 @@ struct_name(n) ::= STRUCT(S) optional_name(N). { free(S); } else { char digest[17]; - PSI_TokenHash(S, digest); - n = PSI_TokenTranslit(PSI_TokenAppend(S, 1, digest), " ", "@"); + psi_token_hash(S, digest); + n = psi_token_translit(psi_token_append(S, 1, digest), " ", "@"); } } decl_struct_args_block(args_) ::= LBRACE struct_args(args) RBRACE. { @@ -284,7 +291,7 @@ decl_typedef(def) ::= TYPEDEF(T) decl_typedef_body(def_) EOS. { } decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). { def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var); - def->type->token = PSI_TokenCopy(N); + def->type->token = psi_token_copy(N); def->type->real.strct = init_decl_struct(N->text, args); def->type->real.strct->token = N; def->type->real.strct->align = as.pos; @@ -292,7 +299,7 @@ decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args } decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). { def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var); - def->type->token = PSI_TokenCopy(N); + def->type->token = psi_token_copy(N); def->type->real.unn = init_decl_union(N->text, args); def->type->real.unn->token = N; def->type->real.unn->align = as.pos; @@ -301,7 +308,7 @@ decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_ decl_typedef_body_ex(def) ::= decl_enum(e) NAME(ALIAS). { def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0)); def->var->token = ALIAS; - def->type->token = PSI_TokenCopy(e->token); + def->type->token = psi_token_copy(e->token); def->type->real.enm = e; } decl_typedef_body(def) ::= decl_typedef_body_ex(def_). { @@ -312,7 +319,7 @@ decl_typedef_body_fn_args(args) ::= LPAREN decl_args(args_) RPAREN. { } decl_typedef_body(def) ::= decl_func(func_) decl_typedef_body_fn_args(args). { def = init_decl_arg(init_decl_type(PSI_T_FUNCTION, func_->var->name), copy_decl_var(func_->var)); - def->type->token = PSI_TokenCopy(func_->token); + def->type->token = psi_token_copy(func_->token); def->type->real.func = init_decl(init_decl_abi("default"), func_, args); } decl_typedef_body(def) ::= decl_arg(arg). { @@ -346,7 +353,7 @@ decl_typedef_body(def) ::= VOID(T) indirection(decl_i) LPAREN indirection(type_i copy_decl_var(func_->var) ); def->var->pointer_level = type_i; - def->type->token = PSI_TokenCopy(func_->token); + def->type->token = psi_token_copy(func_->token); def->type->real.func = init_decl(init_decl_abi("default"), func_, args); } decl_typedef_body(def) ::= CONST VOID(T) pointers(decl_i) LPAREN indirection(type_i) NAME(N) RPAREN decl_typedef_body_fn_args(args). { @@ -362,7 +369,7 @@ decl_typedef_body(def) ::= CONST VOID(T) pointers(decl_i) LPAREN indirection(typ copy_decl_var(func_->var) ); def->var->pointer_level = type_i; - def->type->token = PSI_TokenCopy(func_->token); + def->type->token = psi_token_copy(func_->token); def->type->real.func = init_decl(init_decl_abi("default"), func_, args); } decl_abi(abi) ::= NAME(T). { @@ -399,7 +406,7 @@ decl_typedef_body(def) ::= const_decl_type(type_) indirection(decl_i) LPAREN ind copy_decl_var(func_->var) ); def->var->pointer_level = type_i; - def->type->token = PSI_TokenCopy(func_->token); + def->type->token = psi_token_copy(func_->token); def->type->real.func = init_decl(init_decl_abi("default"), func_, args); } decl_arg(arg_) ::= VOID(T) pointers(p) NAME(N). { @@ -475,7 +482,7 @@ decl_scalar_type(type_) ::= CHAR(C). { } decl_scalar_type(type_) ::= SHORT(S) decl_scalar_type_short(s). { if (s) { - type_ = PSI_TokenCat(2, S, s); + type_ = psi_token_cat(2, S, s); free(S); free(s); } else { @@ -493,7 +500,7 @@ decl_scalar_type(type_) ::= INT(I). { } decl_scalar_type(type_) ::= LONG(L) decl_scalar_type_long(l). { if (l) { - type_ = PSI_TokenCat(2, L, l); + type_ = psi_token_cat(2, L, l); free(L); free(l); } else { @@ -508,7 +515,7 @@ decl_scalar_type_long(l) ::= DOUBLE(D). { } decl_scalar_type_long(l) ::= LONG(L) decl_scalar_type_long_long(ll). { if (ll) { - l = PSI_TokenCat(2, L, ll); + l = psi_token_cat(2, L, ll); free(L); free(ll); } else { @@ -522,14 +529,14 @@ decl_scalar_type_long_long(ll) ::= INT(I). { ll = I; } decl_type(type_) ::= UNSIGNED(U) decl_scalar_type(N). { - PSI_Token *T = PSI_TokenCat(2, U, N); + struct psi_token *T = psi_token_cat(2, U, N); type_ = init_decl_type(T->type, T->text); type_->token = T; free(U); free(N); } decl_type(type_) ::= SIGNED(S) decl_scalar_type(N). { - PSI_Token *T = PSI_TokenCat(2, S, N); + struct psi_token *T = psi_token_cat(2, S, N); type_ = init_decl_type(T->type, T->text); type_->token = T; free(S); @@ -637,7 +644,7 @@ num_exp(exp) ::= num_exp_token(tok). { } num_exp(exp) ::= decl_var(var). { exp = init_num_exp(PSI_T_NAME, var); - exp->token = PSI_TokenCopy(var->token); + exp->token = psi_token_copy(var->token); } num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). { exp_->operator = operator_->type; @@ -662,6 +669,17 @@ let_func(func) ::= let_func_token(T) LPAREN impl_var(var) RPAREN. { func = init_let_func(T->type, T->text, var); free(T); } +let_vals(vals) ::= let_val(val). { + vals = init_let_vals(val); +} +let_vals(vals) ::= let_vals(vals_) COMMA let_val(val). { + vals = add_let_val(vals_, val); +} +let_func(func) ::= let_func_token(T) LPAREN impl_var(var) COMMA let_vals(vals) RPAREN. { + func = init_let_func(T->type, T->text, var); + func->inner = vals; + free(T); +} callback_arg_list ::= . callback_arg_list(args) ::= callback_args(args_). { args = args_; @@ -672,6 +690,12 @@ callback_args(args) ::= set_value(val). { callback_args(args) ::= callback_args(args_) COMMA set_value(val). { args = add_set_value(args_, val); } +callback_rval(rval) ::= let_func_token(F). { + rval = F; +} +callback_rval(rval) ::= VOID(V). { + rval = V; +} let_val(val) ::= NULL. { val = init_let_val(PSI_LET_NULL, NULL); } @@ -681,10 +705,10 @@ let_val(val) ::= num_exp(exp). { let_val(val) ::= CALLOC LPAREN let_calloc(alloc) RPAREN. { val = init_let_val(PSI_LET_CALLOC, alloc); } -let_val(val) ::= let_func(func). { - val = init_let_val(PSI_LET_FUNC, func); +let_val(val) ::= let_func(func_). { + val = init_let_val(PSI_LET_FUNC, func_); } -let_val(val) ::= CALLBACK let_func_token(F) LPAREN impl_var(var) LPAREN callback_arg_list(args_) RPAREN RPAREN. { +let_val(val) ::= CALLBACK callback_rval(F) LPAREN impl_var(var) LPAREN callback_arg_list(args_) RPAREN RPAREN. { val = init_let_val(PSI_LET_CALLBACK, init_let_callback( init_let_func(F->type, F->text, var), args_)); free(F);