mirror of
https://github.com/dstotijn/hetty.git
synced 2025-07-01 18:47:29 -04:00
Replace lexer, add parser
This commit is contained in:
53
pkg/search/ast.go
Normal file
53
pkg/search/ast.go
Normal file
@ -0,0 +1,53 @@
|
||||
package search
|
||||
|
||||
import "strings"
|
||||
|
||||
type Expression interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
type PrefixExpression struct {
|
||||
Operator TokenType
|
||||
Right Expression
|
||||
}
|
||||
|
||||
func (pe *PrefixExpression) expressionNode() {}
|
||||
func (pe *PrefixExpression) String() string {
|
||||
b := strings.Builder{}
|
||||
b.WriteString("(")
|
||||
b.WriteString(pe.Operator.String())
|
||||
b.WriteString(" ")
|
||||
b.WriteString(pe.Right.String())
|
||||
b.WriteString(")")
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
type InfixExpression struct {
|
||||
Operator TokenType
|
||||
Left Expression
|
||||
Right Expression
|
||||
}
|
||||
|
||||
func (ie *InfixExpression) expressionNode() {}
|
||||
func (ie *InfixExpression) String() string {
|
||||
b := strings.Builder{}
|
||||
b.WriteString("(")
|
||||
b.WriteString(ie.Left.String())
|
||||
b.WriteString(" ")
|
||||
b.WriteString(ie.Operator.String())
|
||||
b.WriteString(" ")
|
||||
b.WriteString(ie.Right.String())
|
||||
b.WriteString(")")
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
type StringLiteral struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
func (sl *StringLiteral) expressionNode() {}
|
||||
func (sl *StringLiteral) String() string {
|
||||
return sl.Value
|
||||
}
|
Reference in New Issue
Block a user