parser

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: Apache-2.0 Imports: 9 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,
		In,
		NotIn,
	}
	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 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 added in v0.1.4

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 added in v0.1.4

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 added in v0.1.4

func KeyFromString(str string) (Key, bool)

func PickRangeKeys added in v0.1.4

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

func PickSpecifiedKeys added in v0.1.4

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

func (Key) String added in v0.1.4

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

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) (*Validation, map[*tp.Field]*Validation, error)

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 *tp.Field
	Double         float64
	Int            int64
	Bool           bool
	Enum           *tp.EnumValue
	Binary         string
	Function       *ToolFunction
}

func (*TypedValidationValue) GetFieldReferenceName added in v0.2.0

func (t *TypedValidationValue) GetFieldReferenceName(ref string, st *golang.StructLike) 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 added in v0.1.4

func (vt ValueType) String() string

Jump to

Keyboard shortcuts

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