parser_compile_file vs parser_compile_string

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-11 10:32:43 +01:00
parent a84f9483e6
commit cf1ea01de3
3 changed files with 28 additions and 13 deletions

View file

@ -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 ========================*/

4
main.c
View file

@ -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;
}

View file

@ -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;