parsing

package
v0.22.5 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataType                  = "puccini.type"
	MetadataConverter             = "puccini.converter"
	MetadataComparer              = "puccini.comparer"
	MetadataQuirks                = "puccini.quirks"
	MetadataDataTypePrefix        = "puccini.data-type:"
	MetadataScriptletPrefix       = "puccini.scriptlet:"
	MetadataScriptletImportPrefix = "puccini.scriptlet.import:"

	MetadataCanonicalName   = "tosca.canonical-name"
	MetadataNormative       = "tosca.normative"
	MetadataFunctionPrefix  = "tosca.function."
	MetadataContraintPrefix = "tosca.constraint."
)

Variables

This section is empty.

Functions

func GetCanonicalName

func GetCanonicalName(entityPtr EntityPtr) string

func GetDataTypeMetadata

func GetDataTypeMetadata(metadata map[string]string) map[string]string

func GetDescription

func GetDescription(entityPtr EntityPtr) (string, bool)

From HasMetadata interface

func GetKey

func GetKey(entityPtr EntityPtr) string

From Mappable interface

func GetMetadata

func GetMetadata(entityPtr EntityPtr) (map[string]string, bool)

From HasMetadata interface

func Inherit

func Inherit(entityPtr EntityPtr) bool

From Inherits interface

func PreRead

func PreRead(entityPtr EntityPtr) bool

From PreReadable interface

func Render

func Render(entityPtr EntityPtr) bool

From Renderable interface

func SetInputs

func SetInputs(entityPtr EntityPtr, inputs map[string]ard.Value) bool

From HasInputs interface

func SetMetadata

func SetMetadata(entityPtr EntityPtr, name string, value string) bool

From HasMetadata interface

func ValidateRequiredFields

func ValidateRequiredFields(entityPtr EntityPtr) bool

From "mandatory" tags

(reflection.EntityTraverser signature)

Types

type Context

type Context struct {
	Parent             *Context
	Name               string
	Path               ard.Path
	URL                exturl.URL
	RepositoryURL      exturl.URL
	Bases              []exturl.URL
	Data               ard.Value
	Locator            ard.Locator
	CanonicalNamespace *string
	Namespace          *Namespace
	ScriptletNamespace *ScriptletNamespace
	Hierarchy          *Hierarchy
	Problems           *problems.Problems
	Quirks             Quirks
	Grammar            *Grammar
	FunctionPrefix     string
	ReadTagOverrides   map[string]string
}

func GetContext

func GetContext(entityPtr EntityPtr) *Context

From Contextual interface

func NewContext

func NewContext(stylist *terminal.Stylist, quirks Quirks) *Context

func (*Context) Clone

func (self *Context) Clone(data ard.Value) *Context

func (*Context) EmbedScriptlet

func (self *Context) EmbedScriptlet(name string, scriptlet string)

func (*Context) FieldChild

func (self *Context) FieldChild(name ard.Value, data ard.Value) *Context

func (*Context) FieldChildren

func (self *Context) FieldChildren() []*Context

func (*Context) FormatBadData

func (self *Context) FormatBadData() string

func (*Context) GetAncestor

func (self *Context) GetAncestor(generation int) *Context

func (*Context) GetCanonicalNamespace

func (self *Context) GetCanonicalNamespace() *string

func (*Context) GetFieldChild

func (self *Context) GetFieldChild(name string) (*Context, bool)

func (*Context) GetLocation

func (self *Context) GetLocation() (int, int)

func (*Context) GetRequiredFieldChild

func (self *Context) GetRequiredFieldChild(name string) (*Context, bool)

func (*Context) HasQuirk

func (self *Context) HasQuirk(quirk Quirk) bool

func (*Context) ImportScriptlet

func (self *Context) ImportScriptlet(name string, path string)

func (*Context) Is

func (self *Context) Is(typeNames ...ard.TypeName) bool

func (*Context) ListChild

func (self *Context) ListChild(index int, data ard.Value) *Context

func (*Context) MapChild

func (self *Context) MapChild(name ard.Value, data ard.Value) *Context

func (*Context) NewFunctionCall

func (self *Context) NewFunctionCall(name string, arguments []any) *FunctionCall

func (*Context) NewImportContext

func (self *Context) NewImportContext(url exturl.URL) *Context

func (*Context) Read added in v0.22.4

func (self *Context) Read(context contextpkg.Context) (ard.Value, ard.Locator, error)

func (*Context) ReadBoolean

func (self *Context) ReadBoolean() *bool

func (*Context) ReadFields

func (self *Context) ReadFields(entityPtr EntityPtr) []string

From "read" tags

func (*Context) ReadFloat

func (self *Context) ReadFloat() *float64

func (*Context) ReadInteger

func (self *Context) ReadInteger() *int64

func (*Context) ReadListItems

func (self *Context) ReadListItems(read Reader, process Processor) bool

func (*Context) ReadMapItems

func (self *Context) ReadMapItems(read Reader, process Processor) bool

func (*Context) ReadSequencedListItems

func (self *Context) ReadSequencedListItems(read Reader, process Processor) bool

func (*Context) ReadString

func (self *Context) ReadString() *string

func (*Context) ReadStringList

func (self *Context) ReadStringList() *[]string

func (*Context) ReadStringListFixed

func (self *Context) ReadStringListFixed(length int) *[]string

func (*Context) ReadStringListMinLength

func (self *Context) ReadStringListMinLength(length int) *[]string

func (*Context) ReadStringMap

func (self *Context) ReadStringMap() *map[string]any

func (*Context) ReadStringOrStringList

func (self *Context) ReadStringOrStringList() *[]string

func (*Context) ReadStringStringMap

func (self *Context) ReadStringStringMap() *map[string]string

func (*Context) Report

func (self *Context) Report(skip int, item string, message string) bool

func (*Context) ReportCopyLoop

func (self *Context) ReportCopyLoop(name string) bool

func (*Context) ReportDuplicateMapKey

func (self *Context) ReportDuplicateMapKey(key string) bool

func (*Context) ReportError

func (self *Context) ReportError(err error) bool

func (*Context) ReportFieldReferenceNotFound

func (self *Context) ReportFieldReferenceNotFound(types ...reflect.Type) bool

func (*Context) ReportImportIncompatible

func (self *Context) ReportImportIncompatible(url exturl.URL) bool

func (*Context) ReportImportLoop

func (self *Context) ReportImportLoop(url exturl.URL) bool

func (*Context) ReportIncompatible

func (self *Context) ReportIncompatible(name string, target string, kind string) bool

func (*Context) ReportIncompatibleExtension

func (self *Context) ReportIncompatibleExtension(extension string, requiredExtensions []string) bool

func (*Context) ReportIncompatibleType

func (self *Context) ReportIncompatibleType(type_ EntityPtr, parentType EntityPtr) bool

func (*Context) ReportIncompatibleTypeInSet

func (self *Context) ReportIncompatibleTypeInSet(type_ EntityPtr) bool

func (*Context) ReportInheritanceLoop

func (self *Context) ReportInheritanceLoop(parentType EntityPtr) bool

func (*Context) ReportKeynameMalformedSequencedList

func (self *Context) ReportKeynameMalformedSequencedList() bool

func (*Context) ReportKeynameMissing

func (self *Context) ReportKeynameMissing() bool

func (*Context) ReportKeynameUnsupported

func (self *Context) ReportKeynameUnsupported() bool

func (*Context) ReportKeynameUnsupportedValue

func (self *Context) ReportKeynameUnsupportedValue() bool

func (*Context) ReportMissingEntrySchema

func (self *Context) ReportMissingEntrySchema(kind string) bool

func (*Context) ReportNameAmbiguous

func (self *Context) ReportNameAmbiguous(type_ reflect.Type, name string, entityPtrs ...EntityPtr) bool

func (*Context) ReportNameInvalid

func (self *Context) ReportNameInvalid(entityPtr EntityPtr, name string) bool

func (*Context) ReportNotInRange

func (self *Context) ReportNotInRange(name string, value uint64, lower uint64, upper uint64) bool

func (*Context) ReportPath

func (self *Context) ReportPath(skip int, message string) bool

func (*Context) ReportPathf

func (self *Context) ReportPathf(skip int, f string, arg ...any) bool

func (*Context) ReportPrimitiveType

func (self *Context) ReportPrimitiveType() bool

func (*Context) ReportProblematic

func (self *Context) ReportProblematic(skip int, problematic problems.Problematic) bool

func (*Context) ReportReferenceAmbiguous

func (self *Context) ReportReferenceAmbiguous(kind string, entityPtr EntityPtr) bool

func (*Context) ReportReferenceNotFound

func (self *Context) ReportReferenceNotFound(kind string, entityPtr EntityPtr) bool

func (*Context) ReportRefinement

func (self *Context) ReportRefinement(parentValue ard.Value) bool

func (*Context) ReportRepositoryInaccessible

func (self *Context) ReportRepositoryInaccessible(repositoryName string) bool

func (*Context) ReportReservedMetadata

func (self *Context) ReportReservedMetadata() bool

func (*Context) ReportTypeIncomplete

func (self *Context) ReportTypeIncomplete(parentType EntityPtr) bool

func (*Context) ReportURL

func (self *Context) ReportURL(skip int, item string, message string, row int, column int) bool

func (*Context) ReportUndeclared

func (self *Context) ReportUndeclared(kind string) bool

func (*Context) ReportUnknown

func (self *Context) ReportUnknown(kind string) bool

func (*Context) ReportUnknownDataType

func (self *Context) ReportUnknownDataType(dataTypeName string) bool

func (*Context) ReportUnsupportedType

func (self *Context) ReportUnsupportedType() bool

func (*Context) ReportValueAspectWrongType

func (self *Context) ReportValueAspectWrongType(aspect string, value ard.Value, allowedTypeNames ...ard.TypeName) bool

func (*Context) ReportValueInvalid

func (self *Context) ReportValueInvalid(kind string, reason string) bool

func (*Context) ReportValueMalformed

func (self *Context) ReportValueMalformed(kind string, reason string) bool

func (*Context) ReportValueRequired

func (self *Context) ReportValueRequired(kind string) bool

func (*Context) ReportValueWrongFormat

func (self *Context) ReportValueWrongFormat(format string) bool

func (*Context) ReportValueWrongLength

func (self *Context) ReportValueWrongLength(kind string, length int) bool

func (*Context) ReportValueWrongType

func (self *Context) ReportValueWrongType(allowedTypeNames ...ard.TypeName) bool

func (*Context) Reportf

func (self *Context) Reportf(skip int, f string, arg ...any) bool

func (*Context) SequencedListChild

func (self *Context) SequencedListChild(index int, name string, data ard.Value) *Context

func (*Context) SetReadTag

func (self *Context) SetReadTag(fieldName string, tag string)

func (*Context) ValidateType

func (self *Context) ValidateType(requiredTypeNames ...ard.TypeName) bool

func (*Context) ValidateUnsupportedFields

func (self *Context) ValidateUnsupportedFields(keys []string)

type ContextContainer

type ContextContainer struct {
	Context *Context
}

func NewContextContainer

func NewContextContainer(context *Context) *ContextContainer

func (*ContextContainer) GetContext

func (self *ContextContainer) GetContext() *Context

(Contextual interface)

type Contextual

type Contextual interface {
	GetContext() *Context
}

type EntityPtr

type EntityPtr = any

func GetParent

func GetParent(entityPtr EntityPtr) (EntityPtr, bool)

From Hierarchical interface

type EntityPtrSet

type EntityPtrSet map[EntityPtr]struct{}

func (EntityPtrSet) Add

func (self EntityPtrSet) Add(entityPtr EntityPtr)

func (EntityPtrSet) Contains

func (self EntityPtrSet) Contains(entityPtr EntityPtr) bool

type EntityPtrs

type EntityPtrs []EntityPtr

func (EntityPtrs) Len

func (self EntityPtrs) Len() int

(sort.Interface)

func (EntityPtrs) Less

func (self EntityPtrs) Less(i, j int) bool

(sort.Interface)

func (EntityPtrs) Swap

func (self EntityPtrs) Swap(i, j int)

(sort.Interface)

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name" yaml:"name"`
	Arguments []any  `json:"arguments" yaml:"arguments"`
	URL       string `json:"url,omitempty" yaml:"url,omitempty"`
	Row       int    `json:"row,omitempty" yaml:"row,omitempty"`
	Column    int    `json:"column,omitempty" yaml:"column,omitempty"`
	Path      string `json:"path,omitempty" yaml:"path,omitempty"`
}

func NewFunctionCall

func NewFunctionCall(name string, arguments []any, url string, row int, column int, path string) *FunctionCall

type Grammar

type Grammar struct {
	Versions                   GrammarVersions
	Readers                    Readers
	InvalidNamespaceCharacters string
}

func NewGrammar

func NewGrammar() Grammar

func (*Grammar) RegisterReader

func (self *Grammar) RegisterReader(name string, reader Reader)

func (*Grammar) RegisterVersion

func (self *Grammar) RegisterVersion(keyword string, version string, implicitProfilePath string)

type GrammarVersion

type GrammarVersion struct {
	Version             string
	ImplicitProfilePath string
}

type GrammarVersions

type GrammarVersions map[string][]GrammarVersion

func (GrammarVersions) Add

func (self GrammarVersions) Add(keyword string, version string, implicitProfilePath string)

type HasInputs

type HasInputs interface {
	SetInputs(map[string]ard.Value)
}

type HasMetadata

type HasMetadata interface {
	GetDescription() (string, bool)
	GetMetadata() (map[string]string, bool) // should return a copy
	SetMetadata(name string, value string) bool
}

type Hierarchical

type Hierarchical interface {
	GetParent() EntityPtr
}

type Hierarchy

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

func NewHierarchy

func NewHierarchy() *Hierarchy

func NewHierarchyFor

func NewHierarchyFor(entityPtr EntityPtr, work reflection.EntityWork, hierarchyContext HierarchyContext) *Hierarchy

func (*Hierarchy) AddTo

func (self *Hierarchy) AddTo(entityPtr EntityPtr)

Into "hierarchy" tags

func (*Hierarchy) Empty

func (self *Hierarchy) Empty() bool

func (*Hierarchy) Find

func (self *Hierarchy) Find(entityPtr EntityPtr) (*Hierarchy, bool)

func (*Hierarchy) GetContext

func (self *Hierarchy) GetContext() *Context

func (*Hierarchy) IsCompatible

func (self *Hierarchy) IsCompatible(baseEntityPtr EntityPtr, entityPtr EntityPtr) bool

func (Hierarchy) Len

func (self Hierarchy) Len() int

(sort.Interface)

func (Hierarchy) Less

func (self Hierarchy) Less(i, j int) bool

(sort.Interface)

func (*Hierarchy) Merge

func (self *Hierarchy) Merge(hierarchy *Hierarchy, hierarchyContext HierarchyContext)

func (*Hierarchy) Print

func (self *Hierarchy) Print(indent int)

Note that the same name could be printed out twice in the hierarchy, even under the same parent! That's because we are printing the local name of the type, and types imported from other files can have the same name (though you would need a namespace_prefix to avoid a namespace error)

func (*Hierarchy) PrintChild

func (self *Hierarchy) PrintChild(indent int, treePrefix terminal.TreePrefix, last bool)

func (*Hierarchy) PrintChildren

func (self *Hierarchy) PrintChildren(indent int, treePrefix terminal.TreePrefix)

func (*Hierarchy) Range

func (self *Hierarchy) Range(f func(EntityPtr, EntityPtr) bool)

func (*Hierarchy) Root

func (self *Hierarchy) Root() *Hierarchy

func (Hierarchy) Swap

func (self Hierarchy) Swap(i, j int)

(sort.Interface)

type HierarchyContext

type HierarchyContext = EntityPtrSet

Keeps track of failed types

type ImportSpec

type ImportSpec struct {
	URL             exturl.URL
	NameTransformer NameTransformer
	Implicit        bool
}

func GetImportSpecs

func GetImportSpecs(entityPtr EntityPtr) []*ImportSpec

From Importer interface

type Importer

type Importer interface {
	GetImportSpecs() []*ImportSpec
}

type Inherits

type Inherits interface {
	Inherit()
}

type Mappable

type Mappable interface {
	GetKey() string
}

type NameTransformer

type NameTransformer = func(string, EntityPtr) []string

type Namespace

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

func NewNamespace

func NewNamespace() *Namespace

func NewNamespaceFor

func NewNamespaceFor(entityPtr EntityPtr) *Namespace

From "namespace" tags

func (*Namespace) Empty

func (self *Namespace) Empty() bool

func (*Namespace) Lookup

func (self *Namespace) Lookup(name string) (EntityPtr, bool)

func (*Namespace) LookupForType

func (self *Namespace) LookupForType(name string, type_ reflect.Type) (EntityPtr, bool)

func (*Namespace) Merge

func (self *Namespace) Merge(namespace *Namespace, nameTransformer NameTransformer)

func (*Namespace) Print

func (self *Namespace) Print(indent int)

func (*Namespace) Range

func (self *Namespace) Range(f func(EntityPtr) bool)

func (*Namespace) Set

func (self *Namespace) Set(name string, entityPtr EntityPtr) (EntityPtr, bool)

If the name has already been set returns existing entityPtr, true

type PreReadable

type PreReadable interface {
	PreRead()
}

type Processor

type Processor = func(ard.Value)

type Quirk

type Quirk string
const (
	// In TOSCA 1.0-1.3 the Simple Profile is implicitly imported by default. This quirk will disable
	// implicit imports.
	QuirkImportsImplicitDisable Quirk = "imports.implicit.disable"

	// Allows imported files to contain a `topology_template`
	// section, which is ignored.
	QuirkImportsTopologyTemplateIgnore Quirk = "imports.topology_template.ignore"

	// By default Puccini will report an error if a file imports
	// another file with an incompatible grammar. This quirk will disable the check.
	QuirkImportsVersionPermissive Quirk = "imports.version.permissive"

	// Allows the "import" syntax to be a sequenced list, in which the
	// name is ignored.
	QuirkImportsSequencedList Quirk = "imports.sequencedlist"

	// By default Puccini is strict about "string"-typed values
	// and will consider integers, floats, and boolean values to be problems. This quirk will accept
	// such values and convert them as sensibly as possible to strings. This includes accepting floats
	// and integers for the TOSCA "version" primitive type. Note that string conversions may very well
	// *not* be identical to the literal YAML. For example, `1.0000` in YAML (a float) would become
	// the string `1` in TOSCA.
	QuirkDataTypesStringPermissive Quirk = "data_types.string.permissive"

	// By default Puccini requires all "timestamp" values to be
	// specified as strings in the ISO 8601 format. However, some YAML environments may support the
	// optional !!timestamp type. This quirk will allow such values. Note that such values will not have
	// the "$originalString" key, because the literal YAML is not preserved by the YAML parser.
	QuirkDataTypesTimestampPermissive Quirk = "data_types.timestamp.permissive"

	// By default Puccini will ensure that capabilities have
	// the minimum number of incoming relationships. This quirk will disable that validation.
	QuirkCapabilitiesOccurrencesPermissive Quirk = "capabilities.occurrences.permissive"

	// This will ignore any type that is has the `tosca.normative: 'true'` metadata.
	QuirkNamespaceNormativeIgnore Quirk = "namespace.normative.ignore"

	// In TOSCA 1.0-1.3 all the normative types have long
	// names, such as "tosca.nodes.Compute", prefixed names ("tosca:Compute"), and also short names
	// ("Compute"). Those short names are annoying because it means you can't use those names for your
	// own types. This quirk disables the short names (the prefixed names remain).
	QuirkNamespaceNormativeShortcutsDisable Quirk = "namespace.normative.shortcuts.disable"

	// According to the examples in the TOSCA 1.0-1.3 specs,
	// the `requirements` key under `substitution_mappings` is syntactically a map. However, this syntax
	// is inconsistent because it doesn't match the syntax in node templates, which is a sequenced list.
	// (In node types, too, it is a sequenced list, although grammatically it works like a map.) This
	// quirk allows the expected syntax to be a sequenced list.
	QuirkSubstitutionMappingsRequirementsList Quirk = "substitution_mappings.requirements.list"

	// Normally the `requirements` under
	// `substitution_mappings` must be mapped to an assigned requirement in a node template. This quirk
	// allows unassigned requirements to be mapped.
	QuirkSubstitutionMappingsRequirementsPermissive Quirk = "substitution_mappings.requirements.permissive"

	// Ignores the "annotation_types" keyword in service templates and the
	// "annotations" keyword in parameter definitions.
	QuirkAnnotationsIgnore Quirk = "annotations.ignore"

	// Allows interface types, definitions, and assignments to
	// refer to operations directly in addition to using the "operations" keyname. This allows TOSCA 1.3
	// and 2.0 to support the TOSCA 1.2 grammar.
	QuirkInterfacesOperationsPermissive Quirk = "interfaces.operations.permissive"

	// Combines "imports.topology_template.ignore", "data_types.string.permissive",
	// "capabilities.occurrences.permissive", "substitution_mappings.requirements.permissive",
	// "substitution_mappings.requirements.list"
	QuirkETSINFV Quirk = "etsinfv"

	// Combines "annotations.ignore", "imports.sequencedlist", "imports.version.permissive"
	QuirkONAP Quirk = "onap"
)

type Quirks

type Quirks []Quirk

func NewQuirks

func NewQuirks(quirks ...string) Quirks

func (Quirks) Has

func (self Quirks) Has(quirk Quirk) bool

func (Quirks) String

func (self Quirks) String() string

fmt.Stringify interface

type ReadField

type ReadField struct {
	FieldName string
	Key       string
	Context   *Context
	Entity    reflect.Value
	Reader    Reader
	Mode      ReadMode
	Important bool
	Wildcard  bool
}

func NewReadField

func NewReadField(fieldName string, tag string, context *Context, entity reflect.Value) *ReadField

func (*ReadField) Read

func (self *ReadField) Read()

type ReadMode

type ReadMode int
const (
	ReadFieldModeDefault             ReadMode = 0
	ReadFieldModeList                ReadMode = 1
	ReadFieldModeSequencedList       ReadMode = 2
	ReadFieldModeUniqueSequencedList ReadMode = 3
	ReadFieldModeItem                ReadMode = 4
)

type Reader

type Reader = func(*Context) EntityPtr

type Readers

type Readers map[string]Reader

type Renderable

type Renderable interface {
	Render()
}

type Scriptlet

type Scriptlet struct {
	Base                  exturl.URL `json:"base" yaml:"base"`
	Path                  string     `json:"path" yaml:"path"`
	Scriptlet             string     `json:"scriptlet" yaml:"scriptlet"`
	NativeArgumentIndexes []int      `json:"nativeArgumentIndexes" yaml:"nativeArgumentIndexes"`
}

func (*Scriptlet) Read

func (self *Scriptlet) Read(context contextpkg.Context) (string, error)

type ScriptletNamespace

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

func NewScriptletNamespace

func NewScriptletNamespace() *ScriptletNamespace

func (*ScriptletNamespace) Lookup

func (self *ScriptletNamespace) Lookup(name string) (*Scriptlet, bool)

func (*ScriptletNamespace) Merge

func (self *ScriptletNamespace) Merge(namespace *ScriptletNamespace)

func (*ScriptletNamespace) Range

func (self *ScriptletNamespace) Range(f func(string, *Scriptlet) bool)

func (*ScriptletNamespace) RegisterScriptlet

func (self *ScriptletNamespace) RegisterScriptlet(name string, scriptlet string, nativeArgumentIndexes []int)

func (*ScriptletNamespace) RegisterScriptlets

func (self *ScriptletNamespace) RegisterScriptlets(scriptlets map[string]string, nativeArgumentIndexes map[string][]int, ignore ...string)

func (*ScriptletNamespace) Set

func (self *ScriptletNamespace) Set(name string, scriptlet *Scriptlet)

type TypesByName

type TypesByName []reflect.Type

func (TypesByName) Len

func (self TypesByName) Len() int

(sort.Interface)

func (TypesByName) Less

func (self TypesByName) Less(i, j int) bool

(sort.Interface)

func (TypesByName) Swap

func (self TypesByName) Swap(i, j int)

(sort.Interface)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳