From: Wolfgang (Blub) Bumiller Date: Sun, 11 Nov 2012 09:32:43 +0000 (+0100) Subject: parser_compile_file vs parser_compile_string X-Git-Tag: 0.1~32 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cf1ea01de310ebfd9338d86d6cf649c81ce17a01;p=xonotic%2Fgmqcc.git parser_compile_file vs parser_compile_string --- diff --git a/gmqcc.h b/gmqcc.h index bf3c7c6..7b10013 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -939,10 +939,11 @@ void cprintmsg (lex_ctx ctx, int lvl, const char *msgtype, const char *msg, ...) /*===================== parser.c commandline ========================*/ /*===================================================================*/ -bool parser_init (); -bool parser_compile(const char *filename); -bool parser_finish (const char *output); -void parser_cleanup(); +bool parser_init (); +bool parser_compile_file (const char *filename); +bool parser_compile_string(const char *name, const char *str); +bool parser_finish (const char *output); +void parser_cleanup (); /*===================================================================*/ /*======================= main.c commandline ========================*/ diff --git a/main.c b/main.c index a65a735..dddc9eb 100644 --- a/main.c +++ b/main.c @@ -460,7 +460,7 @@ int main(int argc, char **argv) { (items_data[itr].type == TYPE_SRC ? "progs.src" : ("unknown")))))); - if (!parser_compile(items_data[itr].filename)) { + if (!parser_compile_file(items_data[itr].filename)) { retval = 1; goto cleanup; } @@ -500,7 +500,7 @@ int main(int argc, char **argv) { if (!line[0] || (line[0] == '/' && line[1] == '/')) continue; printf(" src: %s\n", line); - if (!parser_compile(line)) { + if (!parser_compile_file(line)) { retval = 1; goto srcdone; } diff --git a/parser.c b/parser.c index 72fa486..f548e22 100644 --- a/parser.c +++ b/parser.c @@ -2840,14 +2840,8 @@ bool parser_init() return true; } -bool parser_compile(const char *filename) +bool parser_compile() { - parser->lex = lex_open(filename); - if (!parser->lex) { - printf("failed to open file \"%s\"\n", filename); - return false; - } - /* initial lexer/parser state */ parser->lex->flags.noops = true; @@ -2878,6 +2872,26 @@ bool parser_compile(const char *filename) return !parser->errors; } +bool parser_compile_file(const char *filename) +{ + parser->lex = lex_open(filename); + if (!parser->lex) { + printf("failed to open file \"%s\"\n", filename); + return false; + } + return parser_compile(); +} + +bool parser_compile_string(const char *name, const char *str) +{ + parser->lex = lex_open_string(str, strlen(str), name); + if (!parser->lex) { + printf("failed to create lexer for string \"%s\"\n", name); + return false; + } + return parser_compile(); +} + void parser_cleanup() { size_t i;