From ed09d372138ebf29be56013a4a9160e7c927d99a Mon Sep 17 00:00:00 2001 From: "Johan B.W. de Vries" Date: Sun, 9 Feb 2025 15:03:47 +0100 Subject: [PATCH] Fix: predeclared functions would sometimes fail --- 1-lang0py/lang0py.lang0 | 11 ++--------- tests/parsingpredeclaredfunction.lang0 | 11 ----------- tests/parsingpredeclaredfunction0.lang0 | 10 ++++++++++ tests/parsingpredeclaredfunction1.lang0 | 10 ++++++++++ 4 files changed, 22 insertions(+), 20 deletions(-) delete mode 100644 tests/parsingpredeclaredfunction.lang0 create mode 100644 tests/parsingpredeclaredfunction0.lang0 create mode 100644 tests/parsingpredeclaredfunction1.lang0 diff --git a/1-lang0py/lang0py.lang0 b/1-lang0py/lang0py.lang0 index cbdd484..aa9a897 100644 --- a/1-lang0py/lang0py.lang0 +++ b/1-lang0py/lang0py.lang0 @@ -369,16 +369,11 @@ parseblock indent: parsefunc: calc funcname lexident - calc char peek - calc iseoblock eq char "/" - if iseoblock - return - / trace funcname emit "def " emit funcname emit "(" - set first "1" + set isnotfirst "" forever calc char peek calc isspace eq char " " @@ -388,13 +383,11 @@ parsefunc: / skip calc var lexident - calc isfirst eq first "1" - calc isnotfirst not isfirst if isnotfirst emit ", " / emit var - set first "0" + set isnotfirst "1" / calc char peek calc iseoblock eq char "/" diff --git a/tests/parsingpredeclaredfunction.lang0 b/tests/parsingpredeclaredfunction.lang0 deleted file mode 100644 index a794b15..0000000 --- a/tests/parsingpredeclaredfunction.lang0 +++ /dev/null @@ -1,11 +0,0 @@ -func result/ - -main: - declare result - calc result func "Success" - emit result -/ - -func result: - return result -/ diff --git a/tests/parsingpredeclaredfunction0.lang0 b/tests/parsingpredeclaredfunction0.lang0 new file mode 100644 index 0000000..bb15859 --- /dev/null +++ b/tests/parsingpredeclaredfunction0.lang0 @@ -0,0 +1,10 @@ +func/ + +main: + check func : "The function should return 1, even though it is not defined yet" + emit "Success" +/ + +func: + return "1" +/ diff --git a/tests/parsingpredeclaredfunction1.lang0 b/tests/parsingpredeclaredfunction1.lang0 new file mode 100644 index 0000000..743a6f6 --- /dev/null +++ b/tests/parsingpredeclaredfunction1.lang0 @@ -0,0 +1,10 @@ +func arg/ + +main: + check func "1" : "The function should return 1, even though it is not defined yet" + emit "Success" +/ + +func arg: + return arg +/