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 <neil@brown.name>
struct parse_context {
struct token_config config;
char *file_name;
struct parse_context {
struct token_config config;
char *file_name;
} else
prog = parse_oceani(s->code, &context.config,
dotrace ? stderr : NULL);
} 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 && doprint)
print_exec(*prog, 0, brackets);
+ if (prog && doexec && !context.parse_error) {
if (!analyse_prog(*prog, &context)) {
fprintf(stderr, "oceani: type error in program - not running.\n");
exit(1);
if (!analyse_prog(*prog, &context)) {
fprintf(stderr, "oceani: type error in program - not running.\n");
exit(1);
+ exit(context.parse_error ? 1 : 0);
$0->right = $<4;
var_block_close(config2context(config), CloseSequential);
if (config2context(config)->scope_stack) abort();
$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);
Varlist -> Varlist ArgDecl ${
$0 = new(binode);