From 69756809ef2d0324ec94b277f9750f92db4ae416 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 10 Nov 2021 21:27:50 +1100 Subject: [PATCH] oceani: remove the need for 'then' in function declarations. 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 --- csrc/oceani-tests.mdc | 4 ++-- csrc/oceani.mdc | 3 +-- csrc/parsergen.mdc | 15 ++++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/csrc/oceani-tests.mdc b/csrc/oceani-tests.mdc index d9be788..2314ce3 100644 --- a/csrc/oceani-tests.mdc +++ b/csrc/oceani-tests.mdc @@ -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 diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index f257736..590add2 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -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 = $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; -- 2.43.0