mirror of
https://github.com/dstotijn/hetty
synced 2024-11-26 21:50:19 +00:00
Support implicit boolean expression nested in groups
This commit is contained in:
parent
5bce912e89
commit
8ab65fb55f
2 changed files with 24 additions and 3 deletions
|
@ -9,10 +9,10 @@ type precedence int
|
||||||
const (
|
const (
|
||||||
_ precedence = iota
|
_ precedence = iota
|
||||||
precLowest
|
precLowest
|
||||||
|
precEq
|
||||||
precAnd
|
precAnd
|
||||||
precOr
|
precOr
|
||||||
precNot
|
precNot
|
||||||
precEq
|
|
||||||
precLessGreater
|
precLessGreater
|
||||||
precPrefix
|
precPrefix
|
||||||
precGroup
|
precGroup
|
||||||
|
@ -218,8 +218,19 @@ func parseGroupedExpression(p *Parser) (Expression, error) {
|
||||||
return nil, fmt.Errorf("could not parse grouped expression: %v", err)
|
return nil, fmt.Errorf("could not parse grouped expression: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := p.expectPeek(TokParenClose); err != nil {
|
for p.nextToken(); !p.curTokenIs(TokParenClose); p.nextToken() {
|
||||||
return nil, err
|
if p.curTokenIs(TokEOF) {
|
||||||
|
return nil, fmt.Errorf("unexpected EOF: unmatched parentheses")
|
||||||
|
}
|
||||||
|
right, err := p.parseExpression(precLowest)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("could not parse expression: %v", err)
|
||||||
|
}
|
||||||
|
expr = &InfixExpression{
|
||||||
|
Operator: TokOpAnd,
|
||||||
|
Left: expr,
|
||||||
|
Right: right,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return expr, nil
|
return expr, nil
|
||||||
|
|
|
@ -153,6 +153,16 @@ func TestParseQuery(t *testing.T) {
|
||||||
},
|
},
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "implicit boolean expression nested in group",
|
||||||
|
input: "(foo bar)",
|
||||||
|
expectedExpression: &InfixExpression{
|
||||||
|
Operator: TokOpAnd,
|
||||||
|
Left: &StringLiteral{Value: "foo"},
|
||||||
|
Right: &StringLiteral{Value: "bar"},
|
||||||
|
},
|
||||||
|
expectedError: nil,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "implicit and explicit boolean expression with string literal operands",
|
name: "implicit and explicit boolean expression with string literal operands",
|
||||||
input: "foo bar OR baz yolo",
|
input: "foo bar OR baz yolo",
|
||||||
|
|
Loading…
Reference in a new issue