Parser doesn't stop when it encounters wrong parenthesis
Closed this issue · 1 comments
shtolfensie commented
The parser should stop execution and return an error when it finds invalid syntax. Right now it just logs the error into the console and continues.
Console output
2021/04/28 00:52:06 &{{1 5 5} <nil> <nil>}
2021/04/28 00:52:06 &{{1 2 2} <nil> <nil>}
2021/04/28 00:52:06 &{{1 3 3} <nil> <nil>}
2021/04/28 00:52:06 &{{1 2 2} <nil> <nil>} &{{1 3 3} <nil> <nil>}
2021/04/28 00:52:06 &{{1 5 5} <nil> <nil>}
2021/04/28 00:52:06 &{{0 + 0} 0xc0000a2c30 0xc0000a2c90} &{{1 5 5} <nil> <nil>}
2021/04/28 00:52:06 error at: (
2021/04/28 00:52:06 &{{1 ( 0} <nil> <nil>}
2021/04/28 00:52:06 &{{0 * 0} 0xc0000a2d50 0xc0000a2d80} &{{1 ( 0} <nil> <nil>}
5 <nil>
PASS
ok ivs-calculator/pkg/interpreter 0.003s
Code to reproduce
func TestParse(t *testing.T) {
inStr, _ := toSlice("5%((2 + 3)(*5)")
post, _ := inToPost(inStr)
tree := postToTree(post)
fmt.Println(Interpret(tree))
}
shtolfensie commented
Also with these inputs it doesn't even detect the wrong syntax
inStr, _ := toSlice("5%((2 +3)()*5)")
--- or ---
inStr, _ := toSlice("5%((2 +3)(4)*5)")
--- or ---
inStr, _ := toSlice("5%((2 +3)(4+9)*5)")
Should we consider this correct syntax? I would prefer if it was reported as an error to the user.
The last one is the worst, because it might almost look correct, but the parser completely ignores it.