sfvm

package
v1.3.3-beta11 Latest Latest
Warning

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

Go to latest
Published: May 28, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.3.3

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

func NewConfig added in v1.3.3

func NewConfig(opts ...Option) *Config

type Glob added in v1.3.3

type Glob interface {
	Match(string) bool
	String() string
}

type GlobEx added in v1.3.3

type GlobEx struct {
	Origin glob.Glob
	Rule   string
}

func (*GlobEx) Match added in v1.3.3

func (g *GlobEx) Match(d string) bool

func (*GlobEx) String added in v1.3.3

func (g *GlobEx) String() string

type Option added in v1.3.3

type Option func(*Config)

func WithEnableDebug added in v1.3.3

func WithEnableDebug(b ...bool) Option

func WithInitialContextVars added in v1.3.3

func WithInitialContextVars(o *omap.OrderedMap[string, ValueOperator]) Option

func WithResultCaptured added in v1.3.3

func WithResultCaptured(c ResultCapturedCallback) Option

type RecursiveConfigItem added in v1.3.3

type RecursiveConfigItem struct {
	Key            string
	Value          string
	SyntaxFlowRule bool
}

type RecursiveConfigKey added in v1.3.3

type RecursiveConfigKey string
const (
	RecursiveConfig_Depth    RecursiveConfigKey = "depth"
	RecursiveConfig_DepthMin RecursiveConfigKey = "depth_min"
	RecursiveConfig_DepthMax RecursiveConfigKey = "depth_max"
	RecursiveConfig_Exclude  RecursiveConfigKey = "exclude"
)

func FormatRecursiveConfigKey added in v1.3.3

func FormatRecursiveConfigKey(i string) RecursiveConfigKey

type ResultCapturedCallback added in v1.3.3

type ResultCapturedCallback func(name string, results ValueOperator) error

type SFFrame

type SFFrame struct {
	Text  string
	Codes []*SFI

	StatementStack *utils.Stack[int]
	// contains filtered or unexported fields
}

func NewSFFrame

func NewSFFrame(vars *omap.OrderedMap[string, ValueOperator], text string, codes []*SFI) *SFFrame

func (*SFFrame) Debug

func (s *SFFrame) Debug(v ...bool) *SFFrame

func (*SFFrame) GetSymbolTable

func (s *SFFrame) GetSymbolTable() *omap.OrderedMap[string, ValueOperator]

func (*SFFrame) ToLeft

func (s *SFFrame) ToLeft() bool

func (*SFFrame) ToRight

func (s *SFFrame) ToRight() bool

type SFI

type SFI struct {
	OpCode           SFVMOpCode
	UnaryInt         int
	UnaryStr         string
	UnaryBool        bool
	Desc             string
	Values           []string
	SyntaxFlowConfig []*RecursiveConfigItem
}

func (*SFI) String

func (s *SFI) String() string

type SFVMOpCode

type SFVMOpCode int
const (
	OpPass SFVMOpCode = iota

	// enter/exit statement
	OpEnterStatement
	OpExitStatement

	OpPushInput
	OpDuplicate

	// OpPushNumber and OpPushString and OpPushBool can push literal into stack
	OpPushNumber
	OpPushString
	OpPushBool
	OpPop

	// OpPushSearchExact can push data from origin
	OpPushSearchExact
	OpPushSearchGlob
	OpPushSearchRegexp

	OpGetCallArgs
	OpGetAllCallArgs

	// use def chain
	OpGetUsers
	OpGetBottomUsers
	OpGetDefs
	OpGetTopDefs

	// ListOperation
	OpListIndex

	// => variable
	OpNewRef
	OpUpdateRef

	/*
		Binary Operator
		Fetch TWO in STACK, calc result, push result into stack
	*/
	OpEq
	OpNotEq
	OpGt
	OpGtEq
	OpLt
	OpLtEq
	OpLogicAnd
	OpLogicOr
	OpLogicBang

	/*
		Unary Operator: Fetch ONE in STACK, calc result, push result into stack
	*/
	OpReMatch
	OpGlobMatch
	OpNot

	OpCheckStackTop
)

type SyntaxFlowVirtualMachine

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

func NewSyntaxFlowVirtualMachine

func NewSyntaxFlowVirtualMachine(opts ...Option) *SyntaxFlowVirtualMachine

func (*SyntaxFlowVirtualMachine) Compile

func (s *SyntaxFlowVirtualMachine) Compile(text string) (ret error)

func (*SyntaxFlowVirtualMachine) Debug

func (*SyntaxFlowVirtualMachine) Feed

func (*SyntaxFlowVirtualMachine) ForEachFrame added in v1.3.3

func (s *SyntaxFlowVirtualMachine) ForEachFrame(h func(frame *SFFrame))

func (*SyntaxFlowVirtualMachine) Show added in v1.3.3

func (s *SyntaxFlowVirtualMachine) Show()

type SyntaxFlowVisitor

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

func NewSyntaxFlowVisitor

func NewSyntaxFlowVisitor() *SyntaxFlowVisitor

func (*SyntaxFlowVisitor) CreateFrame

func (v *SyntaxFlowVisitor) CreateFrame(vars *omap.OrderedMap[string, ValueOperator]) *SFFrame

func (*SyntaxFlowVisitor) EmitCheckStackTop

func (y *SyntaxFlowVisitor) EmitCheckStackTop()

func (*SyntaxFlowVisitor) EmitDuplicate added in v1.3.3

func (v *SyntaxFlowVisitor) EmitDuplicate()

func (*SyntaxFlowVisitor) EmitEnterStatement added in v1.3.3

func (y *SyntaxFlowVisitor) EmitEnterStatement()

func (*SyntaxFlowVisitor) EmitEqual

func (v *SyntaxFlowVisitor) EmitEqual(i any)

func (*SyntaxFlowVisitor) EmitExitStatement added in v1.3.3

func (y *SyntaxFlowVisitor) EmitExitStatement()

func (*SyntaxFlowVisitor) EmitGetBottomUsers added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetBottomUsers()

func (*SyntaxFlowVisitor) EmitGetBottomUsersWithConfig added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetBottomUsersWithConfig(config []*RecursiveConfigItem)

func (*SyntaxFlowVisitor) EmitGetCall added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetCall()

func (*SyntaxFlowVisitor) EmitGetDefs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetDefs()

func (*SyntaxFlowVisitor) EmitGetTopDef added in v1.3.3

func (y *SyntaxFlowVisitor) EmitGetTopDef()

func (*SyntaxFlowVisitor) EmitGetTopDefs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetTopDefs()

func (*SyntaxFlowVisitor) EmitGetTopDefsWithConfig added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetTopDefsWithConfig(config []*RecursiveConfigItem)

func (*SyntaxFlowVisitor) EmitGetUsers added in v1.3.3

func (v *SyntaxFlowVisitor) EmitGetUsers()

func (*SyntaxFlowVisitor) EmitListIndex added in v1.3.3

func (y *SyntaxFlowVisitor) EmitListIndex(i int)

func (*SyntaxFlowVisitor) EmitNewRef

func (y *SyntaxFlowVisitor) EmitNewRef(i string)

func (*SyntaxFlowVisitor) EmitOperator

func (y *SyntaxFlowVisitor) EmitOperator(i string)

func (*SyntaxFlowVisitor) EmitPass added in v1.3.3

func (v *SyntaxFlowVisitor) EmitPass()

func (*SyntaxFlowVisitor) EmitPop

func (y *SyntaxFlowVisitor) EmitPop()

func (*SyntaxFlowVisitor) EmitPushAllCallArgs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitPushAllCallArgs()

func (*SyntaxFlowVisitor) EmitPushCallArgs added in v1.3.3

func (v *SyntaxFlowVisitor) EmitPushCallArgs(i int)

func (*SyntaxFlowVisitor) EmitPushGlob

func (v *SyntaxFlowVisitor) EmitPushGlob(i string)

func (*SyntaxFlowVisitor) EmitPushInput added in v1.3.3

func (v *SyntaxFlowVisitor) EmitPushInput()

func (*SyntaxFlowVisitor) EmitPushLiteral

func (v *SyntaxFlowVisitor) EmitPushLiteral(i any)

func (*SyntaxFlowVisitor) EmitRegexpMatch

func (y *SyntaxFlowVisitor) EmitRegexpMatch(i string)

func (*SyntaxFlowVisitor) EmitSearchExact added in v1.3.3

func (v *SyntaxFlowVisitor) EmitSearchExact(isMember bool, i string)

func (*SyntaxFlowVisitor) EmitSearchGlob added in v1.3.3

func (v *SyntaxFlowVisitor) EmitSearchGlob(isMember bool, i string)

func (*SyntaxFlowVisitor) EmitSearchRegexp added in v1.3.3

func (v *SyntaxFlowVisitor) EmitSearchRegexp(isMember bool, i string)

func (*SyntaxFlowVisitor) EmitUpdate

func (y *SyntaxFlowVisitor) EmitUpdate(i string)

func (*SyntaxFlowVisitor) EnterFilterExpr added in v1.3.3

func (y *SyntaxFlowVisitor) EnterFilterExpr() func()

func (*SyntaxFlowVisitor) FormatStringOrGlob

func (y *SyntaxFlowVisitor) FormatStringOrGlob(text string) (string, bool)

func (*SyntaxFlowVisitor) Show

func (v *SyntaxFlowVisitor) Show()

func (*SyntaxFlowVisitor) VisitActualParam added in v1.3.3

func (y *SyntaxFlowVisitor) VisitActualParam(i sf.IActualParamContext) error

func (*SyntaxFlowVisitor) VisitChainFilter

func (y *SyntaxFlowVisitor) VisitChainFilter(raw sf.IChainFilterContext) interface{}

func (*SyntaxFlowVisitor) VisitConditionExpression

func (y *SyntaxFlowVisitor) VisitConditionExpression(raw sf.IConditionExpressionContext) interface{}

func (*SyntaxFlowVisitor) VisitFilterExpr

func (y *SyntaxFlowVisitor) VisitFilterExpr(raw sf.IFilterExprContext) error

func (*SyntaxFlowVisitor) VisitFilterStatement

func (y *SyntaxFlowVisitor) VisitFilterStatement(raw sf.IFilterStatementContext) interface{}

func (*SyntaxFlowVisitor) VisitFilters

func (y *SyntaxFlowVisitor) VisitFilters(raw sf.IFiltersContext) interface{}

func (*SyntaxFlowVisitor) VisitFlow

func (y *SyntaxFlowVisitor) VisitFlow(raw sf.IFlowContext) interface{}

func (*SyntaxFlowVisitor) VisitNameFilter added in v1.3.3

func (y *SyntaxFlowVisitor) VisitNameFilter(isMember bool, i sf.INameFilterContext) error

func (*SyntaxFlowVisitor) VisitNumberLiteral

func (y *SyntaxFlowVisitor) VisitNumberLiteral(raw sf.INumberLiteralContext) int

func (*SyntaxFlowVisitor) VisitRecursiveConfig added in v1.3.3

func (v *SyntaxFlowVisitor) VisitRecursiveConfig(i *sf.RecursiveConfigContext) []*RecursiveConfigItem

func (*SyntaxFlowVisitor) VisitRefVariable

func (y *SyntaxFlowVisitor) VisitRefVariable(raw sf.IRefVariableContext) string

func (*SyntaxFlowVisitor) VisitStringLiteral

func (y *SyntaxFlowVisitor) VisitStringLiteral(raw sf.IStringLiteralContext) (string, bool)

type ValueList added in v1.3.3

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

func (*ValueList) ExactMatch added in v1.3.3

func (v *ValueList) ExactMatch(isMember bool, s string) (bool, ValueOperator, error)

func (*ValueList) ForEach added in v1.3.3

func (v *ValueList) ForEach(h func(i any))

func (*ValueList) GetAllCallActualParams added in v1.3.3

func (v *ValueList) GetAllCallActualParams() (ValueOperator, error)

func (*ValueList) GetCallActualParams added in v1.3.3

func (v *ValueList) GetCallActualParams(i int) (ValueOperator, error)

func (*ValueList) GetCalled added in v1.3.3

func (v *ValueList) GetCalled() (ValueOperator, error)

func (*ValueList) GetSyntaxFlowBottomUse added in v1.3.3

func (v *ValueList) GetSyntaxFlowBottomUse(config ...*RecursiveConfigItem) (ValueOperator, error)

func (*ValueList) GetSyntaxFlowDef added in v1.3.3

func (v *ValueList) GetSyntaxFlowDef() (ValueOperator, error)

func (*ValueList) GetSyntaxFlowTopDef added in v1.3.3

func (v *ValueList) GetSyntaxFlowTopDef(config ...*RecursiveConfigItem) (ValueOperator, error)

func (*ValueList) GetSyntaxFlowUse added in v1.3.3

func (v *ValueList) GetSyntaxFlowUse() (ValueOperator, error)

func (*ValueList) GlobMatch added in v1.3.3

func (v *ValueList) GlobMatch(isMember bool, s Glob) (bool, ValueOperator, error)

func (*ValueList) IsList added in v1.3.3

func (v *ValueList) IsList() bool

func (*ValueList) IsMap added in v1.3.3

func (v *ValueList) IsMap() bool

func (*ValueList) ListIndex added in v1.3.3

func (v *ValueList) ListIndex(i int) (ValueOperator, error)

func (*ValueList) Recursive added in v1.3.3

func (v *ValueList) Recursive(f func(operator ValueOperator) error) error

func (*ValueList) RegexpMatch added in v1.3.3

func (v *ValueList) RegexpMatch(isMember bool, regexp *regexp.Regexp) (bool, ValueOperator, error)

func (*ValueList) String added in v1.3.3

func (v *ValueList) String() string

type ValueOperator added in v1.3.3

type ValueOperator interface {
	String() string
	IsMap() bool
	IsList() bool

	// Recursive will execute with handler for every list or map
	Recursive(func(ValueOperator) error) error

	// ExactMatch return ops, for OpPushSearchExact
	ExactMatch(bool, string) (bool, ValueOperator, error)
	// GlobMatch return opts, for OpPushSearchGlob
	GlobMatch(bool, Glob) (bool, ValueOperator, error)
	// RegexpMatch for OpPushSearchRegexp
	RegexpMatch(bool, *regexp.Regexp) (bool, ValueOperator, error)

	// GetCallActualParams for OpGetCallArgs
	GetCalled() (ValueOperator, error)
	GetCallActualParams(int) (ValueOperator, error)
	GetAllCallActualParams() (ValueOperator, error)

	// GetTopDef and GetBottomUse is for OpBottomUse
	// use and def
	GetSyntaxFlowUse() (ValueOperator, error)
	GetSyntaxFlowDef() (ValueOperator, error)
	// top and bottom
	GetSyntaxFlowTopDef(...*RecursiveConfigItem) (ValueOperator, error)
	GetSyntaxFlowBottomUse(...*RecursiveConfigItem) (ValueOperator, error)

	// ListIndex for OpListIndex, like a[1] a must be list...
	ListIndex(i int) (ValueOperator, error)
}

func AutoValue added in v1.3.3

func AutoValue(i any) ValueOperator

func MergeValues added in v1.3.3

func MergeValues(values ...ValueOperator) ValueOperator

func NewValues added in v1.3.3

func NewValues(values []ValueOperator) ValueOperator

Jump to

Keyboard shortcuts

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