token

package
v1.14.10 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyEncoder  emptyEncoder
	StringEncoder stringEncoder
	NumberEncoder numberEncoder
	BoolEncoder   boolEncoder
)
View Source
var (
	REG_LBT       = regexp.MustCompile(`^([(\[{])`)
	REG_RBT       = regexp.MustCompile(`^([)\]}])`)
	REG_OPERATOR  = regexp.MustCompile(`^(&&|\|\|)`)
	REG_CONDITION = regexp.MustCompile(`^(?:(==|!=|>=|<=|>|<|containsBit|unContainsBit|contains|unContains|startsWith|unStartsWith|endsWith|unEndsWith|reg|notIn|in|isNot|is)\s*)`)
	REG_IDENT     = regexp.MustCompile(`^([a-zA-Z_][\w\\.\-]*)`)
	REG_NUM       = regexp.MustCompile(`^((?:\+|-)?\d+(?:\.\d+)?)`)
	REG_BOOL      = regexp.MustCompile(`^(true|false)`)
	REG_STRING    = regexp.MustCompile(`^(?:'(.*?)'|"(.*?)")`)
	REG_DELIM     = regexp.MustCompile(`^(\s*)`)
	REG_ILLEGAL   = regexp.MustCompile(`^(.+)`)
)

token 的正则表达式

View Source
var (
	DelimParser = Parser{Reg: REG_DELIM, Token: DELIM, Encodable: EmptyEncoder}
)

token 解析器

View Source
var ParserMap = map[Token]Parser{
	LBT:       lbtParser,
	RBT:       rbtParser,
	OPERATOR:  operatorParser,
	CONDITION: conditionParser,
	IDENT:     identParser,
	NUM:       numParser,
	BOOL:      boolParser,
	STRING:    stringParser,
	DELIM:     DelimParser,
	ILLEGAL:   illegalParser,
}

ParserMap token 解析器映射

View Source
var ParserPriority = []Parser{
	conditionParser,
	operatorParser,
	numParser,
	boolParser,
	stringParser,
	identParser,
	lbtParser,
	rbtParser,
	illegalParser,
}

ParserPriority token 解析器优先级

StateMatrix 状态转移矩阵

Functions

This section is empty.

Types

type Encodable

type Encodable interface {
	Encode(any) string
	Decode(string) any
}

type Parser

type Parser struct {
	Reg   *regexp.Regexp
	Token Token
	Encodable
}

Parser token 解析器

包含词法分析正则
包含 Token 标识
包含编码、解码器

type Token

type Token string
const (
	LITERAL_BEGIN Token = "literal_begin"
	LITERAL_END   Token = "literal_end"

	LBT       Token = "lbt"       // 左括号
	RBT       Token = "rbt"       // 有括号
	OPERATOR  Token = "operator"  // 逻辑关系
	CONDITION Token = "condition" // 条件
	IDENT     Token = "ident"     // 变量
	NUM       Token = "num"       // 数字
	BOOL      Token = "bool"      // bool
	STRING    Token = "string"    // 字符串
	DELIM     Token = "delim"     // 空字符
	ILLEGAL   Token = "illegal"   // 无法解析
)

token

Jump to

Keyboard shortcuts

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