ql

package
v0.0.0-...-2873e01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CHAR_WHITELIST_WHITESPACE = " \n\t"
	CHAR_WHITELIST_OPERATORS  = "!+-/*=<>&|"
	CHAR_WHITELIST_QUOTES     = "'"
)
View Source
const (
	// Special tokens
	ILLEGAL tokenCode = iota
	EOF
	WS // 2
	IDENT
	LNULL
	LBOOL // 4
	LNUMBER
	LSTRING
	COMMA    // ,
	DOT      // .
	OPERATOR // + - / *
	PARENTHESIS_OPEN
	PARENTHESIS_CLOSE
	KEYWORD
)

Variables

This section is empty.

Functions

func MakeValueOf

func MakeValueOf(t string, v interface{}) *typedValue

func WrapValue

func WrapValue(v expr.TypedValue) *typedValue

Types

type ASTNode

type ASTNode struct {

	// Meta holds additional node data
	// while processing the AST
	Meta map[string]any `json:"-"`

	Ref  string     `json:"ref,omitempty"`
	Args ASTNodeSet `json:"args,omitempty"`

	Symbol string      `json:"symbol,omitempty"`
	Value  *typedValue `json:"value,omitempty"`

	Raw string `json:"raw,omitempty"`
	// contains filtered or unexported fields
}

func MergeAnd

func MergeAnd(a, b *ASTNode) *ASTNode

func MergeOr

func MergeOr(a, b *ASTNode) *ASTNode

func (ASTNode) Clone

func (n ASTNode) Clone() *ASTNode

func (*ASTNode) CollectSymbols

func (n *ASTNode) CollectSymbols() (out []string)

func (*ASTNode) String

func (n *ASTNode) String() string

func (*ASTNode) Traverse

func (n *ASTNode) Traverse(f func(*ASTNode) (bool, *ASTNode, error)) (err error)

Traverse traverses the AST down to leaf nodes.

If fnc. returns false, the traversal of the current branch ends.

type ASTNodeSet

type ASTNodeSet []*ASTNode

type FunctionHandler

type FunctionHandler func(ident function) (parserNode, error)

type Ident

type Ident struct {
	Value string
	// contains filtered or unexported fields
}

SelectStatement represents a SQL SELECT statement.

func (Ident) String

func (n Ident) String() string

func (Ident) ToAST

func (n Ident) ToAST() (out *ASTNode)

func (Ident) Validate

func (n Ident) Validate() (err error)

type IdentHandler

type IdentHandler func(ident Ident) (Ident, error)

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer represents a lexical scanner.

func NewLexer

func NewLexer(r io.Reader) *Lexer

NewLexer returns a new instance of Lexer.

func (*Lexer) Scan

func (s *Lexer) Scan() Token

Scan returns the next token and literal value.

type Parser

type Parser struct {
	OnIdent    IdentHandler
	OnFunction FunctionHandler
	// contains filtered or unexported fields
}

Parser represents a parser.

func NewParser

func NewParser() *Parser

NewParser returns a new instance of Parser.

func (*Parser) Parse

func (p *Parser) Parse(s string) (*ASTNode, error)

Parse parses the given expression and returns the generated AST

type RuneReader

type RuneReader interface {
	// contains filtered or unexported methods
}

Lexer represents a lexical scanner.

type Token

type Token struct {
	// contains filtered or unexported fields
}

Lexer represents a lexical scanner.

func (Token) Is

func (t Token) Is(cc ...tokenCode) bool

type TokenConsumerComma

type TokenConsumerComma struct{}

type TokenConsumerGeneric

type TokenConsumerGeneric struct {
	// contains filtered or unexported fields
}

func (TokenConsumerGeneric) Consume

func (g TokenConsumerGeneric) Consume(s RuneReader) Token

func (TokenConsumerGeneric) Test

func (g TokenConsumerGeneric) Test(ch rune) bool

type TokenConsumerIdent

type TokenConsumerIdent struct{}

func (TokenConsumerIdent) Consume

func (TokenConsumerIdent) Consume(s RuneReader) Token

Consumes the current rune and all contiguous ident runes.

func (TokenConsumerIdent) Test

func (i TokenConsumerIdent) Test(ch rune) bool

type TokenConsumerNumber

type TokenConsumerNumber struct{}

func (TokenConsumerNumber) Consume

func (str TokenConsumerNumber) Consume(s RuneReader) Token

Consumes entire number (very naive and simplified)

func (TokenConsumerNumber) Test

func (str TokenConsumerNumber) Test(ch rune) bool

type TokenConsumerOperator

type TokenConsumerOperator struct{}

type TokenConsumerString

type TokenConsumerString struct{}

func (TokenConsumerString) Consume

func (str TokenConsumerString) Consume(s RuneReader) Token

Consumes entire string (skipping quotes)

func (TokenConsumerString) Test

func (str TokenConsumerString) Test(ch rune) bool

type TokenConsumerWS

type TokenConsumerWS struct{}

type TokenConsumers

type TokenConsumers interface {
	Test(ch rune) bool
	Consume(s RuneReader) Token
}

Lexer represents a lexical scanner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL