types

package
v0.0.0-...-1b8cbf5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package types defines the Papyrus type system.

Types are broken down into two main categories: Invokable and Value types; as the names imply, the former describes function type information and the latter value type information (e.g. for variables and parameters).

Value types again break down into two categories: Scalar and Array types; the former represent single values while the latter represent sequence of some scalar type.

Scalar types again break down into two categories: Object and Primitive types; the former representing an script object and the latter the four primitive types: BoolType, IntType, FloatType, StringType.

There are also two special types: NoneType and VoidType. None is a scalar value type that is compatible with any object type and is used exclusively with the 'None' literal. Void is a value type that is used for functions that do not return a value.

Index

Constants

This section is empty.

Variables

View Source
var (
	// BoolType is the boolean type.
	BoolType = &Primitive{BoolKind, "Bool", "bool"}
	// IntType is the integer type.
	IntType = &Primitive{IntKind, "Int", "int"}
	// FloatType is the floating-point type.
	FloatType = &Primitive{FloatKind, "Float", "float"}
	// StringType is the string type.
	StringType = &Primitive{StringKind, "String", "string"}
	// BoolArrayType is the boolean array type.
	BoolArrayType = &Array{BoolType}
	// IntArrayType is the integer array type.
	IntArrayType = &Array{IntType}
	// FloatArrayType is the floating-point array type.
	FloatArrayType = &Array{FloatType}
	// StringArrayType is the string array type.
	StringArrayType = &Array{StringType}
	// NoneType is the type that is compatible with any object or array
	// type. This is used exclusively with the 'None' literal.
	NoneType = None{}
	// VoidType is the type used for functions that do not return a value.
	VoidType = Void{}
)
View Source
var ErrNotTyped = errors.New("node has no type")

ErrNotTyped indicates type resolution failed because the node does not have an intrinsic type, i.e. it's not one of the following:

Functions

This section is empty.

Types

type Array

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

Array represents an array type with an optionally known length.

func ArrayOf

func ArrayOf(element Scalar) *Array

ArrayOf returns a new array type with the given element type or nil if the element is None or nil.

func (*Array) Element

func (a *Array) Element() Scalar

Element returns the scalar type for elements of the array.

func (*Array) IsAssignable

func (a *Array) IsAssignable(other Type) bool

IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsAssignable(b)
b.IsAssignable(a)

func (*Array) IsComparable

func (*Array) IsComparable(Type) bool

IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsComparable(b)
b.IsComparable(a)

func (*Array) IsConvertible

func (*Array) IsConvertible(Type) bool

IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsConvertible(b)
b.IsConvertible(a)

func (*Array) IsEquatable

func (*Array) IsEquatable(Type) bool

IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsEquatable(b)
b.IsEquatable(a)

func (*Array) IsIdentical

func (a *Array) IsIdentical(other Type) bool

IsIdentical returns true if this type is identical to another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsIdentical(b)
b.IsIdentical(a)

func (*Array) Name

func (a *Array) Name() string

Name returns the declared name for the type.

func (*Array) Normalized

func (a *Array) Normalized() string

Normalized returns the normalized name for the type.

func (*Array) String

func (a *Array) String() string

type Invokable

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

Invokable is a function or event type.

func NewEvent

func NewEvent(name string, native bool, params ...Parameter) *Invokable

NewEvent returns a new event Invokable type with zero or more parameters.

func NewFunction

func NewFunction(name string, returnType Value, native, global bool, params ...Parameter) *Invokable

NewFunction returns a new function Invokable type with an optional return type and zero or more parameters.

func (*Invokable) Global

func (i *Invokable) Global() bool

Global returns true if this invokable is global and false otherwise.

func (*Invokable) IsAssignable

func (*Invokable) IsAssignable(Type) bool

IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsAssignable(b)
b.IsAssignable(a)

func (*Invokable) IsComparable

func (*Invokable) IsComparable(Type) bool

IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsComparable(b)
b.IsComparable(a)

func (*Invokable) IsConvertible

func (*Invokable) IsConvertible(Type) bool

IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsConvertible(b)
b.IsConvertible(a)

func (*Invokable) IsEquatable

func (*Invokable) IsEquatable(Type) bool

IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsEquatable(b)
b.IsEquatable(a)

func (*Invokable) IsIdentical

func (i *Invokable) IsIdentical(other Type) bool

IsIdentical returns true if this type is identical to another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsIdentical(b)
b.IsIdentical(a)

func (*Invokable) Kind

func (i *Invokable) Kind() InvokableKind

Kind returns the kind of this invokable.

func (*Invokable) Name

func (i *Invokable) Name() string

Name returns the declared name for the type.

func (*Invokable) Native

func (i *Invokable) Native() bool

Native returns true if this invokable is native and false otherwise.

func (*Invokable) Normalized

func (i *Invokable) Normalized() string

Normalized returns the normalized name for the type.

func (*Invokable) Parameters

func (i *Invokable) Parameters() []Parameter

Parameters returns the parameters in declaration order.

func (*Invokable) ReturnType

func (i *Invokable) ReturnType() Value

ReturnType returns the return type of the function or VoidType if there isn't one.

func (*Invokable) String

func (i *Invokable) String() string

type InvokableKind

type InvokableKind uint8

InvokableKind defines the different kinds of invokable types.

const (
	// FunctionKind represents the function invokable type.
	FunctionKind InvokableKind = iota
	// EventKind represents the event invokable type.
	EventKind
)

type None

type None struct{}

None is the special type used for the 'None' literal.

func (None) IsAssignable

func (None) IsAssignable(Type) bool

IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsAssignable(b)
b.IsAssignable(a)

func (None) IsComparable

func (None) IsComparable(Type) bool

IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsComparable(b)
b.IsComparable(a)

func (None) IsConvertible

func (None) IsConvertible(Type) bool

IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsConvertible(b)
b.IsConvertible(a)

func (None) IsEquatable

func (None) IsEquatable(other Type) bool

IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsEquatable(b)
b.IsEquatable(a)

func (None) IsIdentical

func (None) IsIdentical(Type) bool

IsIdentical returns true if this type is identical to another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsIdentical(b)
b.IsIdentical(a)

func (None) Name

func (None) Name() string

Name returns the declared name for the type.

func (None) Normalized

func (None) Normalized() string

Normalized returns the normalized name for the type.

func (None) String

func (None) String() string

type NotFoundError

type NotFoundError struct {
	Name string
}

NotFoundError indicates type resolution failed because the type refers to a script (object) type that the resolver could not find.

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Object

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

Object represents a named typed (i.e. a script).

func (*Object) IsAssignable

func (o *Object) IsAssignable(other Type) bool

IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsAssignable(b)
b.IsAssignable(a)

func (*Object) IsComparable

func (*Object) IsComparable(Type) bool

IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsComparable(b)
b.IsComparable(a)

func (*Object) IsConvertible

func (o *Object) IsConvertible(other Type) bool

IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsConvertible(b)
b.IsConvertible(a)

func (*Object) IsEquatable

func (o *Object) IsEquatable(other Type) bool

IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsEquatable(b)
b.IsEquatable(a)

func (*Object) IsIdentical

func (o *Object) IsIdentical(other Type) bool

IsIdentical returns true if this type is identical to another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsIdentical(b)
b.IsIdentical(a)

func (*Object) Name

func (o *Object) Name() string

Name returns the declared name for the type.

func (*Object) Node

func (o *Object) Node() ast.Node

Node returns the node that defines the type.

func (*Object) Normalized

func (o *Object) Normalized() string

Normalized returns the normalized name for the type.

func (*Object) Parent

func (o *Object) Parent() *Object

Parent is the object this object extends or nil if it extends nothing.

func (*Object) String

func (o *Object) String() string

type Parameter

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

Parameter is a function or event parameter (though not a type itself).

func NewParameter

func NewParameter(name string, typ Value, def bool) Parameter

NewParameter returns a new parameter with the given name, type and default flag (true if the parameter has a default value and false otherwise).

func (Parameter) Default

func (p Parameter) Default() bool

Default returns true if this parameter has a default value.

func (Parameter) Name

func (p Parameter) Name() string

Name returns the declared name for the parameter.

func (Parameter) Normalized

func (p Parameter) Normalized() string

Normalized returns the normalized name for the parameter.

func (Parameter) String

func (p Parameter) String() string

func (Parameter) Type

func (p Parameter) Type() Type

Type returns the type of the parameter.

type Primitive

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

Primitive represents a single Primitive, built-in type.

func (*Primitive) IsAssignable

func (p *Primitive) IsAssignable(other Type) bool

IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsAssignable(b)
b.IsAssignable(a)

func (*Primitive) IsComparable

func (p *Primitive) IsComparable(other Type) bool

IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsComparable(b)
b.IsComparable(a)

func (*Primitive) IsConvertible

func (p *Primitive) IsConvertible(other Type) bool

IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsConvertible(b)
b.IsConvertible(a)

func (*Primitive) IsEquatable

func (p *Primitive) IsEquatable(other Type) bool

IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsEquatable(b)
b.IsEquatable(a)

func (*Primitive) IsIdentical

func (p *Primitive) IsIdentical(other Type) bool

IsIdentical returns true if this type is identical to another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsIdentical(b)
b.IsIdentical(a)

func (*Primitive) Kind

func (p *Primitive) Kind() PrimitiveKind

Kind returns the kind of basic type.

func (*Primitive) Name

func (p *Primitive) Name() string

Name returns the standard name for the type.

func (*Primitive) Normalized

func (p *Primitive) Normalized() string

Normalized returns the normalized name for the type.

func (*Primitive) String

func (p *Primitive) String() string

type PrimitiveKind

type PrimitiveKind uint8

PrimitiveKind defines the various primitive types.

const (
	// BoolKind represents the primitive boolean type.
	BoolKind PrimitiveKind = iota
	// IntKind represents the primitive integer type.
	IntKind
	// FloatKind represents the primitive floating-point type.
	FloatKind
	// StringKind represents the primitive string type.
	StringKind
)

type Resolver

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

Resolver creates types for ast.Node instances.

Note: Resolver is stateful! In order to resolve script (object) types correctly, the script they extend must have been resolved first.

func (*Resolver) Resolve

func (r *Resolver) Resolve(node ast.Node) (Type, error)

Resolve returns the type for a given ast.Node or an error that wraps one of the following errors if type resolution fails:

  • NotFoundError if a node refers to an script (object) type the resolver does not know, i.e. it hasn't been resolved yet
  • ErrNotTyped if a node does not have an intrinsic type

type Scalar

type Scalar interface {
	Value
	// contains filtered or unexported methods
}

Scalar is the common interface for all scalar (i.e. non-array) types.

type Type

type Type interface {
	fmt.Stringer

	// Name returns the standard name for the type.
	Name() string

	// Normalized returns the normalized name for the type.
	Normalized() string

	// IsIdentical returns true if this type is
	// identical to another type and false otherwise.
	//
	// This method is commutative; both of the following expressions will always
	// evaluate to the same value:
	//
	//  a.IsIdentical(b)
	//  b.IsIdentical(a)
	IsIdentical(Type) bool

	// IsAssignable returns true if a value of another type can be assigned to a
	// variable of this type without an explicit type conversion and false
	// otherwise.
	//
	// This method is NOT commutative; the following expressions may not evaluate
	// to the same value:
	//
	//  a.IsAssignable(b)
	//  b.IsAssignable(a)
	IsAssignable(Type) bool

	// IsComparable returns true if a value of this type can be compared (i.e.
	// with '>', '<=', etc.) with a value of another type and false otherwise.
	//
	// This method is commutative; both of the following expressions will always
	// evaluate to the same value:
	//
	//  a.IsComparable(b)
	//  b.IsComparable(a)
	IsComparable(Type) bool

	// IsEquatable returns true if a value of this type can be checked for
	// equality (i.e. with '==' or '!=') with a value of another type and false
	// otherwise.
	//
	// This method is commutative; both of the following expressions will always
	// evaluate to the same value:
	//
	//  a.IsEquatable(b)
	//  b.IsEquatable(a)
	IsEquatable(Type) bool

	// IsConvertible returns true if a value of this type can be converted to
	// a value of another type through an explicit cast and false otherwise.
	//
	// This method is NOT commutative; the following expressions may not evaluate
	// to the same value:
	//
	//  a.IsConvertible(b)
	//  b.IsConvertible(a)
	IsConvertible(Type) bool
	// contains filtered or unexported methods
}

Type is the common interface for all types.

type Value

type Value interface {
	Type
	// contains filtered or unexported methods
}

Value is a common interface for all value types (scalars and arrays).

type Void

type Void struct{}

Void is special type used for functions that do not return a value.

func (Void) IsAssignable

func (Void) IsAssignable(Type) bool

IsAssignable returns true if a value of another type can be assigned to a variable of this type without an explicit type conversion and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsAssignable(b)
b.IsAssignable(a)

func (Void) IsComparable

func (Void) IsComparable(Type) bool

IsComparable returns true if a value of this type can be compared (i.e. with '>', '<=', etc.) with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsComparable(b)
b.IsComparable(a)

func (Void) IsConvertible

func (Void) IsConvertible(Type) bool

IsConvertible returns true if a value of this type can be converted to a value of another type through an explicit cast and false otherwise.

This method is NOT commutative; the following expressions may not evaluate to the same value:

a.IsConvertible(b)
b.IsConvertible(a)

func (Void) IsEquatable

func (Void) IsEquatable(Type) bool

IsEquatable returns true if a value of this type can be checked for equality (i.e. with '==' or '!=') with a value of another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsEquatable(b)
b.IsEquatable(a)

func (Void) IsIdentical

func (Void) IsIdentical(Type) bool

IsIdentical returns true if this type is identical to another type and false otherwise.

This method is commutative; both of the following expressions will always evaluate to the same value:

a.IsIdentical(b)
b.IsIdentical(a)

func (Void) Name

func (Void) Name() string

Name returns the declared name for the type.

func (Void) Normalized

func (Void) Normalized() string

Normalized returns the normalized name for the type.

func (Void) String

func (Void) String() string

Jump to

Keyboard shortcuts

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