parser

package
v0.0.0-...-bd71913 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NodeDefaultSeerLeaf = "config"

Functions

This section is empty.

Types

type At

type At interface {
	At(string) (At, error)
	Get(any) error // converts to schema expected type + validate type and value
	Set(any) error // validate type and value
}

type Attribute

type Attribute struct {
	Name      string
	Type      Type
	Required  bool
	Key       bool // means the value is the key of a map
	Default   any
	Path      []StringMatch
	Compat    []StringMatch
	Validator AttributeValidator
}

func Attributes

func Attributes(attrs ...*Attribute) []*Attribute

func Bool

func Bool(name string, options ...Option) *Attribute

func Float

func Float(name string, options ...Option) *Attribute

func Int

func Int(name string, options ...Option) *Attribute

func String

func String(name string, options ...Option) *Attribute

func StringSlice

func StringSlice(name string, options ...Option) *Attribute

type AttributeValidator

type AttributeValidator func(any) error

type Node

type Node struct {
	Group      bool
	Match      StringMatch
	Attributes []*Attribute
	Children   []*Node
}

func Define

func Define(match StringMatch, attrs []*Attribute, children ...*Node) *Node

func DefineGroup

func DefineGroup(match string, children ...*Node) *Node

func DefineIter

func DefineIter(attrs []*Attribute, children ...*Node) *Node

func DefineIterGroup

func DefineIterGroup(attrs []*Attribute, children ...*Node) *Node

func Root

func Root(attrs []*Attribute, children ...*Node) *Node

func (*Node) ChildMatch

func (n *Node) ChildMatch(name string) (*Node, error)

func (*Node) Map

func (n *Node) Map() map[string]any

func (*Node) Object

func (n *Node) Object(query *seer.Query) (object.Object[object.Refrence], error)

type Option

type Option func(*Attribute)

func Compat

func Compat(path ...StringMatch) Option

func Default

func Default[T any](val T) Option

func InSet

func InSet[T string | int | float64](elms ...T) Option

func IsCID

func IsCID() Option

func IsEmail

func IsEmail() Option

func IsFqdn

func IsFqdn() Option

func IsHttpMethod

func IsHttpMethod() Option

func IsVariableName

func IsVariableName() Option

func Key

func Key() Option

func Path

func Path(path ...StringMatch) Option

func Required

func Required() Option

func Validator

func Validator[T any](validator func(T) error) Option

type Parser

type Parser interface {
	Schema() Schema
	Parse() (object.Object[object.Refrence], error)
}

func New

func New(schema Schema, options ...seer.Option) (Parser, error)

type Schema

type Schema interface {
	Yaml() string
	Json() string
	Map() map[string]any
}

func SchemaDefinition

func SchemaDefinition(root *Node) Schema

type StringMatch

type StringMatch any // string or PathMatcher

type StringMatchAll

type StringMatchAll struct{}

func (StringMatchAll) Match

func (StringMatchAll) Match(string) bool

func (StringMatchAll) String

func (StringMatchAll) String() string

type StringMatcher

type StringMatcher interface {
	Match(s string) bool
	String() string
}

func All

func All() StringMatcher

func Either

func Either(values ...string) StringMatcher

type SupportedTypes

type SupportedTypes interface {
	int | bool | float64 | string | []string
}

type Type

type Type int
const (
	TypeInt Type = iota
	TypeBool
	TypeFloat
	TypeString
	TypeStringSlice
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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