parser

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RangeKeys = []Key{
		In,
		NotIn,
	}
	NumericKeys = []Key{
		Const,
		LessThan,
		LessEqual,
		GreatThan,
		GreatEqual,
		In,
		NotIn,
		NotNil,
	}
	BinaryKeys = []Key{
		Const,
		MinSize,
		MaxSize,
		Pattern,
		Prefix,
		Suffix,
		Contains,
		NotContains,
		In,
		NotIn,
		NotNil,
	}
	BoolKeys = []Key{
		Const,
		NotNil,
	}
	EnumKeys = []Key{
		Const,
		DefinedOnly,
		NotNil,
	}
	ListKeys = []Key{
		MinSize,
		MaxSize,
		Elem,
	}
	MapKeys = []Key{
		MinSize,
		MaxSize,
		NoSparse,
		MapKey,
		MapValue,
	}
	StructLikeFieldKeys = []Key{
		Skip,
		NotNil,
	}
	StructLikeKeys = []Key{
		Assert,
	}
)
View Source
var KeyString = [...]string{
	Const:       "const",
	LessThan:    "lt",
	LessEqual:   "le",
	GreatThan:   "gt",
	GreatEqual:  "ge",
	In:          "in",
	NotIn:       "not_in",
	NotNil:      "not_nil",
	MinSize:     "min_size",
	MaxSize:     "max_size",
	Pattern:     "pattern",
	Prefix:      "prefix",
	Suffix:      "suffix",
	Contains:    "contains",
	NotContains: "not_contains",
	DefinedOnly: "defined_only",
	Elem:        "elem",
	MapKey:      "key",
	MapValue:    "value",
	NoSparse:    "no_sparse",
	Skip:        "skip",
	Assert:      "assert",
}
View Source
var ValueTypeName = [...]string{
	FieldReferenceValue: "field-reference-value",
	DoubleValue:         "double-value",
	IntValue:            "int-value",
	BoolValue:           "bool-value",
	EnumValue:           "enum-value",
	BinaryValue:         "binary-value",
	FunctionValue:       "function-value",
}

Functions

func Pretty

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

func Size

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

Types

type Annotation

type Annotation struct {
	Key    string
	Values []string
}

func NewAnnotation

func NewAnnotation() *Annotation

func RulesToAnnotations

func RulesToAnnotations(fieldRules *api.FieldRules) ([]*Annotation, error)

RulesToAnnotations convert the rule struct to []*Annotation

func (*Annotation) GetKey

func (p *Annotation) GetKey() string

func (*Annotation) GetValues

func (p *Annotation) GetValues() []string

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) SprintSyntaxTree

func (p *Function) SprintSyntaxTree() string

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 Key

type Key int
const (
	Const Key = iota
	LessThan
	LessEqual
	GreatThan
	GreatEqual
	In
	NotIn
	NotNil
	MinSize
	MaxSize
	Pattern
	Prefix
	Suffix
	Contains
	NotContains
	DefinedOnly
	Elem
	MapKey
	MapValue
	NoSparse
	Skip
	Assert
)

func KeyFromString

func KeyFromString(str string) (Key, bool)

func PickRangeKeys

func PickRangeKeys(keys []Key) (ret []Key)

func PickSpecifiedKeys

func PickSpecifiedKeys(keys []Key) (ret []Key)

func (Key) String

func (k Key) String() (string, bool)

type Parser

type Parser struct{}

func NewParser

func NewParser() *Parser

func (*Parser) Parse

type Rule

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

type RuleFactory

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

func NewRuleFactory

func NewRuleFactory(keys []Key) *RuleFactory

func (*RuleFactory) NewRule

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

type ToolFunction

type ToolFunction struct {
	Name      string
	Arguments []ValidationValue
}

type TypedValidationValue

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

func (*TypedValidationValue) GetFieldReferenceName

func (t *TypedValidationValue) GetFieldReferenceName(ref string) string

type Validation

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

type ValidationType

type ValidationType int
const (
	NumericValidation ValidationType = iota
	BinaryValidation
	BoolValidation
	EnumValidation
	ListValidation
	MapValidation
	StructLikeFieldValidation
	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
)

func (ValueType) String

func (vt ValueType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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