From c207c0668d973ccc6be7de055d87a0867ffa9ba8 Mon Sep 17 00:00:00 2001 From: William Bell Date: Tue, 14 Nov 2023 21:48:04 +0000 Subject: [PATCH] Fix indentation and translation errors in doWrap, forLoop, ifStatement, and whileLoop functions. Also fix syntax error in broken_funcCall test file. --- src/dowraps.go | 6 +++--- src/forloop.go | 2 +- src/ifstatement.go | 4 ++-- src/whileloop.go | 5 +++-- tests/broken_funcCall.ar | 5 ++++- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/dowraps.go b/src/dowraps.go index 633d49f..644cf2c 100644 --- a/src/dowraps.go +++ b/src/dowraps.go @@ -42,7 +42,7 @@ func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, boo for i := 0; i < len(codelines); { indent := len(codelines[i].code) - len(strings.TrimLeft(codelines[i].code, " ")) if indent != setindent { - return nil, false, ArErr{"Syntax Error", "invalid indent", i, code.path, codelines[i].code, true}, 1 + return nil, false, ArErr{"Syntax Error", "invalid indent", code.line, code.path, codelines[i].code, true}, 1 } val, _, err, step := translateVal(codelines[i], i, codelines, 3) @@ -57,9 +57,9 @@ func parseDoWrap(code UNPARSEcode, index int, codelines []UNPARSEcode) (any, boo func runDoWrap(d dowrap, Stack stack, stacklevel int) (any, ArErr) { newstack := append(Stack, newscope()) + newstackCopy := make(stack, len(newstack)) + copy(newstackCopy, newstack) for _, v := range d.run { - newstackCopy := make(stack, len(newstack)) - copy(newstackCopy, newstack) val, err := runVal(v, newstackCopy, stacklevel+1) if err.EXISTS { return nil, err diff --git a/src/forloop.go b/src/forloop.go index 3165599..84d1a86 100644 --- a/src/forloop.go +++ b/src/forloop.go @@ -63,7 +63,7 @@ func parseForLoop(code UNPARSEcode, index int, codelines []UNPARSEcode) (forLoop } innertotalstep += tostep - 1 body := strings.Join(tosplit[i:], ")") - bodyval, worked, err, bodystep := translateVal(UNPARSEcode{code: body, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 1) + bodyval, worked, err, bodystep := translateVal(UNPARSEcode{code: body, realcode: code.realcode, line: code.line, path: code.path}, index, codelines, 3) if !worked { if i == 0 { return forLoop{}, worked, err, bodystep diff --git a/src/ifstatement.go b/src/ifstatement.go index 42d143a..c196e42 100644 --- a/src/ifstatement.go +++ b/src/ifstatement.go @@ -70,7 +70,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst }, i, codeline, - 2, + 3, ) if err.EXISTS || !worked { return ifstatement{}, worked, err, step @@ -99,7 +99,7 @@ func parseIfStatement(code UNPARSEcode, index int, codeline []UNPARSEcode) (ifst }, i, codeline, - 2, + 3, ) if err.EXISTS { return ifstatement{}, false, err, step diff --git a/src/whileloop.go b/src/whileloop.go index ef4687e..f59253d 100644 --- a/src/whileloop.go +++ b/src/whileloop.go @@ -96,7 +96,7 @@ func parseForeverLoop(code UNPARSEcode, index int, codeline []UNPARSEcode) (whil }, index, codeline, - 2, + 3, ) return whileLoop{ condition: true, @@ -108,13 +108,14 @@ func parseForeverLoop(code UNPARSEcode, index int, codeline []UNPARSEcode) (whil } func runWhileLoop(loop whileLoop, stack stack, stacklevel int) (any, ArErr) { + newstack := append(stack, newscope()) for { condition, err := runVal(loop.condition, newstack, stacklevel+1) - newbodystack := append(newstack, newscope()) if err.EXISTS { return nil, err } + newbodystack := append(newstack, newscope()) if !anyToBool(condition) { break } diff --git a/tests/broken_funcCall.ar b/tests/broken_funcCall.ar index 4a9d8e4..73ce20e 100644 --- a/tests/broken_funcCall.ar +++ b/tests/broken_funcCall.ar @@ -9,4 +9,7 @@ let x = do let c = (class.f(path)) c.nice(callback) return class.object() -x.cool("to", ()=term.log("epic")) \ No newline at end of file + + +forever do + x.cool("to", ()="epic") \ No newline at end of file