]> ocean-lang.org Git - ocean/commitdiff
oceani: remove the need for 'then' in function declarations.
authorNeilBrown <neil@brown.name>
Wed, 10 Nov 2021 10:27:50 +0000 (21:27 +1100)
committerNeilBrown <neil@brown.name>
Sat, 13 Nov 2021 22:50:56 +0000 (09:50 +1100)
Previously an IN had to follow a terminal because it would never for a
reduce.
This made is a problem for
    func FuncName
          arguments
    do
          code

as the IN follows FuncName - a non-terminal.

Fix this by allowing an IN to force a reduce if nothing at all can be
shifted.
After "func IDENTIFIER", nothing can be shifted.  The IDENTIFIER must be
reduced to FuncName.  At that point, the IN is expected, so it won't be
ignored.

This allows the 'then' to be dropped.

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

index d9be788450c88baf56d37a6e613b18fb31e88dff..2314ce3ea4d9ec070c7cf23867f04f3072fd71b3 100644 (file)
@@ -620,7 +620,7 @@ Test functions.  They don't return anything, so we need to get them to print
 
 ###### test: functions
 
-       func test1 then
+       func test1
                t: Boolean
        do
                if t:
@@ -971,7 +971,7 @@ Test for type errors with functions
        do
                pass
 
-       func test1 then
+       func test1
                b:Boolean
        do
                pass
index f257736edc328baf8ba313d28f3bd7826e4e5004..590add27c0782c52388c1752651b145fc0a5cfda 100644 (file)
@@ -4718,8 +4718,7 @@ analysis is a bit more interesting at this level.
                        } else
                                var_block_close(c, CloseSequential, NULL);
                } }$
-               | func FuncName then IN OpenScope OptNL Args OUT OptNL do Block Newlines ${ {
-                       // FIXME that 'then' should not be there.
+               | func FuncName IN OpenScope OptNL Args OUT OptNL do Block Newlines ${ {
                        struct text funcname = { " func", 5};
                        $0 = $<FN;
                        if ($0) {
index 80027aa74e49989428ea370172c3a783c8ebfd40..6cb5a7371aa3935663d05df35a186ef8d2a6da32 100644 (file)
@@ -2785,11 +2785,12 @@ might also be ignored.  Ignoring tokens is combined with shifting.
        }
 
 Indents are ignored unless they can be shifted onto the stack
-immediately.  The end of an indented section - the OUT token - is
-ignored precisely when the indent was ignored.  To keep track of this we
-need a small stack of flags, which is easily stored as bits in an
-`unsigned long`.  This will never overflow and the scanner only allows
-20 levels of indentation.
+immediately or nothing can be shifted (in which case we reduce, and try
+again).  The end of an indented section - the OUT token - is ignored
+precisely when the indent was ignored.  To keep track of this we need a
+small stack of flags, which is easily stored as bits in an `unsigned
+long`.  This will never overflow and the scanner only allows 20 levels
+of indentation.
 
 ###### parser state
        unsigned long ignored_indents;
@@ -2829,8 +2830,8 @@ we try to reduce a production.
                continue;
        }
 
-       if (tk->num == TK_in) {
-               /* No indent expected here, so ignore IN */
+       if (tk->num == TK_in && states[p.stack[p.tos-1].state].go_to_cnt > 0) {
+               /* No indent expected here and reduce is not mandatory, so ignore IN */
                free(tk);
                tk = NULL;
                p.ignored_indents <<= 1;