From ff0048963fcbcddc9de14a3e1c370fcc81d12af7 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 1 Feb 2017 12:30:32 +0100 Subject: [PATCH] get rid of weird lemon symbols --- Makefile.frag | 1 - src/parser.re | 18 +++++++++--------- src/parser_def.h | 1 - src/parser_proc.inc | 25 +++++++++++++++++++++++++ src/parser_proc.y | 26 +++++++++++++++++++++++++- 5 files changed, 59 insertions(+), 12 deletions(-) diff --git a/Makefile.frag b/Makefile.frag index d192749..ff6460b 100644 --- a/Makefile.frag +++ b/Makefile.frag @@ -19,7 +19,6 @@ psi-build-headers: $(PHP_PSI_HEADERS) .PHONY: psi-clean-headers psi-clean-headers: -rm -f $(PHP_PSI_HEADERS) - -rmdir $(PHP_PSI_BUILDDIR)/types .PHONY: psi-clean-sources psi-clean-sources: diff --git a/src/parser.re b/src/parser.re index 7ed6628..b56385d 100644 --- a/src/parser.re +++ b/src/parser.re @@ -4,10 +4,10 @@ #include "parser.h" -void *psi_parser_proc_Alloc(void*(unsigned long)); -void psi_parser_proc_Free(void*, void(*)(void*)); -void psi_parser_proc_(void *, token_t, struct psi_token *, struct psi_parser *); -void psi_parser_proc_Trace(FILE *, const char*); +void *psi_parser_proc_init(void); +void psi_parser_proc_free(void **parser_proc); +void psi_parser_proc_parse(void *parser_proc, token_t r, struct psi_token *token, struct psi_parser *parser); +void psi_parser_proc_trace(FILE *out, char *prefix); struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, unsigned flags) { @@ -20,10 +20,10 @@ struct psi_parser *psi_parser_init(struct psi_parser *P, psi_error_cb error, uns P->col = 1; P->line = 1; - P->proc = psi_parser_proc_Alloc(malloc); + P->proc = psi_parser_proc_init(); if (flags & PSI_DEBUG) { - psi_parser_proc_Trace(stderr, "PSI> "); + psi_parser_proc_trace(stderr, "PSI> "); } return P; @@ -152,15 +152,15 @@ static ssize_t psi_parser_fill(struct psi_parser *P, size_t n) void psi_parser_parse(struct psi_parser *P, struct psi_token *T) { if (T) { - psi_parser_proc_(P->proc, T->type, T, P); + psi_parser_proc_parse(P->proc, T->type, T, P); } else { - psi_parser_proc_(P->proc, 0, NULL, P); + psi_parser_proc_parse(P->proc, 0, NULL, P); } } void psi_parser_dtor(struct psi_parser *P) { - psi_parser_proc_Free(P->proc, free); + psi_parser_proc_free(&P->proc); switch (P->input.type) { case PSI_PARSE_FILE: diff --git a/src/parser_def.h b/src/parser_def.h index 05489e7..5d6a84a 100644 --- a/src/parser_def.h +++ b/src/parser_def.h @@ -62,7 +62,6 @@ # define TOKEN_DTOR(token, dtor) #endif -DEF(%name, psi_parser_proc_) DEF(%token_prefix, PSI_T_) DEF(%token_type, {struct psi_token *}) DEF(%token_destructor, {free($$);}) diff --git a/src/parser_proc.inc b/src/parser_proc.inc index 9bd05e5..5e2128c 100644 --- a/src/parser_proc.inc +++ b/src/parser_proc.inc @@ -6,4 +6,29 @@ #include "plist.h" #include "parser.h" + +/* rename lemon symbols, works better than DEF(%name) */ +#define ParseAlloc psi_parser_proc_init_ex +#define Parse psi_parser_proc_parse +#define ParseTrace psi_parser_proc_trace +#define ParseFree psi_parser_proc_free_ex + +/* fwd decls */ +void *ParseAlloc(void *(*mallocProc)(size_t)); +void ParseFree(void *p, void (*freeProc)(void*)); + +/* wrappers */ +void *psi_parser_proc_init(void) +{ + return ParseAlloc(malloc); +} + +void psi_parser_proc_free(void **parser_proc) +{ + if (*parser_proc) { + ParseFree(*parser_proc, free); + *parser_proc = NULL; + } +} + } diff --git a/src/parser_proc.y b/src/parser_proc.y index 66d8844..15407e0 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -6,8 +6,32 @@ #include "plist.h" #include "parser.h" + +/* rename lemon symbols, works better than DEF(%name) */ +#define ParseAlloc psi_parser_proc_init_ex +#define Parse psi_parser_proc_parse +#define ParseTrace psi_parser_proc_trace +#define ParseFree psi_parser_proc_free_ex + +/* fwd decls */ +void *ParseAlloc(void *(*mallocProc)(size_t)); +void ParseFree(void *p, void (*freeProc)(void*)); + +/* wrappers */ +void *psi_parser_proc_init(void) +{ + return ParseAlloc(malloc); +} + +void psi_parser_proc_free(void **parser_proc) +{ + if (*parser_proc) { + ParseFree(*parser_proc, free); + *parser_proc = NULL; + } +} + } -%name psi_parser_proc_ %token_prefix PSI_T_ %token_type {struct psi_token *} %token_destructor {free($$);} -- 2.30.2