parser: accepts espression forest (multi expressions)

This commit is contained in:
Celestino Amoroso 2024-03-31 06:10:27 +02:00
parent 4e361f938e
commit 28e3b2f741
2 changed files with 112 additions and 104 deletions

View File

@ -81,6 +81,11 @@ func (self *parser) parse(scanner *scanner, termSymbols ...Symbol) (tree *ast, e
continue
}
if tk.Sym == SymSemiColon {
tree.ToForest()
continue
}
//fmt.Println("Token:", tk)
if firstToken && (tk.Sym == SymMinus || tk.Sym == SymPlus) {
if tk.Sym == SymMinus {

View File

@ -19,7 +19,8 @@ func TestParser(t *testing.T) {
}
// inputs1 := []inputType{
// {`true AND true`, true, nil},
// {`a=5; a`, int64(5), nil},
// {`a=5; b=2; add(a, b*3)`, int64(11), nil},
// {`"a" < "b" AND ~ 2 == 1`, true, nil},
// }
@ -125,6 +126,8 @@ func TestParser(t *testing.T) {
/* 99 */ {`false and (x=2 but x==2) or x==2`, nil, errors.New(`undefined variable "x"`)},
/* 100 */ {`false or true`, true, nil},
/* 101 */ {`false or (x==2)`, nil, errors.New(`undefined variable "x"`)},
/* 102 */ {`a=5; a`, int64(5), nil},
/* 103 */ {`a=5; b=2; add(a, b*3)`, int64(11), nil},
}
succeeded := 0
failed := 0
@ -272,8 +275,8 @@ func NoTestListParser(t *testing.T) {
func logTest(t *testing.T, n int, source string, wantResult any, wantErr error) {
if wantErr == nil {
t.Log(fmt.Sprintf("[+]Test nr %2d -- %q --> %v", n, source, wantResult))
t.Log(fmt.Sprintf("[+]Test nr %3d -- %q --> %v", n, source, wantResult))
} else {
t.Log(fmt.Sprintf("[-]Test nr %2d -- %q --> %v", n, source, wantErr))
t.Log(fmt.Sprintf("[-]Test nr %3d -- %q --> %v", n, source, wantErr))
}
}