]> ocean-lang.org Git - ocean/blobdiff - csrc/oceani.mdc
oceani: minimal error tracking.
[ocean] / csrc / oceani.mdc
index 8e1cb41410623cc4d5fe660528af6a029d7c983e..4689a525233f020dd92362fddbb8712b200ff5d3 100644 (file)
@@ -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);