compiler

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

README

Compiler support code

This directory contains compiler support code used by Gnostic and Gnostic extensions.

Documentation

Overview

Package compiler provides support functions to generated compiler code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolForScalarNode added in v0.5.0

func BoolForScalarNode(node *yaml.Node) (bool, bool)

BoolForScalarNode returns the bool value of a node.

func CallExtension added in v0.5.0

func CallExtension(context *Context, in *yaml.Node, extensionName string) (handled bool, response *any.Any, err error)

CallExtension calls a binary extension handler.

func ClearCaches added in v0.4.1

func ClearCaches()

ClearCaches clears all caches.

func ClearFileCache added in v0.4.1

func ClearFileCache()

ClearFileCache clears the file cache.

func ClearInfoCache added in v0.3.1

func ClearInfoCache()

ClearInfoCache clears the info cache.

func ConvertInterfaceArrayToStringArray

func ConvertInterfaceArrayToStringArray(interfaceArray []interface{}) []string

ConvertInterfaceArrayToStringArray converts an array of interfaces to an array of strings, if possible.

func Description added in v0.4.2

func Description(item interface{}) string

Description returns a human-readable represention of an item.

func DisableFileCache added in v0.3.0

func DisableFileCache()

DisableFileCache turns off file caching.

func DisableInfoCache added in v0.3.0

func DisableInfoCache()

DisableInfoCache turns off parsed info caching.

func Display added in v0.5.0

func Display(node *yaml.Node) string

Display returns a description of a node for use in error messages.

func EnableFileCache added in v0.4.1

func EnableFileCache()

EnableFileCache turns on file caching.

func EnableInfoCache added in v0.4.1

func EnableInfoCache()

EnableInfoCache turns on parsed info caching.

func FetchFile

func FetchFile(fileurl string) ([]byte, error)

FetchFile gets a specified file from the local filesystem or a remote location.

func FloatForScalarNode added in v0.5.0

func FloatForScalarNode(node *yaml.Node) (float64, bool)

FloatForScalarNode returns the float value of a node.

func GetInfoCache added in v0.3.1

func GetInfoCache() map[string]*yaml.Node

GetInfoCache returns the info cache map.

func IntForScalarNode added in v0.5.0

func IntForScalarNode(node *yaml.Node) (int64, bool)

IntForScalarNode returns the integer value of a node.

func InvalidKeysInMap

func InvalidKeysInMap(m *yaml.Node, allowedKeys []string, allowedPatterns []*regexp.Regexp) []string

InvalidKeysInMap returns keys in a map that don't match a list of allowed keys and patterns.

func MapHasKey

func MapHasKey(m *yaml.Node, key string) bool

MapHasKey returns true if a yamlv2.MapSlice contains a specified key.

func MapValueForKey

func MapValueForKey(m *yaml.Node, key string) *yaml.Node

MapValueForKey gets the value of a map value for a specified key.

func Marshal added in v0.5.0

func Marshal(in *yaml.Node) []byte

Marshal creates a yaml version of a structure in our preferred style

func MissingKeysInMap

func MissingKeysInMap(m *yaml.Node, requiredKeys []string) []string

MissingKeysInMap identifies which keys from a list of required keys are not in a map.

func NewErrorGroupOrNil

func NewErrorGroupOrNil(errors []error) error

NewErrorGroupOrNil returns a new ErrorGroup for a slice of errors or nil if the slice is empty.

func NewMappingNode added in v0.5.0

func NewMappingNode() *yaml.Node

NewMappingNode creates a new Mapping node.

func NewNullNode added in v0.5.2

func NewNullNode() *yaml.Node

NewNullNode creates a new Null node.

func NewScalarNodeForBool added in v0.5.0

func NewScalarNodeForBool(b bool) *yaml.Node

NewScalarNodeForBool creates a new node to hold a bool.

func NewScalarNodeForFloat added in v0.5.0

func NewScalarNodeForFloat(f float64) *yaml.Node

NewScalarNodeForFloat creates a new node to hold a float.

func NewScalarNodeForInt added in v0.5.0

func NewScalarNodeForInt(i int64) *yaml.Node

NewScalarNodeForInt creates a new node to hold an integer.

func NewScalarNodeForString added in v0.5.0

func NewScalarNodeForString(s string) *yaml.Node

NewScalarNodeForString creates a new node to hold a string.

func NewSequenceNode added in v0.5.0

func NewSequenceNode() *yaml.Node

NewSequenceNode creates a new Sequence node.

func NewSequenceNodeForStringArray added in v0.5.0

func NewSequenceNodeForStringArray(strings []string) *yaml.Node

NewSequenceNodeForStringArray creates a new node to hold an array of strings.

func PluralProperties

func PluralProperties(count int) string

PluralProperties returns the string "properties" pluralized.

func ReadBytesForFile

func ReadBytesForFile(filename string) ([]byte, error)

ReadBytesForFile reads the bytes of a file.

func ReadInfoForRef

func ReadInfoForRef(basefile string, ref string) (*yaml.Node, error)

ReadInfoForRef reads a file and return the fragment needed to resolve a $ref.

func ReadInfoFromBytes

func ReadInfoFromBytes(filename string, bytes []byte) (*yaml.Node, error)

ReadInfoFromBytes unmarshals a file as a *yaml.Node.

func RemoveFromFileCache added in v0.3.0

func RemoveFromFileCache(fileurl string)

RemoveFromFileCache removes an entry from the file cache.

func RemoveFromInfoCache added in v0.3.0

func RemoveFromInfoCache(filename string)

RemoveFromInfoCache removes an entry from the info cache.

func SequenceNodeForNode added in v0.5.0

func SequenceNodeForNode(node *yaml.Node) (*yaml.Node, bool)

SequenceNodeForNode returns a node if it is a SequenceNode.

func SortedKeysForMap

func SortedKeysForMap(m *yaml.Node) []string

SortedKeysForMap returns the sorted keys of a yamlv2.MapSlice.

func StringArrayContainsValue

func StringArrayContainsValue(array []string, value string) bool

StringArrayContainsValue returns true if a string array contains a specified value.

func StringArrayContainsValues

func StringArrayContainsValues(array []string, values []string) bool

StringArrayContainsValues returns true if a string array contains all of a list of specified values.

func StringArrayForSequenceNode added in v0.5.0

func StringArrayForSequenceNode(node *yaml.Node) []string

StringArrayForSequenceNode converts a sequence node to an array of strings, if possible.

func StringForScalarNode added in v0.5.0

func StringForScalarNode(node *yaml.Node) (string, bool)

StringForScalarNode returns the string value of a node.

func StringValue

func StringValue(item interface{}) (value string, ok bool)

StringValue returns the string value of an item.

func UnpackMap

func UnpackMap(in *yaml.Node) (*yaml.Node, bool)

UnpackMap gets a *yaml.Node if possible.

Types

type Context

type Context struct {
	Parent            *Context
	Name              string
	Node              *yaml.Node
	ExtensionHandlers *[]ExtensionHandler
}

Context contains state of the compiler as it traverses a document.

func NewContext

func NewContext(name string, node *yaml.Node, parent *Context) *Context

NewContext returns a new object representing the compiler state

func NewContextWithExtensions

func NewContextWithExtensions(name string, node *yaml.Node, parent *Context, extensionHandlers *[]ExtensionHandler) *Context

NewContextWithExtensions returns a new object representing the compiler state

func (*Context) Description

func (context *Context) Description() string

Description returns a text description of the compiler state

type Error

type Error struct {
	Context *Context
	Message string
}

Error represents compiler errors and their location in the document.

func NewError

func NewError(context *Context, message string) *Error

NewError creates an Error.

func (*Error) Error

func (err *Error) Error() string

Error returns the string value of an Error.

type ErrorGroup

type ErrorGroup struct {
	Errors []error
}

ErrorGroup is a container for groups of Error values.

func (*ErrorGroup) Error

func (group *ErrorGroup) Error() string

type ExtensionHandler

type ExtensionHandler struct {
	Name string
}

ExtensionHandler describes a binary that is called by the compiler to handle specification extensions.

Jump to

Keyboard shortcuts

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