core

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	YISP_SPECIAL_MERGE_KEY = "__YISP_MERGE_KEY__"
)

Variables

View Source
var EvaluationError = ErrorTypeEvaluation{Type: "YispErrorEvaluation"}

Functions

func IsTruthy

func IsTruthy(node *YispNode) (bool, error)

isTruthy determines if a value is considered "truthy" in a boolean context

func IsZero

func IsZero(v any) bool

func JsonPrint

func JsonPrint(tag string, obj any)

JsonPrint prints an object as formatted JSON with a tag

func RenderCode

func RenderCode(file string, line, after, before int, comments []Comment) (string, error)

func VerifyTypes added in v1.3.1

func VerifyTypes(node *YispNode, allowUntypedManifest bool) error

Types

type Attribute

type Attribute struct {
	Sources []FilePos

	KeyHeadComment string
	KeyLineComment string
	KeyFootComment string

	HeadComment string
	LineComment string
	FootComment string

	KeyStyle yaml.Style
	Style    yaml.Style
}

func (*Attribute) Column

func (a *Attribute) Column() int

func (*Attribute) File

func (a *Attribute) File() string

func (*Attribute) Line

func (a *Attribute) Line() int

func (Attribute) Merge added in v1.0.6

func (a Attribute) Merge(other Attribute) Attribute

type Comment

type Comment struct {
	Line   int
	Column int
	Text   string
}

type Engine

type Engine interface {
	Run(document io.Reader, env *Env, location string) (*YispNode, error)
	Apply(car *YispNode, cdr []*YispNode, env *Env, mode EvalMode) (*YispNode, error)
	Eval(node *YispNode, env *Env, mode EvalMode) (*YispNode, error)
	Render(node *YispNode) (string, error)
	GetOption(key string) (any, bool)
}

type Env

type Env struct {
	Parent *Env
	Vars   map[string]*YispNode
}

Env represents the execution environment with variable bindings

func NewEnv

func NewEnv() *Env

NewEnv creates a new environment with an empty variable map

func (*Env) Clone

func (e *Env) Clone() *Env

func (*Env) CreateChild

func (e *Env) CreateChild() *Env

func (*Env) Depth

func (e *Env) Depth() int

func (*Env) Get

func (e *Env) Get(key string) (*YispNode, bool)

func (*Env) Root

func (e *Env) Root() *Env

func (*Env) Set

func (e *Env) Set(key string, value *YispNode)

type ErrorTypeEvaluation

type ErrorTypeEvaluation struct {
	Type    string
	Node    *YispNode
	Message string
	Parent  *ErrorTypeEvaluation
}

func NewEvaluationError

func NewEvaluationError(node *YispNode, message string) *ErrorTypeEvaluation

func NewEvaluationErrorWithParent

func NewEvaluationErrorWithParent(node *YispNode, message string, parent error) *ErrorTypeEvaluation

func (*ErrorTypeEvaluation) Error

func (e *ErrorTypeEvaluation) Error() string

func (*ErrorTypeEvaluation) GetRoot

func (*ErrorTypeEvaluation) String

func (e *ErrorTypeEvaluation) String() string

type EvalMode

type EvalMode int
const (
	EvalModeQuote EvalMode = iota
	EvalModeEval
)

type FilePos added in v1.0.6

type FilePos struct {
	File   string
	Line   int
	Column int
}

type Kind

type Kind int32

Kind represents the type of a YispNode

const (
	KindSymbol Kind = iota
	KindParameter
	KindNull
	KindBool
	KindInt
	KindFloat
	KindString
	KindArray
	KindMap
	KindLambda
	KindType
)

func (Kind) String

func (k Kind) String() string

type Lambda

type Lambda struct {
	Arguments []TypedSymbol
	Returns   *Schema
	Body      *YispNode
	Clojure   *Env
}

type Schema

type Schema struct {
	ID                   string             `json:"$id,omitempty"`
	Ref                  string             `json:"$ref,omitempty"`
	Type                 string             `json:"type,omitempty"`
	Format               string             `json:"format,omitempty"`
	Required             []string           `json:"required,omitempty"`
	Properties           map[string]*Schema `json:"properties,omitempty"`
	Items                *Schema            `json:"items,omitempty"`
	AdditionalProperties any                `json:"additionalProperties,omitempty"`
	Arguments            []*Schema          `json:"arguments,omitempty"`
	Returns              *Schema            `json:"returns,omitempty"`
	Description          string             `json:"description,omitempty"`
	Default              any                `json:"default,omitempty"`

	OneOf []*Schema `json:"oneOf,omitempty"`

	// Numeric constraints
	MultipleOf       *int     `json:"multipleOf,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty"`
	Maximum          *float64 `json:"maximum,omitempty"`
	ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty"`
	ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty"`

	// String constraints
	MinLength *int `json:"minLength,omitempty"`
	MaxLength *int `json:"maxLength,omitempty"`

	PatchStrategy    string `json:"patchStrategy,omitempty"`
	PatchMergeKey    string `json:"patchMergeKey,omitempty"`
	K8sPatchStrategy string `json:"x-kubernetes-patch-strategy,omitempty"`
	K8sPatchMergeKey string `json:"x-kubernetes-patch-merge-key,omitempty"`
}

func LoadSchemaFromGVK

func LoadSchemaFromGVK(group, version, kind string) (*Schema, error)

func LoadSchemaFromID

func LoadSchemaFromID(id string) (*Schema, error)

func LoadSchemaFromURL added in v1.3.0

func LoadSchemaFromURL(url string) (*Schema, error)

func (*Schema) Cast

func (s *Schema) Cast(node *YispNode) (*YispNode, error)

func (*Schema) Equals

func (s *Schema) Equals(other *Schema) bool

func (*Schema) GetAdditionalProperties

func (s *Schema) GetAdditionalProperties() any

func (*Schema) GetItems

func (s *Schema) GetItems() *Schema

func (*Schema) GetPatchMergeKey

func (s *Schema) GetPatchMergeKey() string

func (*Schema) GetPatchStrategy

func (s *Schema) GetPatchStrategy() string

func (*Schema) GetProperties

func (s *Schema) GetProperties() map[string]*Schema

func (*Schema) InterpolateDefaults

func (s *Schema) InterpolateDefaults(node *YispNode) error

func (*Schema) ToYispNode

func (s *Schema) ToYispNode() (*YispNode, error)

func (*Schema) Validate

func (s *Schema) Validate(node *YispNode) error

type TypedSymbol

type TypedSymbol struct {
	Name   string
	Schema *Schema
}

type YamlDocument

type YamlDocument []any

type YispMap

type YispMap = orderedmap.OrderedMap[string, any]

func NewYispMap

func NewYispMap() *YispMap

type YispNode

type YispNode struct {
	Kind           Kind
	Tag            string
	Value          any
	Anchor         string
	Attr           Attribute
	IsDocumentRoot bool
	Type           *Schema
}

YispNode represents a node in the Yisp language

func CallEngineByPath

func CallEngineByPath(path, base string, env *Env, e Engine) (*YispNode, error)

func DeepMergeYispNode

func DeepMergeYispNode(dst, src *YispNode, schema *Schema) (*YispNode, error)

func ParseAny

func ParseAny(filename string, v any) (*YispNode, error)

func ParseJson

func ParseJson(filename string, reader io.Reader) (*YispNode, error)

func (*YispNode) Sourcemap added in v1.0.5

func (n *YispNode) Sourcemap() string

func (*YispNode) String

func (n *YispNode) String() string

func (*YispNode) ToNative added in v1.3.0

func (n *YispNode) ToNative() (any, error)

type YispOperator

type YispOperator func([]*YispNode, *Env, EvalMode, Engine) (*YispNode, error)

Jump to

Keyboard shortcuts

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