ast

package
v5.1.5+incompatible Latest Latest
Warning

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

Go to latest
Published: May 27, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

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{}) ([]byte, error)

执行子所有节点

func FindAllExpressConvertString

func FindAllExpressConvertString(str string) []string

find like #{*} value *

func FindAllExpressString

func FindAllExpressString(str string) []string

find like ${*} value *

func Replace

func Replace(startChar string, 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{}) ([]byte, error)
}

sql构建抽象语法树节点

type NodeBind

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

func (*NodeBind) Eval

func (it *NodeBind) Eval(env map[string]interface{}) ([]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{}) ([]byte, error)

func (*NodeChoose) Type

func (it *NodeChoose) Type() NodeType

type NodeConfigHolder

type NodeConfigHolder struct {
	Convert SqlArgTypeConvert
	Proxy   ExpressionEngine
}

func (*NodeConfigHolder) GetExpressionEngineProxy

func (it *NodeConfigHolder) GetExpressionEngineProxy() ExpressionEngine

func (*NodeConfigHolder) GetSqlArgTypeConvert

func (it *NodeConfigHolder) GetSqlArgTypeConvert() SqlArgTypeConvert

type NodeForEach

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

foreach 节点

func (*NodeForEach) Eval

func (it *NodeForEach) Eval(env map[string]interface{}) ([]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{}) ([]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{}) ([]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{}) ([]byte, error)

func (*NodeOtherwise) Type

func (it *NodeOtherwise) Type() NodeType

type NodeParser

type NodeParser struct {
	Holder NodeConfigHolder
}

节点解析器

func (NodeParser) ParserNodes

func (it NodeParser) ParserNodes(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{}) ([]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{}) ([]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
)

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{}) ([]byte, error)

func (*NodeWhen) Type

func (it *NodeWhen) 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