types

package
v0.23.8 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Any    = TypeFromString("any")
	Bool   = TypeFromString("bool")
	Char   = TypeFromString("char")
	Data   = TypeFromString("data")
	Number = TypeFromString("number")
	String = TypeFromString("string")

	AnyArray    = TypeFromString("[]any")
	BoolArray   = TypeFromString("[]bool")
	NumberArray = TypeFromString("[]number")
	StringArray = TypeFromString("[]string")

	AnyMap    = TypeFromString("{}any")
	NumberMap = TypeFromString("{}number")
	StringMap = TypeFromString("{}string")

	ErrorInterface = NewInterface("error.Error", map[string]*Type{
		"Error": String,
	})
)

Functions

This section is empty.

Types

type Kind

type Kind int
const (
	// An unresolved interface (object type) is named, but the properties will
	// be nil because they are not known. This is a distinction from a resolved
	// interface which allowed to have zero or more properties.
	//
	// KindUnresolvedInterface = 0 on purpose it acts as a fallthrough/unknown
	// type.
	KindUnresolvedInterface Kind = iota
	KindResolvedInterface

	// Basic types.
	KindAny
	KindBool
	KindChar
	KindData
	KindNumber
	KindString

	// Other.
	KindArray
	KindMap
	KindFunc
)

type Type

type Type struct {
	Kind Kind

	// Name is used as the descriptive name for the object.
	Name string

	// Element is used when Kind is an Array or Map.
	Element *Type

	// Argument and Returns are used when Kind is a Func. Either may be nil.
	Arguments, Returns []*Type

	// Properties is used for KindInterface
	Properties map[string]*Type
}

Type represents a data type.

func NewFunc

func NewFunc(args, returns []*Type) *Type

func NewInterface

func NewInterface(name string, properties map[string]*Type) *Type

func NewUnresolvedInterface

func NewUnresolvedInterface(name string) *Type

func TypeFromString

func TypeFromString(s string) *Type

TypeFromString decodes a syntactically-valid type from a string.

func (*Type) String

func (t *Type) String() string

func (*Type) ToArray

func (t *Type) ToArray() *Type

ToArray creates an array type using this element type.

func (*Type) ToMap

func (t *Type) ToMap() *Type

ToMap creates a map type using this element type.

Jump to

Keyboard shortcuts

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