Help us shape the future of Go! Take the 2026 Go Developer Survey

base

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BREAKFLAG = errors.New("break")
View Source
var CONTINUEFLAG = errors.New("break")
View Source
var TypeMap = map[string]string{
	"int":     "int",
	"int8":    "int8",
	"int16":   "int16",
	"int32":   "int32",
	"int64":   "int64",
	"uint":    "uint",
	"uint8":   "uint8",
	"uint16":  "uint16",
	"uint32":  "uint32",
	"uint64":  "uint64",
	"float32": "float32",
	"float64": "float64",
}

Functions

This section is empty.

Types

type Arg

type Arg struct {
	Constant       *Constant
	Variable       string
	FunctionCall   *FunctionCall
	MethodCall     *MethodCall
	ThreeLevelCall *ThreeLevelCall
	MapVar         *MapVar
	Expression     *Expression
}

func (*Arg) Evaluate

func (a *Arg) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type Args

type Args struct {
	ArgList []*Arg
}

func (*Args) AcceptConstant

func (as *Args) AcceptConstant(cons *Constant) error

func (*Args) AcceptExpression

func (as *Args) AcceptExpression(exp *Expression) error

func (*Args) AcceptFunctionCall

func (as *Args) AcceptFunctionCall(funcCall *FunctionCall) error

func (*Args) AcceptMapVar

func (as *Args) AcceptMapVar(mapVar *MapVar) error

func (*Args) AcceptMethodCall

func (as *Args) AcceptMethodCall(methodCall *MethodCall) error

func (*Args) AcceptThreeLevelCall added in v1.5.2

func (as *Args) AcceptThreeLevelCall(threeLevelCall *ThreeLevelCall) error

func (*Args) AcceptVariable

func (as *Args) AcceptVariable(name string) error

func (*Args) Evaluate

func (as *Args) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) ([]reflect.Value, error)

type ArgsHolder

type ArgsHolder interface {
	AcceptArgs(funcArg *Args) error
}

type Assignment

type Assignment struct {
	SourceCode
	Variable       string
	MapVar         *MapVar
	AssignOperator string
	MathExpression *MathExpression
	Expression     *Expression
}

:= or =

func (*Assignment) AcceptExpression

func (a *Assignment) AcceptExpression(exp *Expression) error

func (*Assignment) AcceptMapVar

func (a *Assignment) AcceptMapVar(mapVar *MapVar) error

func (*Assignment) AcceptMathExpression

func (a *Assignment) AcceptMathExpression(me *MathExpression) error

func (*Assignment) AcceptVariable

func (a *Assignment) AcceptVariable(name string) error

func (*Assignment) Evaluate

func (a *Assignment) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (value reflect.Value, err error)

type AssignmentHolder

type AssignmentHolder interface {
	AcceptAssignment(a *Assignment) error
}

type AtDescHolder

type AtDescHolder interface {
	AcceptDesc(val string) error
}

type AtIdHolder

type AtIdHolder interface {
	AcceptId(val int64) error
}

type AtNameHolder

type AtNameHolder interface {
	AcceptName(val string) error
}

type AtSalienceHolder

type AtSalienceHolder interface {
	AcceptSalience(val int64) error
}

type BreakStmt added in v1.5.7

type BreakStmt struct {
}

func (*BreakStmt) Evaluate added in v1.5.7

func (forStmt *BreakStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type ConcStatement

type ConcStatement struct {
	Assignments     []*Assignment
	FunctionCalls   []*FunctionCall
	MethodCalls     []*MethodCall
	ThreeLevelCalls []*ThreeLevelCall
}

func (*ConcStatement) AcceptAssignment

func (cs *ConcStatement) AcceptAssignment(assignment *Assignment) error

func (*ConcStatement) AcceptFunctionCall

func (cs *ConcStatement) AcceptFunctionCall(funcCall *FunctionCall) error

func (*ConcStatement) AcceptMethodCall

func (cs *ConcStatement) AcceptMethodCall(methodCall *MethodCall) error

func (*ConcStatement) AcceptThreeLevelCall added in v1.5.2

func (cs *ConcStatement) AcceptThreeLevelCall(threeLevelCall *ThreeLevelCall) error

func (*ConcStatement) Evaluate

func (cs *ConcStatement) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type Constant

type Constant struct {
	ConstantValue reflect.Value
}

func (*Constant) AcceptDesc

func (cons *Constant) AcceptDesc(desc string) error

receive rule's description

func (*Constant) AcceptId

func (cons *Constant) AcceptId(id int64) error

func (*Constant) AcceptInteger

func (cons *Constant) AcceptInteger(i64 int64) error

func (*Constant) AcceptName

func (cons *Constant) AcceptName(name string) error

receive rule's name

func (*Constant) AcceptSalience

func (cons *Constant) AcceptSalience(sal int64) error

func (*Constant) AcceptString

func (cons *Constant) AcceptString(str string) error

func (*Constant) Evaluate

func (cons *Constant) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type ConstantHolder

type ConstantHolder interface {
	AcceptConstant(cons *Constant) error
}

type ContinueStmt added in v1.5.7

type ContinueStmt struct {
}

func (*ContinueStmt) Evaluate added in v1.5.7

func (continueStmt *ContinueStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type ElseIfStmt

type ElseIfStmt struct {
	Expression    *Expression
	StatementList *Statements
}

func (*ElseIfStmt) AcceptExpression

func (ef *ElseIfStmt) AcceptExpression(expr *Expression) error

func (*ElseIfStmt) AcceptStatements

func (ef *ElseIfStmt) AcceptStatements(stmts *Statements) error

func (*ElseIfStmt) Evaluate

func (ef *ElseIfStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type ElseStmt

type ElseStmt struct {
	StatementList *Statements
}

func (*ElseStmt) AcceptStatements

func (e *ElseStmt) AcceptStatements(stmts *Statements) error

func (*ElseStmt) Evaluate

func (e *ElseStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type Expression

type Expression struct {
	SourceCode
	ExpressionLeft     *Expression
	ExpressionRight    *Expression
	ExpressionAtom     *ExpressionAtom
	MathExpression     *MathExpression
	LogicalOperator    string
	ComparisonOperator string
	NotOperator        string
}

func (*Expression) AcceptExpression

func (e *Expression) AcceptExpression(expression *Expression) error

func (*Expression) AcceptExpressionAtom

func (e *Expression) AcceptExpressionAtom(atom *ExpressionAtom) error

func (*Expression) AcceptMathExpression

func (e *Expression) AcceptMathExpression(atom *MathExpression) error

func (*Expression) Evaluate

func (e *Expression) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type ExpressionAtom

type ExpressionAtom struct {
	SourceCode
	Variable       string
	Constant       *Constant
	FunctionCall   *FunctionCall
	MethodCall     *MethodCall
	ThreeLevelCall *ThreeLevelCall
	MapVar         *MapVar
}

func (*ExpressionAtom) AcceptConstant

func (e *ExpressionAtom) AcceptConstant(cons *Constant) error

func (*ExpressionAtom) AcceptFunctionCall

func (e *ExpressionAtom) AcceptFunctionCall(funcCall *FunctionCall) error

func (*ExpressionAtom) AcceptMapVar

func (e *ExpressionAtom) AcceptMapVar(mapVar *MapVar) error

func (*ExpressionAtom) AcceptMethodCall

func (e *ExpressionAtom) AcceptMethodCall(methodCall *MethodCall) error

func (*ExpressionAtom) AcceptThreeLevelCall added in v1.5.2

func (e *ExpressionAtom) AcceptThreeLevelCall(threeLevelCall *ThreeLevelCall) error

func (*ExpressionAtom) AcceptVariable

func (e *ExpressionAtom) AcceptVariable(name string) error

func (*ExpressionAtom) Evaluate

func (e *ExpressionAtom) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type ExpressionAtomHolder

type ExpressionAtomHolder interface {
	AcceptExpressionAtom(atom *ExpressionAtom) error
}

type ExpressionHolder

type ExpressionHolder interface {
	AcceptExpression(expression *Expression) error
}

type ForRangeStmt added in v1.5.7

type ForRangeStmt struct {
	SourceCode
	StatementList *Statements
	// contains filtered or unexported fields
}

forRane循环语法 forRange key=mapInfo{}

func (*ForRangeStmt) AcceptStatements added in v1.5.7

func (forRangeStmt *ForRangeStmt) AcceptStatements(stmts *Statements) error

func (*ForRangeStmt) AcceptVariable added in v1.5.7

func (forRangeStmt *ForRangeStmt) AcceptVariable(name string) error

func (*ForRangeStmt) Evaluate added in v1.5.7

func (forRangeStmt *ForRangeStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type ForStmt added in v1.5.7

type ForStmt struct {
	SourceCode
	Expression    *Expression   // 表达式
	StatementList *Statements   // 执行语句列表
	Assignments   []*Assignment // 赋值语句
}

for循环语法 for i=0;i<100;i+=1

func (*ForStmt) AcceptAssignment added in v1.5.7

func (forStmt *ForStmt) AcceptAssignment(assignment *Assignment) error

func (*ForStmt) AcceptExpression added in v1.5.7

func (forStmt *ForStmt) AcceptExpression(expr *Expression) error

func (*ForStmt) AcceptStatements added in v1.5.7

func (forStmt *ForStmt) AcceptStatements(stmts *Statements) error

func (*ForStmt) Evaluate added in v1.5.7

func (forStmt *ForStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type FunctionCall

type FunctionCall struct {
	SourceCode
	FunctionName string
	FunctionArgs *Args
}

func (*FunctionCall) AcceptArgs

func (fc *FunctionCall) AcceptArgs(funcArg *Args) error

func (*FunctionCall) Evaluate

func (fc *FunctionCall) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (res reflect.Value, err error)

type FunctionCallHolder

type FunctionCallHolder interface {
	AcceptFunctionCall(funcCall *FunctionCall) error
}

type IfStmt

type IfStmt struct {
	Expression     *Expression
	StatementList  *Statements
	ElseIfStmtList []*ElseIfStmt
	ElseStmt       *ElseStmt
}

func (*IfStmt) AcceptExpression

func (i *IfStmt) AcceptExpression(expr *Expression) error

func (*IfStmt) AcceptStatements

func (i *IfStmt) AcceptStatements(stmts *Statements) error

func (*IfStmt) Evaluate

func (i *IfStmt) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type IntegerHolder

type IntegerHolder interface {
	AcceptInteger(val int64) error
}

type KnowledgeContext

type KnowledgeContext struct {
	// ruleName - RuleEntity
	RuleEntities      map[string]*RuleEntity
	SortRules         []*RuleEntity
	SortRulesIndexMap map[string]int
}

func NewKnowledgeContext

func NewKnowledgeContext() *KnowledgeContext

func (*KnowledgeContext) ClearRules

func (k *KnowledgeContext) ClearRules()

type MapVar

type MapVar struct {
	SourceCode
	Name   string // map name
	Intkey int64  // array index
	Strkey string // map key
	Varkey string // array index or map key
}

support map or array

func (*MapVar) AcceptInteger

func (m *MapVar) AcceptInteger(i64 int64) error

func (*MapVar) AcceptString

func (m *MapVar) AcceptString(str string) error

func (*MapVar) AcceptVariable

func (m *MapVar) AcceptVariable(name string) error

func (*MapVar) Evaluate

func (m *MapVar) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type MapVarHolder

type MapVarHolder interface {
	AcceptMapVar(mv *MapVar) error
}

type MathExpression

type MathExpression struct {
	SourceCode
	MathExpressionLeft  *MathExpression
	MathPmOperator      string
	MathMdOperator      string
	MathExpressionRight *MathExpression
	ExpressionAtom      *ExpressionAtom
}

func (*MathExpression) AcceptExpressionAtom

func (e *MathExpression) AcceptExpressionAtom(atom *ExpressionAtom) error

func (*MathExpression) AcceptMathExpression

func (e *MathExpression) AcceptMathExpression(atom *MathExpression) error

func (*MathExpression) Evaluate

func (e *MathExpression) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error)

type MathExpressionHolder

type MathExpressionHolder interface {
	AcceptMathExpression(mh *MathExpression) error
}

type MethodCall

type MethodCall struct {
	SourceCode
	MethodName string
	MethodArgs *Args
}

func (*MethodCall) AcceptArgs

func (mc *MethodCall) AcceptArgs(funcArg *Args) error

func (*MethodCall) Evaluate

func (mc *MethodCall) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (mr reflect.Value, err error)

type MethodCallHolder

type MethodCallHolder interface {
	AcceptMethodCall(methodCall *MethodCall) error
}

type ReturnStatement

type ReturnStatement struct {
	Expression *Expression
}

func (*ReturnStatement) AcceptExpression

func (rs *ReturnStatement) AcceptExpression(expr *Expression) error

func (*ReturnStatement) Evaluate

func (rs *ReturnStatement) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type RuleContent

type RuleContent struct {
	Statements *Statements
}

func (*RuleContent) AcceptStatements

func (t *RuleContent) AcceptStatements(stmts *Statements) error

func (*RuleContent) Execute

func (t *RuleContent) Execute(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type RuleEntity

type RuleEntity struct {
	RuleName        string
	Salience        int64
	RuleDescription string
	RuleContent     *RuleContent
}

func (*RuleEntity) AcceptInteger

func (r *RuleEntity) AcceptInteger(val int64) error

func (*RuleEntity) AcceptString

func (r *RuleEntity) AcceptString(s string) error

func (*RuleEntity) Execute

func (r *RuleEntity) Execute(dc *context.DataContext) (interface{}, error, bool)

type SourceCode

type SourceCode struct {
	Code     string //raw code            -> ctx.GetText()
	LineNum  int    //line number         -> ctx.GetStart().GetLine()
	Column   int    //line start location -> ctx.GetStart().GetColumn()
	LineStop int    //line end location   -> ctx.GetStop().GetColumn()
}

type Statement

type Statement struct {
	IfStmt         *IfStmt
	MethodCall     *MethodCall
	FunctionCall   *FunctionCall
	ThreeLevelCall *ThreeLevelCall
	Assignment     *Assignment
	ConcStatement  *ConcStatement
	ForStmt        *ForStmt      // for语句
	BreakStmt      *BreakStmt    // break语句
	ForRangeStmt   *ForRangeStmt // forRange语句
	ContinueStmt   *ContinueStmt // continue语句
}

func (*Statement) AcceptAssignment

func (s *Statement) AcceptAssignment(assignment *Assignment) error

func (*Statement) AcceptFunctionCall

func (s *Statement) AcceptFunctionCall(funcCall *FunctionCall) error

func (*Statement) AcceptMethodCall

func (s *Statement) AcceptMethodCall(methodCall *MethodCall) error

func (*Statement) AcceptThreeLevelCall added in v1.5.2

func (s *Statement) AcceptThreeLevelCall(threeLevelCall *ThreeLevelCall) error

func (*Statement) Evaluate

func (s *Statement) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type Statements

type Statements struct {
	StatementList   []*Statement
	ReturnStatement *ReturnStatement
}

func (*Statements) Evaluate

func (s *Statements) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (reflect.Value, error, bool)

type StatementsHolder

type StatementsHolder interface {
	AcceptStatements(statement *Statements) error
}

type StringHolder

type StringHolder interface {
	AcceptString(str string) error
}

type ThreeLevelCall added in v1.5.2

type ThreeLevelCall struct {
	SourceCode
	ThreeLevel string
	MethodArgs *Args
}

func (*ThreeLevelCall) AcceptArgs added in v1.5.2

func (tlc *ThreeLevelCall) AcceptArgs(funcArg *Args) error

func (*ThreeLevelCall) Evaluate added in v1.5.2

func (tlc *ThreeLevelCall) Evaluate(dc *context.DataContext, Vars map[string]reflect.Value) (mr reflect.Value, err error)

type ThreeLevelCallHolder added in v1.5.2

type ThreeLevelCallHolder interface {
	AcceptThreeLevelCall(threeLevelCall *ThreeLevelCall) error
}

type VariableHolder

type VariableHolder interface {
	AcceptVariable(name string) error
}

Jump to

Keyboard shortcuts

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