Fix indentation and translation errors in doWrap,

forLoop, ifStatement, and whileLoop functions.
Also fix syntax error in broken_funcCall test
file.
This commit is contained in:
2023-11-14 21:48:04 +00:00
parent 65c608e088
commit c207c0668d
5 changed files with 13 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -9,4 +9,7 @@ let x = do
let c = (class.f(path))
c.nice(callback)
return class.object()
x.cool("to", ()=term.log("epic"))
forever do
x.cool("to", ()="epic")