parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NotNil = "not_nil"
)

Variables

View Source
var (
	NumericAnnotation = struct {
		Const      string
		LessThan   string
		LessEqual  string
		GreatThan  string
		GreatEqual string
		In         string
		NotIn      string
		NotNil     string
	}{
		Const:      "const",
		LessThan:   "lt",
		LessEqual:  "le",
		GreatThan:  "gt",
		GreatEqual: "ge",
		In:         "in",
		NotIn:      "not_in",
		NotNil:     NotNil,
	}
	BinaryAnnotation = struct {
		Const       string
		MinLen      string
		MaxLen      string
		Pattern     string
		Prefix      string
		Suffix      string
		Contains    string
		NotContains string
		In          string
		NotIn       string
		NotNil      string
	}{
		Const:       "const",
		MinLen:      "min_size",
		MaxLen:      "max_size",
		Pattern:     "pattern",
		Prefix:      "prefix",
		Suffix:      "suffix",
		Contains:    "contains",
		NotContains: "not_contains",
		In:          "in",
		NotIn:       "not_in",
		NotNil:      NotNil,
	}
	BoolAnnotation = struct {
		Const  string
		NotNil string
	}{
		Const:  "const",
		NotNil: NotNil,
	}
	EnumAnnotation = struct {
		Const       string
		DefinedOnly string
		NotNil      string
	}{
		Const:       "const",
		DefinedOnly: "defined_only",
		NotNil:      NotNil,
	}
	ListAnnotation = struct {
		MinLen string
		MaxLen string
		Elem   string
	}{
		MinLen: "min_size",
		MaxLen: "max_size",
		Elem:   "elem",
	}
	MapAnnotation = struct {
		MinPairs string
		MaxPairs string
		NoSparse string
		Key      string
		Value    string
	}{
		MinPairs: "min_size",
		MaxPairs: "max_size",
		NoSparse: "no_sparse",
		Key:      "key",
		Value:    "value",
	}
	StructLikeAnnotation = struct {
		Skip   string
		NotNil string
	}{
		Skip:   "skip",
		NotNil: NotNil,
	}
)

Functions

func Pretty

func Pretty(pretty bool) func(*Function) error

func Size

func Size(size int) func(*Function) error

Types

type Function

type Function struct {
	Buffer string

	Pretty bool
	// contains filtered or unexported fields
}

func (*Function) AST

func (t *Function) AST() *node32

func (*Function) Add

func (t *Function) Add(rule pegRule, begin, end, index uint32)

func (*Function) Init

func (p *Function) Init(options ...func(*Function) error) error

func (*Function) Parse

func (p *Function) Parse(rule ...int) error

func (*Function) PrettyPrintSyntaxTree

func (t *Function) PrettyPrintSyntaxTree(buffer string)

func (*Function) Print

func (t *Function) Print()

func (*Function) PrintSyntaxTree

func (p *Function) PrintSyntaxTree()

func (*Function) Reset

func (p *Function) Reset()

func (*Function) Tokens

func (t *Function) Tokens() []token32

func (*Function) Trim

func (t *Function) Trim(length uint32)

func (*Function) WriteSyntaxTree

func (p *Function) WriteSyntaxTree(w io.Writer)

type Parser

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

func NewParser

func NewParser(cu *golang.CodeUtils) *Parser

func (*Parser) Parse

func (p *Parser) Parse(st *tp.StructLike) (map[*tp.Field]*Validation, error)

type Rule

type Rule struct {
	Annotation string
	Specified  *ValidationValue
	Range      []*ValidationValue
	Inner      *Validation
}

type RuleFactory

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

func NewRuleFactory

func NewRuleFactory(specifiedKeys, rangeKeys []string) *RuleFactory

func (*RuleFactory) NewRule

func (v *RuleFactory) NewRule(key string, value *ValidationValue) (bool, *Rule)

type ToolFunction

type ToolFunction struct {
	Name      string
	Arguments []ValidationValue
}

type TypedValidationValue

type TypedValidationValue struct {
	FieldReference *tp.Field
	Double         float64
	Int            int64
	Bool           bool
	Enum           *tp.EnumValue
	Binary         string
	Function       *ToolFunction
}

type Validation

type Validation struct {
	ValidationType ValidationType
	Rules          []*Rule
}

type ValidationType

type ValidationType int
const (
	NumericValidation ValidationType = iota
	BinaryValidation
	BoolValidation
	EnumValidation
	ListValidation
	MapValidation
	StructLikeValidation
)

type ValidationValue

type ValidationValue struct {
	ValueType  ValueType
	TypedValue TypedValidationValue
}

type ValueType

type ValueType int
const (
	FieldReferenceValue ValueType = iota
	DoubleValue
	IntValue
	BoolValue
	EnumValue
	BinaryValue
	FunctionValue
)

Jump to

Keyboard shortcuts

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