Replace SQLite with BadgerDB

This commit is contained in:
David Stotijn
2022-01-21 11:45:54 +01:00
parent 8a3b3cbf02
commit d84d2d0905
49 changed files with 2496 additions and 2677 deletions

View File

@ -2,6 +2,7 @@ package search
import (
"fmt"
"regexp"
)
type precedence int
@ -99,7 +100,7 @@ func ParseQuery(input string) (expr Expression, err error) {
case expr == nil:
expr = right
default:
expr = &InfixExpression{
expr = InfixExpression{
Operator: TokOpAnd,
Left: expr,
Right: right,
@ -170,7 +171,7 @@ func (p *Parser) parseExpression(prec precedence) (Expression, error) {
}
func parsePrefixExpression(p *Parser) (Expression, error) {
expr := &PrefixExpression{
expr := PrefixExpression{
Operator: p.cur.Type,
}
@ -187,7 +188,7 @@ func parsePrefixExpression(p *Parser) (Expression, error) {
}
func parseInfixExpression(p *Parser, left Expression) (Expression, error) {
expr := &InfixExpression{
expr := InfixExpression{
Operator: p.cur.Type,
Left: left,
}
@ -200,13 +201,24 @@ func parseInfixExpression(p *Parser, left Expression) (Expression, error) {
return nil, fmt.Errorf("could not parse expression for right operand: %w", err)
}
if expr.Operator == TokOpRe || expr.Operator == TokOpNotRe {
if rightStr, ok := right.(StringLiteral); ok {
re, err := regexp.Compile(rightStr.Value)
if err != nil {
return nil, fmt.Errorf("could not compile regular expression %q: %w", rightStr.Value, err)
}
right = re
}
}
expr.Right = right
return expr, nil
}
func parseStringLiteral(p *Parser) (Expression, error) {
return &StringLiteral{Value: p.cur.Literal}, nil
return StringLiteral{Value: p.cur.Literal}, nil
}
func parseGroupedExpression(p *Parser) (Expression, error) {
@ -227,7 +239,7 @@ func parseGroupedExpression(p *Parser) (Expression, error) {
return nil, fmt.Errorf("could not parse expression: %w", err)
}
expr = &InfixExpression{
expr = InfixExpression{
Operator: TokOpAnd,
Left: expr,
Right: right,