Documentation
¶
Overview ¶
Package parser contains the definitions of the base tokens, the lexer that converts a query to a token stream, and the parser that converts a token stream into an AST.
Index ¶
Constants ¶
const ( OPERATION = "operation" EXPRESSION = "expression" )
Variables ¶
var TokenLookup = map[Token]string{
OTHER: "OTHER",
EOF: "EOF",
WS: "WS",
STRING: "STRING",
EQUAL: "EQUAL",
GREATER_THAN: "GREATER THAN",
GREATHER_THAN_EQUAL: "GREATER THAN OR EQUAL",
LESS_THAN: "LESS THAN",
LESS_THAN_EQUAL: "LESS THAN OR EQUAL",
NOT_EQUAL: "NOT EQUAL",
AND: "AND",
OR: "OR",
OPEN_BRACKET: "(",
CLOSED_BRACKET: ")",
PERCENT: "%",
}
TokenLookup is a map, useful for printing readable names of the tokens.
Functions ¶
This section is empty.
Types ¶
type Expression ¶
Expression represents something like x=y or x>=y
func (Expression) String ¶
func (e Expression) String() string
String returns the string representation of expression.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer represents a lexical scanner.
func NewLexerFromString ¶
NewLexerFromString returns a Lexer for the provided string.
type Operation ¶
Operation represents a Node (Operation or Expression) compared with another Node using either `AND` or `OR`.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser represents a parser, including a scanner and the underlying raw input. It also contains a small buffer to allow for two unscans.
type Token ¶
type Token int
Token represents a lexical token.
const ( // Special tokens // Iota simply starts and integer count OTHER Token = iota EOF WS // Main literals STRING // Brackets OPEN_BRACKET CLOSED_BRACKET // Special characters GREATER_THAN GREATHER_THAN_EQUAL LESS_THAN LESS_THAN_EQUAL EQUAL NOT_EQUAL PERCENT // Keywords AND OR )
Declare the tokens here.
type TokenStack ¶
type TokenStack struct {
// contains filtered or unexported fields
}
TokenStack is used as the buffer for the Parser.
func (*TokenStack) Len ¶
func (s *TokenStack) Len() int
Len returns the current length of the TokenStack.
func (*TokenStack) Pop ¶
func (s *TokenStack) Pop() (TokenInfo, error)
Pop removes and returns a token from the TokenStack.
func (*TokenStack) Push ¶
func (s *TokenStack) Push(v TokenInfo)
Push pushes a token to the TokenStack.