parser: accepts espression forest (multi expressions)
This commit is contained in:
parent
4e361f938e
commit
28e3b2f741
@ -81,6 +81,11 @@ func (self *parser) parse(scanner *scanner, termSymbols ...Symbol) (tree *ast, e
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tk.Sym == SymSemiColon {
|
||||||
|
tree.ToForest()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
//fmt.Println("Token:", tk)
|
//fmt.Println("Token:", tk)
|
||||||
if firstToken && (tk.Sym == SymMinus || tk.Sym == SymPlus) {
|
if firstToken && (tk.Sym == SymMinus || tk.Sym == SymPlus) {
|
||||||
if tk.Sym == SymMinus {
|
if tk.Sym == SymMinus {
|
||||||
|
@ -19,7 +19,8 @@ func TestParser(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// inputs1 := []inputType{
|
// 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},
|
// {`"a" < "b" AND ~ 2 == 1`, true, nil},
|
||||||
// }
|
// }
|
||||||
|
|
||||||
@ -123,8 +124,10 @@ func TestParser(t *testing.T) {
|
|||||||
/* 97 */ {`false and true`, false, nil},
|
/* 97 */ {`false and true`, false, nil},
|
||||||
/* 98 */ {`false and (x==2)`, false, nil},
|
/* 98 */ {`false and (x==2)`, false, nil},
|
||||||
/* 99 */ {`false and (x=2 but x==2) or x==2`, nil, errors.New(`undefined variable "x"`)},
|
/* 99 */ {`false and (x=2 but x==2) or x==2`, nil, errors.New(`undefined variable "x"`)},
|
||||||
/*100 */ {`false or true`, true, nil},
|
/* 100 */ {`false or true`, true, nil},
|
||||||
/*101 */ {`false or (x==2)`, nil, errors.New(`undefined variable "x"`)},
|
/* 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
|
succeeded := 0
|
||||||
failed := 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) {
|
func logTest(t *testing.T, n int, source string, wantResult any, wantErr error) {
|
||||||
if wantErr == nil {
|
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 {
|
} 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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user