Documentation ¶
Index ¶
- Constants
- Variables
- func NewMathTree() *mathTree
- func NewNode() *commandNode
- func NewVariableNode() *variableNode
- type CloseResponse
- type Command
- type CommandTree
- type CommandType
- type CompleteOption
- type CompleteResponse
- type Context
- type ContextType
- type ExecFunc
- type ExecResponse
- type Expression
- type ExpressionStack
- type ExpressionType
- type Flag
- type FlagValues
- type Flags
- type Item
- type LevelType
- type List
- type MathState
- type MockExpression
- func (_m *MockExpression) Add(ctx SystemContext, r models.Rune) *Response
- func (_m *MockExpression) Close(ctx SystemContext) *CloseResponse
- func (_m *MockExpression) Complete(ctx SystemContext) *CompleteResponse
- func (_m *MockExpression) Type() ExpressionType
- func (_m *MockExpression) Value(ctx SystemContext) Value
- type MockTestExec
- type NextOption
- type NextOptions
- type Object
- type Operator
- type Option
- type Options
- type OutFunc
- type ParseRuneResponse
- type ParseStringResponse
- type ParsedObject
- type Parser
- type Payload
- type Response
- func (r *Response) Action() ResponseAction
- func (r *Response) ContextType() ContextType
- func (r *Response) Err() error
- func (r *Response) Expression() Expression
- func (r *Response) WithAction(action ResponseAction) *Response
- func (r *Response) WithContextType(ctxType ContextType) *Response
- func (r *Response) WithError(err error) *Response
- func (r *Response) WithExpression(exp Expression) *Response
- func (r *Response) WithObject(object Object) *Response
- type ResponseAction
- type ResponseType
- type Result
- type StateCommand
- type SystemContext
- type SystemExecFunc
- type TestExec
- type Value
- type ValueType
- type Valuer
- type VariableState
- type VariableTree
Constants ¶
View Source
const ( DefinitionName = "parser" DefinitionNameContext = "global-context" DefinitionNameRootScope = "parser-global-scope" DefinitionNameCommandTree = "parser-command-tree" )
View Source
const ( ExpressionTypeCmd = "expression-cmd" ExpressionTypeCmdList = "expression-cmd-list" ExpressionTypeMath = "expression-math" ExpressionTypeVar = "expression-var" ExpressionTypeStd = "expression-std" )
View Source
const ( OperatorEqual = OperatorTypeCompare OperatorNotEqual = OperatorTypeCompare + 1 OperatorGreater = OperatorTypeCompare + 2 OperatorGreaterOrEqual = OperatorTypeCompare + 3 OperatorLess = OperatorTypeCompare + 4 OperatorLessOrEqual = OperatorTypeCompare + 5 OperatorConcatenate = OperatorTypeConcatenate OperatorPlus = OperatorTypeAddition OperatorMinus = OperatorTypeAddition + 1 OperatorMultiply = OperatorTypeMultiply OperatorDivide = OperatorTypeMultiply + 1 OperatorNot = OperatorTypeUnary )
Variables ¶
View Source
var ( Definition = di.Def{ Name: DefinitionName, Build: func(ctn di.Container) (interface{}, error) { return newParser(ctn), nil }, } DefinitionScope = di.Def{ Name: DefinitionNameRootScope, Build: func(ctn di.Container) (interface{}, error) { return newRootContext(ctn) }, } DefinitionContext = di.Def{ Name: DefinitionNameContext, Build: func(ctn di.Container) (interface{}, error) { return context.Background(), nil }, } DefinitionCommandTree = di.Def{ Name: DefinitionNameCommandTree, Build: func(ctn di.Container) (interface{}, error) { return List{}, nil }, } )
View Source
var ( ErrWrongRune = errors.New("wrong rune") ErrWrongPayload = errors.New("wrong payload") ErrPanic = errors.New("panic") ErrNotFinished = errors.New("not finished") )
View Source
var ( ErrWrongType = errors.New("wrong type") ErrWrongOperator = errors.New("wrong operator") ErrNoMandatoryFlag = errors.New("no mandatory flag") )
View Source
var (
NullValue = NewStringValue("")
)
Functions ¶
func NewMathTree ¶
func NewMathTree() *mathTree
func NewVariableNode ¶
func NewVariableNode() *variableNode
Types ¶
type CloseResponse ¶
type Command ¶
type Command struct { Type CommandType Path []string Name string ExecFunc ExecFunc SystemExecFunc SystemExecFunc OutFunc OutFunc Flags Flags Options Options MandatoryFlags []string // contains filtered or unexported fields }
func (*Command) Out ¶
func (c *Command) Out(ctx SystemContext, inFlags Flags)
func (*Command) UnnamedFlag ¶
type CommandTree ¶
type CommandTree struct {
// contains filtered or unexported fields
}
func BuildCommandTree ¶
func BuildCommandTree(items map[string]*Item) *CommandTree
func NewCommandTree ¶
func NewCommandTree() *CommandTree
func (*CommandTree) Add ¶
func (c *CommandTree) Add(key string, payload *Payload)
func (*CommandTree) Copy ¶
func (c *CommandTree) Copy() *CommandTree
func (*CommandTree) GetIterator ¶
func (c *CommandTree) GetIterator() *commandIterator
func (*CommandTree) Use ¶
func (c *CommandTree) Use(key string)
type CommandType ¶
type CommandType string
const ( CommandTypeUser CommandType = "user" CommandTypeSystem CommandType = "system" )
type CompleteOption ¶
type CompleteResponse ¶
type CompleteResponse struct { Options []*CompleteOption Merged string }
type ContextType ¶
type ContextType int
const ( ContextTypeNone ContextType = iota ContextTypeCopied // TODO: Rename it ContextTypeNew )
type ExecResponse ¶
type Expression ¶
type Expression interface { Valuer Type() ExpressionType Add(ctx SystemContext, r models.Rune) *Response Complete(ctx SystemContext) *CompleteResponse Close(ctx SystemContext) *CloseResponse }
func NewCommandExpression ¶
func NewCommandExpression(ctx SystemContext) Expression
func NewCommandList ¶
func NewCommandList(rootMode, isCurly bool) Expression
func NewMathExpression ¶
func NewMathExpression() Expression
func NewStdExpression ¶
func NewStdExpression(strictMode bool) Expression
func NewVariable ¶
func NewVariable(functionMode bool) Expression
type ExpressionStack ¶
type ExpressionStack struct {
// contains filtered or unexported fields
}
func (*ExpressionStack) Pop ¶
func (es *ExpressionStack) Pop() (SystemContext, Expression)
func (*ExpressionStack) Push ¶
func (es *ExpressionStack) Push(ctx SystemContext, exp Expression)
func (*ExpressionStack) Size ¶
func (es *ExpressionStack) Size() int
type ExpressionType ¶
type ExpressionType string
type Flag ¶
type Flag struct { Name string Mandatory bool Number uint ValueType // contains filtered or unexported fields }
func (*Flag) Expression ¶
func (f *Flag) Expression() Expression
func (*Flag) Set ¶
func (f *Flag) Set(e Expression)
func (*Flag) Value ¶
func (f *Flag) Value(ctx SystemContext) Value
type FlagValues ¶
func (FlagValues) Set ¶
func (fv FlagValues) Set(name string, value Value)
type MockExpression ¶
MockExpression is an autogenerated mock type for the Expression type
func (*MockExpression) Add ¶
func (_m *MockExpression) Add(ctx SystemContext, r models.Rune) *Response
Add provides a mock function with given fields: ctx, r
func (*MockExpression) Close ¶
func (_m *MockExpression) Close(ctx SystemContext) *CloseResponse
Close provides a mock function with given fields: ctx
func (*MockExpression) Complete ¶
func (_m *MockExpression) Complete(ctx SystemContext) *CompleteResponse
Complete provides a mock function with given fields: ctx
func (*MockExpression) Type ¶
func (_m *MockExpression) Type() ExpressionType
Type provides a mock function with given fields:
func (*MockExpression) Value ¶
func (_m *MockExpression) Value(ctx SystemContext) Value
Value provides a mock function with given fields: ctx
type MockTestExec ¶
MockTestExec is an autogenerated mock type for the TestExec type
func (*MockTestExec) Exec ¶
func (_m *MockTestExec) Exec(ctx Context, flags FlagValues, options Options) (Value, error)
Exec provides a mock function with given fields: ctx, flags, options
type NextOption ¶
type NextOptions ¶
type NextOptions struct { AggregatedLevel LevelType Options []*NextOption Merged string }
type Object ¶
type Object int
const ( ObjectNone Object = iota ObjectError ObjectPath ObjectCommand ObjectMandatoryFlag ObjectOptionalFlag ObjectUnknown ObjectValue ObjectOption ObjectVariableName ObjectVariableWrongName ObjectQuotedString ObjectComment // symbols ObjectSpace ObjectEqualSymbol ObjectVariableSymbol ObjectQuotedSymbol ObjectOperator ObjectSquareBrackets ObjectRoundBrackets ObjectCurlyBrackets )
type OutFunc ¶
type OutFunc func(SystemContext, Flags, Options)
type ParseRuneResponse ¶
type ParseRuneResponse struct {
Object Object
}
type ParseStringResponse ¶
type ParseStringResponse struct { Objects []*ParsedObject Error error }
type ParsedObject ¶
type Parser ¶
type Parser interface { Flush() IsFlushed() bool Add(r models.Rune) (*ParseRuneResponse, error) ParseString(s string) *ParseStringResponse Exec() (*ExecResponse, error) Continue() *CompleteResponse }
type Payload ¶
type Payload struct { Level LevelType Value string NextTree *CommandTree Payload interface{} }
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func NewResponse ¶
func NewResponse() *Response
func (*Response) Action ¶
func (r *Response) Action() ResponseAction
func (*Response) ContextType ¶
func (r *Response) ContextType() ContextType
func (*Response) Expression ¶
func (r *Response) Expression() Expression
func (*Response) WithAction ¶
func (r *Response) WithAction(action ResponseAction) *Response
func (*Response) WithContextType ¶
func (r *Response) WithContextType(ctxType ContextType) *Response
func (*Response) WithExpression ¶
func (r *Response) WithExpression(exp Expression) *Response
func (*Response) WithObject ¶
type ResponseAction ¶
type ResponseAction int
const ( ResponseGoNext ResponseAction = iota ResponseGoOut ResponseRepeat )
type ResponseType ¶
type ResponseType string
type StateCommand ¶
type StateCommand int
const ( StateCommandStart StateCommand = iota StateCommandPath StateCommandCommand StateCommandArgument StateCommandFlag StateFlagEqual StateFlagValue StateCommandOption )
type SystemContext ¶
type SystemContext interface { Context CommandTree() *CommandTree SetCommandTree(commandTree *CommandTree) CommandRoot() *CommandTree SetCommandRoot(commandRoot *CommandTree) VariableTree() *VariableTree GetVariablePayload(name string) interface{} VariableExists(name string) bool GetVariable(name string) Value SetGlobalVariable(name string, value interface{}) SetLocalVariable(name string, value interface{}) Ctx() context.Context WithContext(ctx context.Context) SystemContext New() SystemContext Copy() SystemContext Logger() logger.Logger }
type SystemExecFunc ¶
type SystemExecFunc func(SystemContext, Flags, Options) (Value, error)
type TestExec ¶
type TestExec interface {
Exec(ctx Context, flags FlagValues, options Options) (Value, error)
}
type Value ¶
type Value interface { Bool() bool Number() int String() string IsBool() bool IsString() bool IsNumber() bool Equal(v Value) bool Less(v Value) bool Greater(v Value) bool }
func NewBoolValue ¶
func NewNumberValue ¶
func NewStringValue ¶
type Valuer ¶
type Valuer interface {
Value(ctx SystemContext) Value
}
type VariableState ¶
type VariableState int
const ( VariableStateStart VariableState = iota VariableStateName VariableStateArgument VariableStateFlagName VariableStateValue )
type VariableTree ¶
type VariableTree struct {
// contains filtered or unexported fields
}
func NewVariableTree ¶
func NewVariableTree() *VariableTree
func (*VariableTree) AddGlobal ¶
func (t *VariableTree) AddGlobal(name string, value interface{})
func (*VariableTree) AddLocal ¶
func (t *VariableTree) AddLocal(name string, value interface{})
func (*VariableTree) Copy ¶
func (t *VariableTree) Copy() *VariableTree
func (*VariableTree) Get ¶
func (t *VariableTree) Get(name string) interface{}
func (*VariableTree) GetIterator ¶
func (t *VariableTree) GetIterator() *variableIterator
Source Files ¶
- command.go
- command_iterator.go
- command_node.go
- command_tree.go
- context.go
- def.go
- expression.go
- expression_cmd.go
- expression_cmd_list.go
- expression_math.go
- expression_stack.go
- expression_std.go
- expression_var.go
- flag.go
- item.go
- list.go
- math_node.go
- math_tree.go
- mock_expression.go
- mock_test_exec.go
- parser.go
- response.go
- value.go
- variable_iterator.go
- variable_node.go
- variable_tree.go
Click to show internal directories.
Click to hide internal directories.