compiler

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2022 License: Apache-2.0 Imports: 18 Imported by: 7

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

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

BoolForScalarNode returns the bool value of a node.

func CallExtension

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

CallExtension calls a binary extension handler.

func ClearCaches

func ClearCaches()

ClearCaches clears all caches.

func ClearFileCache

func ClearFileCache()

ClearFileCache clears the file cache.

func ClearInfoCache

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

func Description(item interface{}) string

Description returns a human-readable represention of an item.

func DisableFileCache

func DisableFileCache()

DisableFileCache turns off file caching.

func DisableInfoCache

func DisableInfoCache()

DisableInfoCache turns off parsed info caching.

func Display

func Display(node *yaml.Node) string

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

func EnableFileCache

func EnableFileCache()

EnableFileCache turns on file caching.

func EnableInfoCache

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

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

FloatForScalarNode returns the float value of a node.

func GetInfoCache

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

GetInfoCache returns the info cache map.

func IntForScalarNode

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

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

func NewMappingNode() *yaml.Node

NewMappingNode creates a new Mapping node.

func NewNullNode

func NewNullNode() *yaml.Node

NewNullNode creates a new Null node.

func NewScalarNodeForBool

func NewScalarNodeForBool(b bool) *yaml.Node

NewScalarNodeForBool creates a new node to hold a bool.

func NewScalarNodeForFloat

func NewScalarNodeForFloat(f float64) *yaml.Node

NewScalarNodeForFloat creates a new node to hold a float.

func NewScalarNodeForInt

func NewScalarNodeForInt(i int64) *yaml.Node

NewScalarNodeForInt creates a new node to hold an integer.

func NewScalarNodeForString

func NewScalarNodeForString(s string) *yaml.Node

NewScalarNodeForString creates a new node to hold a string.

func NewSequenceNode

func NewSequenceNode() *yaml.Node

NewSequenceNode creates a new Sequence node.

func NewSequenceNodeForStringArray

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

func RemoveFromFileCache(fileurl string)

RemoveFromFileCache removes an entry from the file cache.

func RemoveFromInfoCache

func RemoveFromInfoCache(filename string)

RemoveFromInfoCache removes an entry from the info cache.

func SequenceNodeForNode

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

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

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

func StringForScalarNode

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