lexer

package
v0.0.0-...-16f1978 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const InCheckerName = "in"

InCheckerName 包含验证器

View Source
const InValueDelimiter = ","

InValueDelimiter in值分割字符

View Source
const LenCheckerName = "len"

LenCheckerName 长度验证器token

View Source
const NotEmptyCheckerName = "notEmpty"

NotEmptyCheckerName 验证不为空的方法token

View Source
const ValueCheckerName = "value"

ValueCheckerName 值验证方法名token

Variables

This section is empty.

Functions

func CompToSymbol

func CompToSymbol(s string) string

CompToSymbol 根据定义的比较运算符字符串 获取 比较运算发symbol

func SetCheckMethods

func SetCheckMethods(method string, factory func(*Checker) (IValidator, error))

SetCheckMethods 注册验证器到方法池

Types

type AbstractValidator

type AbstractValidator struct {
	Checker *Checker
	Indent  string
	Rt      string
}

AbstractValidator 验证器抽象类

func (*AbstractValidator) GetReturn

func (vr *AbstractValidator) GetReturn(msg string) string

GetReturn 返回return字符串

func (*AbstractValidator) SetIndent

func (vr *AbstractValidator) SetIndent(s string)

SetIndent 设置缩进

func (*AbstractValidator) SetReturn

func (vr *AbstractValidator) SetReturn(s string)

SetReturn 设置换行符

type Checker

type Checker struct {
	Exp    *express
	Method string
	Comp   string
	Value  string
}

Checker 每个字段表达式单元有多个checker

type IValidator

type IValidator interface {
	GenCode() string
	SetReturn(s string)
	SetIndent(s string)
}

IValidator 验证器接口

func NewInValidator

func NewInValidator(checker *Checker) (IValidator, error)

NewInValidator 返回存在验证器

func NewLenValidator

func NewLenValidator(checker *Checker) (IValidator, error)

NewLenValidator 返回长度验证器

func NewNotEmptyValidator

func NewNotEmptyValidator(checker *Checker) (IValidator, error)

NewNotEmptyValidator 构造新的非空验证器

func NewValueValidator

func NewValueValidator(checker *Checker) (IValidator, error)

NewValueValidator 返回值验证器

type Lexer

type Lexer struct {
	PointerAlias string
	// contains filtered or unexported fields
}

Lexer 字段tag分析器

func NewLexer

func NewLexer(msg, deli, pointer string, field *types.Var) *Lexer

NewLexer 获取一个表达式分词器

func (*Lexer) GetUsedImports

func (l *Lexer) GetUsedImports() []*packages.Package

GetUsedImports 返回生成文件中使用过的package

func (*Lexer) GetValidatorList

func (l *Lexer) GetValidatorList() ([]IValidator, error)

GetValidatorList 获取字段的验证器列表

func (*Lexer) Parse

func (l *Lexer) Parse() error

Parse 分析tag 先拆解表达式 拆解为多个验证器 后拆解验证器,拆解为多个验证方法 最后组合

func (*Lexer) SetImports

func (l *Lexer) SetImports(imt []*packages.Package)

SetImports 设置解析后的依赖

Jump to

Keyboard shortcuts

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