From: NeilBrown Date: Mon, 19 Feb 2018 05:58:40 +0000 (+1100) Subject: oceani: minimal error tracking. X-Git-Tag: StoneyCreek~3 X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=db13a7edae07b9905343b68f568a7d335d176951 oceani: minimal error tracking. 1/ If the parser hits an error, catch it at eof by having Program -> ERROR 2/ Allow the presence of and error to be recorded in the context. 3/ If an error occured, don't try to run, and do exit with an error status. Now, at last, we get told where the error was. Signed-off-by: NeilBrown --- diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index 8e1cb41..4689a52 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -110,6 +110,7 @@ option. struct parse_context { struct token_config config; char *file_name; + int parse_error; ## parse context }; @@ -226,9 +227,13 @@ option. } else prog = parse_oceani(s->code, &context.config, dotrace ? stderr : NULL); + if (!prog) { + fprintf(stderr, "oceani: fatal parser error.\n"); + context.parse_error = 1; + } if (prog && doprint) print_exec(*prog, 0, brackets); - if (prog && doexec) { + if (prog && doexec && !context.parse_error) { if (!analyse_prog(*prog, &context)) { fprintf(stderr, "oceani: type error in program - not running.\n"); exit(1); @@ -246,7 +251,7 @@ option. s = t; } ## free context - exit(0); + exit(context.parse_error ? 1 : 0); } ### Analysis @@ -367,6 +372,7 @@ stored. } } fputs("\n", stderr); + c->parse_error = 1; } ## Data Structures @@ -2753,7 +2759,12 @@ analysis is a bit more interesting at this level. $0->right = $<4; var_block_close(config2context(config), CloseSequential); if (config2context(config)->scope_stack) abort(); - }$ + }$ + | ERROR ${ + fprintf(stderr, "%s:%d:%d: error: unhandled parse error.\n", + config2context(config)->file_name, $1.line, $1.col); + config2context(config)->parse_error = 1; + }$ Varlist -> Varlist ArgDecl ${ $0 = new(binode);