Documentation ¶
Overview ¶
Package typ provides a xelf type implementation, parser and inference system.
Index ¶
- Variables
- type AltBody
- type AstVal
- func (v *AstVal) As(t Type) (LitVal, error)
- func (v *AstVal) Assign(o LitVal) error
- func (v *AstVal) MarshalJSON() ([]byte, error)
- func (v *AstVal) Mut() LitMut
- func (v *AstVal) New() LitMut
- func (v *AstVal) Nil() bool
- func (v *AstVal) Parse(a ast.Ast) error
- func (v *AstVal) Print(p *bfr.P) error
- func (v *AstVal) Ptr() interface{}
- func (v *AstVal) String() string
- func (v *AstVal) Type() Type
- func (v *AstVal) UnmarshalJSON(b []byte) (err error)
- func (v *AstVal) Value() LitVal
- func (v *AstVal) Zero() bool
- type Body
- type BodyPair
- type Const
- type ConstBody
- type EditFunc
- type Editor
- type Hist
- type LitMut
- type LitVal
- type Lookup
- type Null
- type Param
- type ParamBody
- type Sys
- type Type
- func Alt(ts ...Type) Type
- func Bits(n string, cs ...Const) Type
- func CallOf(t Type) Type
- func Clone(r Type) Type
- func ContEl(t Type) Type
- func Deopt(t Type) Type
- func DictOf(t Type) Type
- func Edit(t Type, f EditFunc) (Type, error)
- func El(t Type) Type
- func ElemTupl(t Type) Type
- func Enum(n string, cs ...Const) Type
- func Form(name string, ps ...Param) Type
- func Func(name string, ps ...Param) Type
- func IdxrOf(t Type) Type
- func KeyrOf(t Type) Type
- func Last(t Type) Type
- func ListOf(t Type) Type
- func LitOf(t Type) Type
- func Obj(n string, ps ...Param) Type
- func Opt(t Type) Type
- func ParamTupl(ps ...Param) Type
- func Parse(str string) (Type, error)
- func ParseAst(a ast.Ast) (Type, error)
- func ParseSym(raw string, src ast.Src) (Type, error)
- func Read(r io.Reader, name string) (Type, error)
- func Ref(name string) Type
- func Res(t Type) Type
- func Sel(sel string) Type
- func Select(t Type, path string) (Type, error)
- func SelectIdx(t Type, idx int) (Type, error)
- func SelectKey(t Type, key string) (Type, error)
- func SelectList(t Type, p cor.Path) (r Type, err error)
- func SelectPath(t Type, path cor.Path) (r Type, err error)
- func SymOf(t Type) Type
- func TagOf(t Type) Type
- func ToType(v LitVal) (t Type, err error)
- func TuplEl(t Type) (Type, int)
- func TypOf(t Type) Type
- func Var(id int32, t Type) Type
- func WithID(id int32, t Type) Type
- func WithRef(r string, t Type) Type
- func (t Type) As(o Type) (LitVal, error)
- func (t *Type) Assign(p LitVal) error
- func (t Type) AssignableTo(dst Type) bool
- func (t Type) ConvertibleTo(dst Type) bool
- func (t Type) Equal(o Type) bool
- func (t *Type) EqualBody(b Body, h Hist) bool
- func (t Type) EqualHist(o Type, h Hist) bool
- func (t Type) MarshalJSON() ([]byte, error)
- func (t Type) Mut() LitMut
- func (*Type) New() LitMut
- func (Type) Nil() bool
- func (t *Type) Parse(a ast.Ast) error
- func (t Type) Print(b *bfr.P) error
- func (t *Type) Ptr() interface{}
- func (t Type) ResolvableTo(dst Type) bool
- func (t Type) String() string
- func (t Type) Type() Type
- func (t *Type) UnmarshalJSON(b []byte) error
- func (t Type) Value() LitVal
- func (t Type) Zero() bool
- type Wrap
- func (w Wrap) As(t Type) (LitVal, error)
- func (w *Wrap) Assign(v LitVal) error
- func (w *Wrap) MarshalJSON() ([]byte, error)
- func (w *Wrap) Mut() LitMut
- func (w Wrap) New() (v LitMut)
- func (w *Wrap) Nil() bool
- func (w *Wrap) Parse(a ast.Ast) error
- func (w *Wrap) Print(p *bfr.P) error
- func (w *Wrap) Ptr() interface{}
- func (w *Wrap) String() string
- func (w *Wrap) Type() Type
- func (w *Wrap) UnmarshalJSON(b []byte) error
- func (w *Wrap) Unwrap() LitVal
- func (w *Wrap) Value() LitVal
- func (w *Wrap) Zero() bool
Constants ¶
This section is empty.
Variables ¶
var ( Void = Type{Kind: knd.Void} None = Type{Kind: knd.None} Bool = Type{Kind: knd.Bool} Num = Type{Kind: knd.Num} Int = Type{Kind: knd.Int} Real = Type{Kind: knd.Real} Char = Type{Kind: knd.Char} Str = Type{Kind: knd.Str} Raw = Type{Kind: knd.Raw} UUID = Type{Kind: knd.UUID} Time = Type{Kind: knd.Time} Span = Type{Kind: knd.Span} Lit = Type{Kind: knd.Lit} Typ = Type{Kind: knd.Typ} VarTyp = Type{Kind: knd.Typ | knd.Var, ID: -1} Sym = Type{Kind: knd.Sym} Tag = Type{Kind: knd.Tag} Tupl = Type{Kind: knd.Tupl} Call = Type{Kind: knd.Call} Exp = Type{Kind: knd.Exp} Idxr = Type{Kind: knd.Idxr} Keyr = Type{Kind: knd.Keyr} List = Type{Kind: knd.List} Dict = Type{Kind: knd.Dict} Data = Type{Kind: knd.Data} Spec = Type{Kind: knd.Spec} All = Type{Kind: knd.All} Any = Type{Kind: knd.Any} )
var ( ErrAssign = fmt.Errorf("cannot assign") ErrIdxBounds = fmt.Errorf("index out of bounds") )
var WrapNull = func(t Type) *Wrap { return &Wrap{Typ: t} }
Functions ¶
This section is empty.
Types ¶
type ConstBody ¶
type ConstBody struct {
Consts []Const
}
ConstBody contains a name and a list of constants for the enum and bits types.
func (*ConstBody) FindKeyIndex ¶
func (*ConstBody) FindValIndex ¶
type EditFunc ¶
EditFunc edits a type and returns the result or an error. A copy editor expects returned types that differ from the input to be already copied.
type LitMut ¶
type LitMut interface { LitVal // New returns a fresh mutable value of the same type or an error. New() LitMut // Ptr returns a pointer to the underlying value for interfacing with other go tools. Ptr() interface{} // Assign assigns the given value to this mutable or returns an error. Assign(LitVal) error // Parse reads the given ast into this mutable or returns an error. // The registry parameter is strictly optional, proxies should bring a registry if required. Parse(ast.Ast) error }
LitMut is the common interface of all mutable literal values see lit.Mut for more information. Mutable values should have an UnmarshalJSON method unless the base type is natively supported. This interface does in principle belong to the lit package.
type LitVal ¶
type LitVal interface { Type() Type // Nil returns whether this is a null value. Nil() bool // Zero returns whether this is a zero value. Zero() bool // Value returns a simple value restricted to these types: Null, Bool, Int, Real, Str, Raw, // UUID, Time, Span, Type, Idxr, Keyr and *SpecRef. Value() LitVal // Mut returns the effective mutable itself or a new mutable for this value. Mut() LitMut // As returns the same or a new value with the given type or an error. // The value type must be convertible to the new type and the value conversion must succeed. As(Type) (LitVal, error) // String returns a string content for char literals and xelf format for other literals. // Use bfr.String(v) to get quoted char literals. String() string // Print writes this literal to the given printer or returns an error. Print(*bfr.P) error // MarshalJSON returns the literal as json bytes MarshalJSON() ([]byte, error) }
LitVal is the common interface of all literal values see lit.Val for more information. This interface does in principle belong to the lit package.
type ParamBody ¶
type ParamBody struct {
Params []Param
}
ParamBody contains a name and a list of parameters for obj and spec types.
func (*ParamBody) FindKeyIndex ¶
type Sys ¶
Sys is the resolution context used to instantiate, bind, update and unify types. Type unification is part of sys, because it needs close access to the type variable bindings.
func NewSys ¶
func NewSys() *Sys
NewSys creates and returns an empty type system using the given type registry.
func (*Sys) Bind ¶
Bind binds type t using an existing id or sets a new id and returns the update type.
type Type ¶
Type describes the shape of a xelf expression, literal or value.
func Last ¶
Last returns the last element type if t is a list or dict type otherwise t is returned as is.
func SelectPath ¶
SelectPath returns the selected type from t or an error.
func (Type) AssignableTo ¶
AssignableTo returns whether *all* values represented by type t can be assigned to dst.
func (Type) ConvertibleTo ¶
ConvertibleTo returns whether *any* value represented by type t can be assigned to dst. That means char is convertible to time, but str is not.
func (*Type) EqualBody ¶
A *Type itself can be used as element body for expression and container types.
func (Type) MarshalJSON ¶
func (Type) ResolvableTo ¶
ResolvableTo returns whether the resolved value of t is convertible to the resolved dest. That call|char, call or exp are all possibly resolvable to time, but not call|str.
func (*Type) UnmarshalJSON ¶
type Wrap ¶
Wrap is versatile literal value wrapper. It can generalize the type of a mutable value. It does also provide automatic optional behaviour, a mutable 'any' value and lazy value support.