Documentation ¶
Index ¶
- Constants
- Variables
- func ErrInvalidIdentifier(name string) error
- func ForEach(box Box, fn func(value interface{}) bool)
- func IsInvalidIdentifierErr(err error) bool
- func IsRuntimeError(err error) bool
- func RuntimeErrorf(msg string, args ...interface{}) error
- type AccessorExpression
- type Bool
- type Box
- type BoxBool
- type BoxFloat
- type BoxInteger
- type BoxLambda
- type BoxMapInterfaceInterface
- type BoxMapStringInterface
- type BoxNestedScope
- type BoxSliceString
- type BoxString
- type CallExpression
- type Empty
- type Expression
- type ExpressionStatement
- type Float
- type FuncScope
- type GlobalFuncScope
- type Identifier
- type IndexExpression
- type InfixExpression
- type InfixFunc
- type Integer
- type InvalidIdentifierError
- type LambdaExpression
- type Lexer
- type NestedScope
- type Ord
- type Parser
- type Position
- type PrefixFunc
- type Query
- type QueryExpression
- type RuntimeError
- type Scope
- type String
- type Token
- type TokenType
Constants ¶
const ( LOWEST = iota PCONDOR PCONDAND EQUALS LESSGREATER PPRODUCT CALL INDEX )
Variables ¶
var ( // UnknownToken can be used as a sentinel token for a unknown state. UnknownToken = Token{ Type: UNKNOWN, } )
Functions ¶
func ErrInvalidIdentifier ¶
ErrInvalidIdentifier defines a sentinel error for invalid identifiers.
func ForEach ¶
ForEach will call the function on every value within a Box. If a Box isn't an iterable then we perform a no-op.
func IsInvalidIdentifierErr ¶
IsInvalidIdentifierErr returns if the error is an ErrInvalidIdentifier error
func IsRuntimeError ¶
IsRuntimeError returns if the error is an ErrInvalidIndex error
func RuntimeErrorf ¶
RuntimeErrorf defines a sentinel error for invalid index.
Types ¶
type AccessorExpression ¶
type AccessorExpression struct { Token Token Right Expression Left Expression }
AccessorExpression represents an expression that is associated with an operator.
func (*AccessorExpression) End ¶
func (ie *AccessorExpression) End() Position
End returns the last position of the identifier.
func (*AccessorExpression) Pos ¶
func (ie *AccessorExpression) Pos() Position
Pos returns the first position of the identifier.
func (*AccessorExpression) String ¶
func (ie *AccessorExpression) String() string
type Box ¶
type Box interface { Ord // IsZero returns if the underlying value is zero. IsZero() bool // Value defines the shadow type value of the Box. Value() interface{} }
Box represents a boxed datatype.
func ConvertRawResult ¶
type BoxBool ¶
type BoxBool struct {
// contains filtered or unexported fields
}
BoxBool defines an ordered float.
type BoxFloat ¶
type BoxFloat struct {
// contains filtered or unexported fields
}
BoxFloat defines an ordered float.
type BoxInteger ¶
type BoxInteger struct {
// contains filtered or unexported fields
}
BoxInteger defines an ordered integer.
func (*BoxInteger) Equal ¶
func (o *BoxInteger) Equal(other Ord) bool
Equal checks if an BoxInteger is equal to another BoxInteger.
func (*BoxInteger) ForEach ¶
func (o *BoxInteger) ForEach(fn func(interface{}) bool)
ForEach iterates over each value in the box.
func (*BoxInteger) IsZero ¶
func (o *BoxInteger) IsZero() bool
IsZero returns if the underlying value is zero.
func (*BoxInteger) Less ¶
func (o *BoxInteger) Less(other Ord) bool
Less checks if a BoxInteger is less than another BoxInteger.
func (*BoxInteger) Value ¶
func (o *BoxInteger) Value() interface{}
Value defines the shadow type value of the Box.
type BoxLambda ¶
type BoxLambda struct {
// contains filtered or unexported fields
}
BoxLambda defines an ordered integer.
func NewLambda ¶
func NewLambda(arg *Identifier, fn func(Scope) ([]Box, error)) *BoxLambda
NewLambda creates a new Box value
type BoxMapInterfaceInterface ¶
type BoxMapInterfaceInterface struct {
// contains filtered or unexported fields
}
BoxMapInterfaceInterface defines an ordered map[interface{}]interface{}.
func NewMapInterfaceInterface ¶
func NewMapInterfaceInterface(value map[interface{}]interface{}) *BoxMapInterfaceInterface
NewMapInterfaceInterface creates a new Box value
func (*BoxMapInterfaceInterface) Equal ¶
func (o *BoxMapInterfaceInterface) Equal(other Ord) bool
Equal checks if an BoxMapInterfaceInterface is equal to another BoxMapInterfaceInterface.
func (*BoxMapInterfaceInterface) ForEach ¶
func (o *BoxMapInterfaceInterface) ForEach(fn func(interface{}) bool)
ForEach iterates over each value in the box.
func (*BoxMapInterfaceInterface) IsZero ¶
func (o *BoxMapInterfaceInterface) IsZero() bool
IsZero returns if the underlying value is zero.
func (*BoxMapInterfaceInterface) Less ¶
func (o *BoxMapInterfaceInterface) Less(other Ord) bool
Less checks if a BoxMapInterfaceInterface is less than another BoxMapInterfaceInterface.
func (*BoxMapInterfaceInterface) Value ¶
func (o *BoxMapInterfaceInterface) Value() interface{}
Value defines the shadow type value of the Box.
type BoxMapStringInterface ¶
type BoxMapStringInterface struct {
// contains filtered or unexported fields
}
BoxMapStringInterface defines an ordered map[string]interface{}.
func NewMapStringInterface ¶
func NewMapStringInterface(value map[string]interface{}) *BoxMapStringInterface
NewMapStringInterface creates a new Box value
func (*BoxMapStringInterface) Equal ¶
func (o *BoxMapStringInterface) Equal(other Ord) bool
Equal checks if an BoxMapStringInterface is equal to another BoxMapStringInterface.
func (*BoxMapStringInterface) ForEach ¶
func (o *BoxMapStringInterface) ForEach(fn func(interface{}) bool)
ForEach iterates over each value in the box.
func (*BoxMapStringInterface) IsZero ¶
func (o *BoxMapStringInterface) IsZero() bool
IsZero returns if the underlying value is zero.
func (*BoxMapStringInterface) Less ¶
func (o *BoxMapStringInterface) Less(other Ord) bool
Less checks if a BoxMapStringInterface is less than another BoxMapStringInterface.
func (*BoxMapStringInterface) Value ¶
func (o *BoxMapStringInterface) Value() interface{}
Value defines the shadow type value of the Box.
type BoxNestedScope ¶
type BoxNestedScope struct {
// contains filtered or unexported fields
}
BoxNestedScope defines an ordered integer.
func (*BoxNestedScope) Equal ¶
func (o *BoxNestedScope) Equal(other Ord) bool
Equal checks if an BoxNestedScope is equal to another BoxNestedScope.
func (*BoxNestedScope) IsZero ¶
func (o *BoxNestedScope) IsZero() bool
IsZero returns if the underlying value is zero.
func (*BoxNestedScope) Less ¶
func (o *BoxNestedScope) Less(other Ord) bool
Less checks if a BoxNestedScope is less than another BoxNestedScope.
func (*BoxNestedScope) Value ¶
func (o *BoxNestedScope) Value() interface{}
Value defines the shadow type value of the Box.
type BoxSliceString ¶
type BoxSliceString struct {
// contains filtered or unexported fields
}
BoxSliceString defines an ordered []string.
func NewSliceString ¶
func NewSliceString(value []string) *BoxSliceString
NewSliceString creates a new Box value
func (*BoxSliceString) Equal ¶
func (o *BoxSliceString) Equal(other Ord) bool
Equal checks if an BoxSliceString is equal to another BoxSliceString.
func (*BoxSliceString) ForEach ¶
func (o *BoxSliceString) ForEach(fn func(interface{}) bool)
ForEach iterates over each value in the box.
func (*BoxSliceString) IsZero ¶
func (o *BoxSliceString) IsZero() bool
IsZero returns if the underlying value is zero.
func (*BoxSliceString) Less ¶
func (o *BoxSliceString) Less(other Ord) bool
Less checks if a BoxSliceString is less than another BoxSliceString.
func (*BoxSliceString) Value ¶
func (o *BoxSliceString) Value() interface{}
Value defines the shadow type value of the Box.
type BoxString ¶
type BoxString struct {
// contains filtered or unexported fields
}
BoxString defines an ordered string.
type CallExpression ¶
type CallExpression struct { Token Token Name Expression Arguments []Expression }
CallExpression represents an expression that is associated with an operator.
func (*CallExpression) End ¶
func (ie *CallExpression) End() Position
End returns the last position of the identifier.
func (*CallExpression) Pos ¶
func (ie *CallExpression) Pos() Position
Pos returns the first position of the identifier.
func (*CallExpression) String ¶
func (ie *CallExpression) String() string
type Empty ¶
type Empty struct {
Token Token
}
Empty represents an empty expression
type Expression ¶
Expression defines a type of AST node for outlining an expression.
type ExpressionStatement ¶
type ExpressionStatement struct { Token Token Expression Expression }
ExpressionStatement is a group of expressions that allows us to group a subset of expressions.
func (*ExpressionStatement) End ¶
func (es *ExpressionStatement) End() Position
End returns the last position of the expression statement.
func (*ExpressionStatement) Pos ¶
func (es *ExpressionStatement) Pos() Position
Pos returns the first position of the expression statement.
func (*ExpressionStatement) String ¶
func (es *ExpressionStatement) String() string
type FuncScope ¶
type FuncScope interface { Add(string, interface{}) Call(*Identifier, []Box) (interface{}, error) }
FuncScope is used to call functions for a given identifier.
type GlobalFuncScope ¶
type GlobalFuncScope struct {
// contains filtered or unexported fields
}
GlobalFuncScope defines a set of builtin functions that can be executed based on a set of arguments.
func NewGlobalFuncScope ¶
func NewGlobalFuncScope(scope Scope) *GlobalFuncScope
NewGlobalFuncScope creates a new scope for executing functions.
func (*GlobalFuncScope) Add ¶
func (s *GlobalFuncScope) Add(name string, fn interface{})
Add a function to the global scope.
func (*GlobalFuncScope) Call ¶
func (s *GlobalFuncScope) Call(ident *Identifier, params []Box) (interface{}, error)
Call a function with a set of arguments.
type Identifier ¶
type Identifier struct {
Token Token
}
Identifier represents an identifier for a given AST block
func (*Identifier) End ¶
func (i *Identifier) End() Position
End returns the last position of the identifier.
func (*Identifier) Pos ¶
func (i *Identifier) Pos() Position
Pos returns the first position of the identifier.
func (*Identifier) String ¶
func (i *Identifier) String() string
type IndexExpression ¶
type IndexExpression struct { Token Token Operator string Left Expression Index Expression }
IndexExpression represents an expression that is associated with an operator.
func (*IndexExpression) End ¶
func (ie *IndexExpression) End() Position
End returns the last position of the identifier.
func (*IndexExpression) Pos ¶
func (ie *IndexExpression) Pos() Position
Pos returns the first position of the identifier.
func (*IndexExpression) String ¶
func (ie *IndexExpression) String() string
type InfixExpression ¶
type InfixExpression struct { Token Token Operator string Right Expression Left Expression }
AccessorExpression represents an expression that is associated with an operator.
func (*InfixExpression) End ¶
func (ie *InfixExpression) End() Position
End returns the last position of the identifier.
func (*InfixExpression) Pos ¶
func (ie *InfixExpression) Pos() Position
Pos returns the first position of the identifier.
func (*InfixExpression) String ¶
func (ie *InfixExpression) String() string
type InfixFunc ¶
type InfixFunc func(Expression) Expression
type Integer ¶
Integer represents an integer for a given AST block
type InvalidIdentifierError ¶
type InvalidIdentifierError struct {
// contains filtered or unexported fields
}
InvalidIdentifierError creates an invalid error.
func (*InvalidIdentifierError) Error ¶
func (e *InvalidIdentifierError) Error() string
func (*InvalidIdentifierError) Name ¶
func (e *InvalidIdentifierError) Name() string
Name returns the name associated with the identifier error.
type LambdaExpression ¶
type LambdaExpression struct { Token Token Argument Expression Expressions []Expression }
LambdaExpression represents an expression that is associated with an operator.
func (*LambdaExpression) End ¶
func (ie *LambdaExpression) End() Position
End returns the last position of the identifier.
func (*LambdaExpression) Pos ¶
func (ie *LambdaExpression) Pos() Position
Pos returns the first position of the identifier.
func (*LambdaExpression) String ¶
func (ie *LambdaExpression) String() string
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer takes a query and breaks it down into tokens that can be consumed at at later date. The lexer in question is lazy and requires the calling of next to move it forward.
type NestedScope ¶
type NestedScope struct {
// contains filtered or unexported fields
}
NestedScope allows scopes to be nested together in a named manor.
func MakeNestedScope ¶
func MakeNestedScope(base Scope) NestedScope
MakeNestedScope creates a new NestedScope.
func (NestedScope) GetIdentValue ¶
func (m NestedScope) GetIdentValue(name string) (Box, error)
GetIdentValue returns the value of the identifier in a given scope.
func (NestedScope) GetIdents ¶
func (m NestedScope) GetIdents() []string
GetIdents returns the identifiers with in a given scope.
func (NestedScope) SetScope ¶
func (m NestedScope) SetScope(name string, scope Scope)
SetScope will set a scope on a given scope.
type Ord ¶
type Ord interface { // Less checks if a Box is less than another Box Less(Ord) bool // Equal checks if an Box is equal to another Box. Equal(Ord) bool }
Ord represents an ordered type
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
func (*Parser) Run ¶
func (p *Parser) Run() (*QueryExpression, error)
Run the parser to the end, which is either an EOF or an error.
type PrefixFunc ¶
type PrefixFunc func() Expression
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
Query holds all the arguments for a given query.
func Parse ¶
Parse attempts to parse a given query into a argument query. Returns an error if it's not in the correct layout.
func (Query) BuiltinsRun ¶
BuiltinsRun runs the query with a set of builtin functions.
type QueryExpression ¶
type QueryExpression struct {
Expressions []Expression
}
QueryExpression represents a query full of expressions
func (*QueryExpression) End ¶
func (e *QueryExpression) End() Position
End returns the last position of the query expression.
func (*QueryExpression) Pos ¶
func (e *QueryExpression) Pos() Position
Pos returns the first position of the query expression.
func (*QueryExpression) String ¶
func (e *QueryExpression) String() string
type RuntimeError ¶
type RuntimeError struct {
// contains filtered or unexported fields
}
RuntimeError creates an invalid error.
func (*RuntimeError) Error ¶
func (e *RuntimeError) Error() string
type Scope ¶
type Scope interface { // GetIdents returns the identifiers that are supported for a given scope. GetIdents() []string // GetIdentValue returns the value of the identifier in a given scope. GetIdentValue(string) (Box, error) }
Scope is used to identify a given expression of a global mutated object.
type Token ¶
Token defines a token found with in a query, along with the position and what type it is.
type TokenType ¶
type TokenType int
TokenType represents a way to identify an individual token.
const ( UNKNOWN TokenType = (iota - 1) EOF IDENT INT //int literal FLOAT //float literal STRING EQ // == NEQ // != ASSIGN // = BANG // ! LT // < LE // <= GT // > GE // >= COMMA // , SEMICOLON // ; LPAREN // ( RPAREN // ) LBRACKET // [ RBRACKET // ] BITAND // & BITOR // | CONDAND // && CONDOR // || TRUE // TRUE FALSE // FALSE LAMBDA // => UNDERSCORE // _ PERIOD // . )