ast

package
v6.5.12+incompatible Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: Apache-2.0 Imports: 8 Imported by: 30

README

abstract syntax tree(AST) ,即抽象语法树,一个二叉树

主要工作内容:解析xml包含的所有节点,抽象为语法树

Documentation

Index

Constants

View Source
const DefaultOverrides = ","
View Source
const DefaultWhereElement_Prefix = "where"
View Source
const DefaultWhereElement_PrefixOverrides = "and |or |And |Or |AND |OR "

Variables

This section is empty.

Functions

func DoChildNodes

func DoChildNodes(childNodes []Node, env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

执行子所有节点

func FindExpress

func FindExpress(str string) []string

find like #{*} value *

func FindRawExpressString

func FindRawExpressString(str string) []string

find like ${*} value *

func Replace

func Replace(findStrs []string, data string, arg map[string]interface{}, engine ExpressionEngine, arg_array *[]interface{}, indexConvert stmt.StmtIndexConvert) (string, error)

执行替换操作

func ReplaceRaw

func ReplaceRaw(findStrs []string, data string, typeConvert SqlArgTypeConvert, arg map[string]interface{}, engine ExpressionEngine) (string, error)

执行替换操作

Types

type ExpressionEngine

type ExpressionEngine interface {
	//引擎名称
	Name() string
	//编译一个表达式
	//参数:lexerArg 表达式内容
	//返回:interface{} 编译结果,error 错误
	Lexer(lexerArg string) (interface{}, error)

	//执行一个表达式
	//参数:lexerResult=编译结果,arg=参数
	//返回:执行结果,错误
	Eval(lexerResult interface{}, arg interface{}, operation int) (interface{}, error)

	LexerAndEval(lexerArg string, arg interface{}) (interface{}, error)
}

q:为什么要拆分表达式编译和执行步骤?优化性能,如果需要可以缓存表达式编译结果,执行表达式时不需要重复编译 表达式引擎接口

type Node

type Node interface {
	Type() NodeType
	Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)
}

sql构建抽象语法树节点

type NodeBind

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

func (*NodeBind) Eval

func (it *NodeBind) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeBind) Type

func (it *NodeBind) Type() NodeType

type NodeChoose

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

func (*NodeChoose) Eval

func (it *NodeChoose) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeChoose) Type

func (it *NodeChoose) Type() NodeType

type NodeConfigHolder

type NodeConfigHolder struct {
	Proxy ExpressionEngine
}

func (*NodeConfigHolder) GetExpressionEngineProxy

func (it *NodeConfigHolder) GetExpressionEngineProxy() ExpressionEngine

type NodeForEach

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

foreach 节点

func (*NodeForEach) Eval

func (it *NodeForEach) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeForEach) Type

func (it *NodeForEach) Type() NodeType

type NodeIf

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

判断节点

func (*NodeIf) Eval

func (it *NodeIf) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeIf) Type

func (it *NodeIf) Type() NodeType

type NodeInclude

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

func (*NodeInclude) Eval

func (it *NodeInclude) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeInclude) Type

func (it *NodeInclude) Type() NodeType

type NodeOtherwise

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

func (*NodeOtherwise) Eval

func (it *NodeOtherwise) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeOtherwise) Type

func (it *NodeOtherwise) Type() NodeType

type NodeParser

type NodeParser struct {
	Holder NodeConfigHolder
}

节点解析器

func (NodeParser) Parser

func (it NodeParser) Parser(mapperXml []etree.Token) []Node

解析为node

type NodeString

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

字符串节点

func (*NodeString) Eval

func (it *NodeString) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeString) Type

func (it *NodeString) Type() NodeType

type NodeTrim

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

Trim操作节点

func (*NodeTrim) Eval

func (it *NodeTrim) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeTrim) Type

func (it *NodeTrim) Type() NodeType

type NodeType

type NodeType int
const (
	NArg    NodeType = iota
	NString          //string 节点
	NIf
	NTrim
	NForEach
	NChoose
	NOtherwise
	NWhen
	NBind
	NInclude
	NWhere
)

func (NodeType) ToString

func (it NodeType) ToString() string

type NodeWhen

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

func (*NodeWhen) Eval

func (it *NodeWhen) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeWhen) Type

func (it *NodeWhen) Type() NodeType

type NodeWhere

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

Trim操作节点

func (*NodeWhere) Eval

func (it *NodeWhere) Eval(env map[string]interface{}, arg_array *[]interface{}, stmtConvert stmt.StmtIndexConvert) ([]byte, error)

func (*NodeWhere) Type

func (it *NodeWhere) Type() NodeType

type SqlArgTypeConvert

type SqlArgTypeConvert interface {
	Convert(arg interface{}) string
}

表达式类型(基本类型)转换函数

Jump to

Keyboard shortcuts

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