]> ocean-lang.org Git - ocean/commitdiff
oceani: add more syntax error handling.
authorNeilBrown <neil@brown.name>
Sun, 9 Jun 2019 00:15:39 +0000 (10:15 +1000)
committerNeilBrown <neil@brown.name>
Sun, 9 Jun 2019 00:15:39 +0000 (10:15 +1000)
We catch some errors earlier so more errors can be
reported in a single run.
The indent structure make recovery easy!

As we might abort out of a var scope, we only insist the scope
is balanced in there are no parser errors.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index 40489bffd41dd17f74a6428ba9826614e4e7fb53..a10d0271fab3291f8251de230891ad1c3312b07e 100644 (file)
@@ -595,8 +595,7 @@ separate file first, then run from there.
                if then else while do
 
 ###### output: syn1
                if then else while do
 
 ###### output: syn1
-       .tmp.code:3:11: error: unhandled parse error: then
-       oceani: no program found.
+       .tmp.code:3:11: Syntax error in statement: then
 
 ###### test: tokerr
        program:
 
 ###### test: tokerr
        program:
@@ -795,8 +794,8 @@ various places that `type_err()` are called.
                print foo, bar
 
 ###### output: type_err_const1
                print foo, bar
 
 ###### output: type_err_const1
-       .tmp.code:3:12: error: unhandled parse error: :
-       oceani: no program found.
+       .tmp.code:3:12: Syntax error in constant: :
+       .tmp.code:4:8: Syntax error in constant: bar
 
 ## Test erroneous command line args
 
 
 ## Test erroneous command line args
 
index f36bbdb13593c6c306920bacd7d1d619513c2957..a8653cc669adbe9ee21d894ecb9744e99b46ce66 100644 (file)
@@ -2067,6 +2067,7 @@ function will be needed.
                        $0->f.type = $<3;
                        $0->f.init = val_init($3);
                }$
                        $0->f.type = $<3;
                        $0->f.init = val_init($3);
                }$
+               | ERROR ${ tok_err(c, "Syntax error in struct field", &$1); }$
 
 ###### forward decls
        static void structure_print_type(struct type *t, FILE *f);
 
 ###### forward decls
        static void structure_print_type(struct type *t, FILE *f);
@@ -3074,6 +3075,7 @@ is in-place.
                | SimpleStatements ; ${ $0 = $<1; }$
 
        SimpleStatement -> pass ${ $0 = NULL; }$
                | SimpleStatements ; ${ $0 = $<1; }$
 
        SimpleStatement -> pass ${ $0 = NULL; }$
+               | ERROR ${ tok_err(c, "Syntax error in statement", &$1); }$
                ## SimpleStatement Grammar
 
 ###### print binode cases
                ## SimpleStatement Grammar
 
 ###### print binode cases
@@ -3917,6 +3919,10 @@ various declarations in the parse context.
                | DeclareProgram
                | DeclareStruct
                | NEWLINE
                | DeclareProgram
                | DeclareStruct
                | NEWLINE
+               | ERROR NEWLINE ${
+                       tok_err(c,
+                               "error: unhandled parse error", &$1);
+               }$
 
        ## top level grammar
 
 
        ## top level grammar
 
@@ -3990,6 +3996,7 @@ searching through for the Nth constant for decreasing N.
                        v->val = interp_exec($5);
                }
        } }$
                        v->val = interp_exec($5);
                }
        } }$
+       | ERROR NEWLINE ${ tok_err(c, "Syntax error in constant", &$1); }$
 
 ###### print const decls
        {
 
 ###### print const decls
        {
@@ -4058,7 +4065,7 @@ analysis is a bit more interesting at this level.
                $0->left = reorder_bilist($<3);
                $0->right = $<4;
                var_block_close(c, CloseSequential);
                $0->left = reorder_bilist($<3);
                $0->right = $<4;
                var_block_close(c, CloseSequential);
-               if (c->scope_stack) abort();
+               if (c->scope_stack && !c->parse_error) abort();
                }$
                | ERROR ${
                        tok_err(c,
                }$
                | ERROR ${
                        tok_err(c,