X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=src%2Fparser_proc_grammar.y;h=f9925cbdd254c5192ab0ad96a5b1e7fe23488432;hp=fc0b75210aad1c9bee15ec96aa19f11745804624;hb=93d6b7f962a82b725d1918684297d68221b0b733;hpb=d2e0af1718294569a84c3c15616c74e4d55ea579 diff --git a/src/parser_proc_grammar.y b/src/parser_proc_grammar.y index fc0b752..f9925cb 100644 --- a/src/parser_proc_grammar.y +++ b/src/parser_proc_grammar.y @@ -1,4 +1,9 @@ %code top { +#ifdef HAVE_CONFIG_H +# include "config.h" +#else +# include "php_config.h" +#endif } %code { @@ -82,6 +87,10 @@ static inline void psi_parser_proc_add_impl(struct psi_parser *P, struct psi_imp } P->impls = psi_plist_add(P->impls, &impl); } +static inline void psi_parser_proc_add_lib(struct psi_parser *P, zend_string *lib) { + char *libname = strdup(lib->val); + P->file.libnames = psi_plist_add(P->file.libnames, &libname); +} /* end code */ } @@ -385,7 +394,7 @@ struct psi_parser; %type impl_stmt %destructor {psi_impl_stmt_free(&$$);} impl_stmt %type impl_type_token impl_type_restricted_token impl_type_extended_token callback_rval let_func_token set_func_token assert_stmt_token -%destructor {psi_token_free(&$$);} impl_type_token impl_type_restricted_token impl_type_extended_token callback_rval let_func_token set_func_token assert_stmt_token +%destructor {} impl_type_token impl_type_restricted_token impl_type_extended_token callback_rval let_func_token set_func_token assert_stmt_token %type impl_args impl_stmts let_exps let_func_exps callback_arg_list callback_args set_exps set_func_exps free_exps %destructor {psi_plist_free($$);} impl_args impl_stmts let_exps let_func_exps callback_arg_list callback_args set_exps set_func_exps free_exps @@ -430,8 +439,7 @@ block: } } | lib { - char *libname = strdup($lib->text->val); - P->file.libnames = psi_plist_add(P->file.libnames, &libname); + psi_parser_proc_add_lib(P, $lib->text); } | constant { psi_parser_proc_add_const(P, $constant); @@ -469,6 +477,9 @@ lib: LIB QUOTED_STRING EOS { $lib = $QUOTED_STRING; } +| HASH PRAGMA LIB QUOTED_STRING EOS { + $lib = $QUOTED_STRING; +} ; cpp: @@ -2291,7 +2302,7 @@ static int psi_parser_proc_lex(YYSTYPE *lvalp, struct psi_parser *P, struct psi_ #if PSI_DEBUG_LEX PSI_DEBUG_PRINT(P, "PSI: LEX index %4zu ", *index); #endif - if (psi_plist_get(tokens, (*index)++, &token)) { + if (psi_plist_get(tokens, (*index)++, &token) && token) { #if PSI_DEBUG_LEX PSI_DEBUG_DUMP(P, psi_token_dump, token); #endif @@ -2324,11 +2335,22 @@ static void psi_parser_proc_error(struct psi_parser *P, struct psi_plist *tokens P->error(PSI_DATA(P), T, PSI_WARNING, "PSI %s at col %u", msg, T->col); while (i <= last || T->type != PSI_T_EOS) { + const char *pos; + if (!psi_plist_get(tokens, i++, &T)) { break; } + + if (i < last + 1) { + pos = "preceding"; + } else if (i > last + 1) { + pos = "following"; + } else { + pos = "offending"; + } + P->error(PSI_DATA(P), T, PSI_WARNING, "PSI %s token '%s' at col %u", - ilast+1?"following":"offending", T->text->val, T->col); + pos, T ? T->text->val : "", T ? T->col : 0); } } else { P->error(PSI_DATA(P), NULL, PSI_WARNING, "PSI %s", msg);