...

Package internal

import "cuelang.org/go/internal"
Overview
Index
Subdirectories

Overview ▾

Package internal exposes some cue internals to other packages.

A better name for this package would be technicaldebt.

Index ▾

Constants
Variables
func ConstraintToken(f *ast.Field) (t token.Token, ok bool)
func DecorateError(info error, err errors.Error) errors.Error
func EmbedStruct(s *ast.StructLit) *ast.EmbedDecl
func FileComment(f *ast.File) *ast.CommentGroup
func GenPath(root string) string
func IsDef(s string) bool
func IsDefOrHidden(s string) bool
func IsDefinition(label ast.Label) bool
func IsEllipsis(x ast.Decl) bool
func IsHidden(s string) bool
func IsRegularField(f *ast.Field) bool
func ListEllipsis(n *ast.ListLit) (elts []ast.Expr, e *ast.Ellipsis)
func NewAttr(name, str string) *ast.Attribute
func NewComment(isDoc bool, s string) *ast.CommentGroup
func PackageInfo(f *ast.File) (p *ast.Package, name string, tok token.Pos)
func SetConstraint(f *ast.Field, t token.Token)
func SetPackage(f *ast.File, name string, overwrite bool)
func ToExpr(n ast.Node) ast.Expr
func ToFile(n ast.Node) *ast.File
func Version(minor, patch int) int
type Attr
    func NewNonExisting(key string) Attr
    func ParseAttrBody(pos token.Pos, s string) (a Attr)
    func (a *Attr) Flag(pos int, key string) (bool, error)
    func (a *Attr) Int(pos int) (int64, error)
    func (a *Attr) Lookup(pos int, key string) (val string, found bool, err error)
    func (a *Attr) String(pos int) (string, error)
type AttrKind
type Context
    func (c Context) Quo(d, x, y *apd.Decimal) (apd.Condition, error)
    func (c Context) Sqrt(d, x *apd.Decimal) (apd.Condition, error)
    func (c Context) WithPrecision(p uint32) Context
type Decimal
type EvaluatorVersion
type KeyValue
    func (kv *KeyValue) Key() string
    func (kv *KeyValue) Text() string
    func (kv *KeyValue) Value() string
type PkgInfo
    func GetPackageInfo(f *ast.File) PkgInfo
    func (p *PkgInfo) IsAnonymous() bool

Package files

attrs.go internal.go

Constants

const (
    MinorCurrent   = 5
    MinorSupported = 4
    PatchSupported = 0
)

MaxDepth indicates the maximum evaluation depth. This is there to break cycles in the absence of cycle detection.

It is registered in a central place to make it easy to find all spots where cycles are broken in this brute-force manner.

TODO(eval): have cycle detection.

const MaxDepth = 20

Variables

APIVersionSupported is the back version until which deprecated features are still supported.

var APIVersionSupported = Version(MinorSupported, PatchSupported)

BaseContext is used as CUE's default context for arbitrary-precision decimals.

var BaseContext = Context{*apd.BaseContext.WithPrecision(34)}

ErrIncomplete can be used by builtins to signal the evaluation was incomplete.

var ErrIncomplete = errors.New("incomplete value")
var ErrInexact = errors.New("inexact subsumption")

MakeInstance makes a new instance from a value.

var MakeInstance func(value interface{}) (instance interface{})

func ConstraintToken

func ConstraintToken(f *ast.Field) (t token.Token, ok bool)

ConstraintToken reports which constraint token (? or !) is associated with a field (if any), taking into account compatibility of deprecated fields.

func DecorateError

func DecorateError(info error, err errors.Error) errors.Error

func EmbedStruct

func EmbedStruct(s *ast.StructLit) *ast.EmbedDecl

func FileComment

func FileComment(f *ast.File) *ast.CommentGroup

func GenPath

func GenPath(root string) string

GenPath reports the directory in which to store generated files.

func IsDef

func IsDef(s string) bool

func IsDefOrHidden

func IsDefOrHidden(s string) bool

func IsDefinition

func IsDefinition(label ast.Label) bool

func IsEllipsis

func IsEllipsis(x ast.Decl) bool

IsEllipsis reports whether the declaration can be represented as an ellipsis.

func IsHidden

func IsHidden(s string) bool

func IsRegularField

func IsRegularField(f *ast.Field) bool

func ListEllipsis

func ListEllipsis(n *ast.ListLit) (elts []ast.Expr, e *ast.Ellipsis)

ListEllipsis reports the list type and remaining elements of a list. If we ever relax the usage of ellipsis, this function will likely change. Using this function will ensure keeping correct behavior or causing a compiler failure.

func NewAttr

func NewAttr(name, str string) *ast.Attribute

func NewComment

func NewComment(isDoc bool, s string) *ast.CommentGroup

NewComment creates a new CommentGroup from the given text. Each line is prefixed with "//" and the last newline is removed. Useful for ASTs generated by code other than the CUE parser.

func PackageInfo

func PackageInfo(f *ast.File) (p *ast.Package, name string, tok token.Pos)

Deprecated: use GetPackageInfo

func SetConstraint

func SetConstraint(f *ast.Field, t token.Token)

SetConstraints sets both the main and deprecated fields of f according to the given constraint token.

func SetPackage

func SetPackage(f *ast.File, name string, overwrite bool)

func ToExpr

func ToExpr(n ast.Node) ast.Expr

ToExpr converts a node to an expression. If it is a file, it will return it as a struct. If is an expression, it will return it as is. Otherwise it panics.

func ToFile

func ToFile(n ast.Node) *ast.File

ToFile converts an expression to a file.

Adjusts the spacing of x when needed.

func Version

func Version(minor, patch int) int

type Attr

Attr holds positional information for a single Attr.

type Attr struct {
    Name   string // e.g. "json" or "protobuf"
    Body   string
    Kind   AttrKind
    Fields []KeyValue
    Err    errors.Error
}

func NewNonExisting

func NewNonExisting(key string) Attr

NewNonExisting creates a non-existing attribute.

func ParseAttrBody

func ParseAttrBody(pos token.Pos, s string) (a Attr)

func (*Attr) Flag

func (a *Attr) Flag(pos int, key string) (bool, error)

Flag reports whether an entry with the given name exists at position pos or onwards or an error if the attribute is invalid or if the first pos-1 entries are not defined.

func (*Attr) Int

func (a *Attr) Int(pos int) (int64, error)

Int reports the integer at the given position or an error if the attribute is invalid, the position does not exist, or the value at the given position is not an integer.

func (*Attr) Lookup

func (a *Attr) Lookup(pos int, key string) (val string, found bool, err error)

Lookup searches for an entry of the form key=value from position pos onwards and reports the value if found. It reports an error if the attribute is invalid or if the first pos-1 entries are not defined.

func (*Attr) String

func (a *Attr) String(pos int) (string, error)

String reports the possibly empty string value at the given position or an error the attribute is invalid or if the position does not exist.

type AttrKind

AttrKind indicates the location of an attribute within CUE source.

type AttrKind uint8
const (
    // FieldAttr indicates an attribute is a field attribute.
    // foo: bar @attr()
    FieldAttr AttrKind = 1 << iota

    // DeclAttr indicates an attribute was specified at a declaration position.
    // foo: {
    //     @attr()
    // }
    DeclAttr
)

type Context

Context wraps apd.Context for CUE's custom logic.

Note that it avoids pointers to make it easier to make copies.

type Context struct {
    apd.Context
}

func (Context) Quo

func (c Context) Quo(d, x, y *apd.Decimal) (apd.Condition, error)

func (Context) Sqrt

func (c Context) Sqrt(d, x *apd.Decimal) (apd.Condition, error)

func (Context) WithPrecision

func (c Context) WithPrecision(p uint32) Context

WithPrecision mirrors upstream, but returning our type without a pointer.

type Decimal

A Decimal is an arbitrary-precision binary-coded decimal number.

Right now Decimal is aliased to apd.Decimal. This may change in the future.

type Decimal = apd.Decimal

type EvaluatorVersion

type EvaluatorVersion int
const (
    DefaultVersion EvaluatorVersion = iota

    // The DevVersion is used for new implementations of the evaluator that
    // do not cover all features of the CUE language yet.
    DevVersion
)

type KeyValue

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

func (*KeyValue) Key

func (kv *KeyValue) Key() string

func (*KeyValue) Text

func (kv *KeyValue) Text() string

func (*KeyValue) Value

func (kv *KeyValue) Value() string

type PkgInfo

type PkgInfo struct {
    Package *ast.Package
    Index   int // position in File.Decls
    Name    string
}

func GetPackageInfo

func GetPackageInfo(f *ast.File) PkgInfo

func (*PkgInfo) IsAnonymous

func (p *PkgInfo) IsAnonymous() bool

IsAnonymous reports whether the package is anonymous.

Subdirectories

Name Synopsis
..