]> ocean-lang.org Git - ocean/commitdiff
parsergen: record line number of reduce fragments.
authorNeilBrown <neil@brown.name>
Tue, 6 Feb 2018 05:42:01 +0000 (16:42 +1100)
committerNeilBrown <neil@brown.name>
Tue, 13 Feb 2018 01:56:57 +0000 (12:56 +1100)
If there is an error in a code fragment used to handle
a 'reduce' action, we need the compiler to report the
correct line from the grammar file.
This information is easily available from the scanner,
we just need to pass it along.

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

index 7499e07c9e5996688cf0642ab1cea7c441cf0a30..97bba421519d13d35c9230ace1722c99e9536c2b 100644 (file)
@@ -452,6 +452,7 @@ Now we have all the bits we need to parse a full production.
        struct symbol **body;
        int             body_size;
        struct text     code;
+       int             code_line;
 
 ###### symbol fields
        int first_production;
@@ -501,6 +502,7 @@ Now we have all the bits we need to parse a full production.
                        tk = token_next(state);
                }
                if (tk.num == TK_open) {
+                       p.code_line = tk.line;
                        p.code = collect_code(state, tk);
                        if (p.code.txt == NULL) {
                                err = "code fragment not closed properly";
@@ -2084,8 +2086,10 @@ automatically freed.  This is equivalent to assigning `NULL` to the pointer.
                        struct production *p = g->productions[i];
                        fprintf(f, "\tcase %d:\n", i);
 
-                       if (p->code.txt)
+                       if (p->code.txt) {
+                               fprintf(f, "#line %d \"%s\"\n", p->code_line, file);
                                gen_code(p, f, g);
+                       }
 
                        if (p->head->struct_name.txt)
                                fprintf(f, "\t\tret_size = sizeof(struct %.*s%s);\n",