]> ocean-lang.org Git - ocean/commitdiff
oceani: detect and report tails on numbers and strings. StoneyCreek StoneyCreek-2
authorNeilBrown <neil@brown.name>
Mon, 19 Feb 2018 06:48:44 +0000 (17:48 +1100)
committerNeilBrown <neil@brown.name>
Mon, 19 Feb 2018 06:48:44 +0000 (17:48 +1100)
Currently illegal, so we should say so.

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

index 10ac4ff543780f6df721ca0ffa2b954750fc5a09..ebb69ade3d2a32f40e0e3666ed6416cf8d2cc4e9 100644 (file)
@@ -375,6 +375,12 @@ stored.
                c->parse_error = 1;
        }
 
+       static void tok_err(struct parse_context *c, char *fmt, struct token *t)
+       {
+               fprintf(stderr, "%s:%d:%d: %s\n", c->file_name, t->line, t->col, fmt);
+               c->parse_error = 1;
+       }
+
 ## Data Structures
 
 One last introductory step before detailing the language elements and
@@ -1281,16 +1287,25 @@ an executable.
                        $0->val.vtype = Vnum;
                        if (number_parse($0->val.num, $0->val.tail, $1.txt) == 0)
                                mpq_init($0->val.num);
+                               if ($0->val.tail[0])
+                                       tok_err(config2context(config), "error: unsupported number suffix.",
+                                               &$1);
                        }$
                | STRING ${
                        $0 = new_pos(val, $1);
                        $0->val.vtype = Vstr;
                        string_parse(&$1, '\\', &$0->val.str, $0->val.tail);
+                       if ($0->val.tail[0])
+                               tok_err(config2context(config), "error: unsupported string suffix.",
+                                       &$1);
                        }$
                | MULTI_STRING ${
                        $0 = new_pos(val, $1);
                        $0->val.vtype = Vstr;
                        string_parse(&$1, '\\', &$0->val.str, $0->val.tail);
+                       if ($0->val.tail[0])
+                               tok_err(config2context(config), "error: unsupported string suffix.",
+                                       &$1);
                        }$
 
 ###### print exec cases
@@ -2782,9 +2797,8 @@ analysis is a bit more interesting at this level.
                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;
+                       tok_err(config2context(config),
+                               "error: unhandled parse error.", &$1);
                }$
 
        Varlist -> Varlist ArgDecl ${