base

package
v1.6.7 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: BSD-3-Clause Imports: 11 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",
	"decimal.Decimal": "decimal.Decimal",
}

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

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

type BreakStmt struct {
}

func (*BreakStmt) Evaluate

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

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

type ContinueStmt struct {
}

func (*ContinueStmt) Evaluate

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

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

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

forRane循环语法 forRange key=mapInfo{}

func (*ForRangeStmt) AcceptStatements

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

func (*ForRangeStmt) AcceptVariable

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

func (*ForRangeStmt) Evaluate

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

type ForStmt

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

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

func (*ForStmt) AcceptAssignment

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

func (*ForStmt) AcceptExpression

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

func (*ForStmt) AcceptStatements

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

func (*ForStmt) Evaluate

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

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

type ThreeLevelCall struct {
	SourceCode
	ThreeLevel string
	MethodArgs *Args
}

func (*ThreeLevelCall) AcceptArgs

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

func (*ThreeLevelCall) Evaluate

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

type ThreeLevelCallHolder

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