internal

package
v0.13.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package internal exposes some cue internals to other packages.

A better name for this package would be technicaldebt.

Index

Constants

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

Variables

View Source
var APIVersionSupported = Version(MinorSupported, PatchSupported)

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

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

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

View Source
var ErrIncomplete = errors.New("incomplete value")

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

View Source
var ErrInexact = errors.New("inexact subsumption")

Functions

func ConstraintToken added in v0.6.0

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 EmbedStruct added in v0.2.0

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

func FileComments added in v0.12.0

func FileComments(f *ast.File) (docs, rest []*ast.CommentGroup)

func GenPath added in v0.1.0

func GenPath(root string) string

GenPath reports the directory in which to store generated files.

func IsDef added in v0.2.0

func IsDef(s string) bool

func IsDefOrHidden added in v0.2.0

func IsDefOrHidden(s string) bool

func IsDefinition added in v0.2.0

func IsDefinition(label ast.Label) bool

func IsEllipsis added in v0.1.0

func IsEllipsis(x ast.Decl) bool

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

func IsHidden added in v0.2.0

func IsHidden(s string) bool

func IsRegularField added in v0.2.0

func IsRegularField(f *ast.Field) bool

func ListEllipsis added in v0.0.6

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 MergeDocs added in v0.12.0

func MergeDocs(comments []*ast.CommentGroup) []*ast.CommentGroup

MergeDocs merges multiple doc comments into one single doc comment.

func NewAttr added in v0.1.0

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

func NewComment added in v0.1.0

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 Package added in v0.11.0

func Package(f *ast.File) *ast.Package

Package finds the package declaration from the preamble of a file.

func SetConstraint added in v0.6.0

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 added in v0.2.0

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

func ToExpr added in v0.1.0

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 added in v0.1.0

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

ToFile converts an expression to a file.

Adjusts the spacing of x when needed.

func Version added in v0.5.0

func Version(minor, patch int) int

Types

type Attr added in v0.1.0

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

Attr holds positional information for a single Attr.

func NewNonExisting added in v0.1.0

func NewNonExisting(key string) Attr

NewNonExisting creates a non-existing attribute.

func ParseAttrBody added in v0.1.0

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

func (*Attr) Flag added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

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 added in v0.1.0

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 added in v0.3.0

type AttrKind uint8

AttrKind indicates the location of an attribute within CUE source.

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 added in v0.6.0

type Context struct {
	apd.Context
}

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

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

func (Context) Quo added in v0.6.0

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

func (Context) Sqrt added in v0.6.0

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

func (Context) WithPrecision added in v0.6.0

func (c Context) WithPrecision(p uint32) Context

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

type Decimal added in v0.0.5

type Decimal = apd.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 EvaluatorVersion added in v0.8.0

type EvaluatorVersion int

EvaluatorVersion is declared here so it can be used everywhere without import cycles, but the canonical documentation lives at cuelang.org/go/cue/cuecontext.EvalVersion.

TODO(mvdan): rename to EvalVersion for consistency with cuecontext.

const (
	// EvalVersionUnset is the zero value, which signals that no evaluator version is provided.
	EvalVersionUnset EvaluatorVersion = 0

	// DefaultVersion is a special value as it selects a version depending on the current
	// value of CUE_EXPERIMENT. It exists separately to [EvalVersionUnset], even though both
	// implement the same version selection logic, so that we can distinguish between
	// a user explicitly asking for the default version versus an entirely unset version.
	DefaultVersion EvaluatorVersion = -1 // TODO(mvdan): rename to EvalDefault for consistency with cuecontext

	EvalV2 EvaluatorVersion = 2
	EvalV3 EvaluatorVersion = 3

	StableVersion = EvalV3 // TODO(mvdan): rename to EvalStable for consistency with cuecontext
	DevVersion    = EvalV3 // TODO(mvdan): rename to EvalExperiment for consistency with cuecontext
)

type KeyValue added in v0.3.0

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

func (*KeyValue) Key added in v0.3.0

func (kv *KeyValue) Key() string

func (*KeyValue) Text added in v0.3.0

func (kv *KeyValue) Text() string

func (*KeyValue) Value added in v0.3.0

func (kv *KeyValue) Value() string

Directories

Path Synopsis
Package buildattr implements support for interpreting the @if build attributes in CUE files.
Package buildattr implements support for interpreting the @if build attributes in CUE files.
ci
cmd
Package copy provides utilities to copy files and directories.
Package copy provides utilities to copy files and directories.
core
Package cueconfig holds internal API relating to CUE configuration.
Package cueconfig holds internal API relating to CUE configuration.
Package cueimports provides support for reading the import section of a CUE file without needing to read the rest of it.
Package cueimports provides support for reading the import section of a CUE file without needing to read the rest of it.
Package testing is a helper package for test packages in the CUE project.
Package testing is a helper package for test packages in the CUE project.
Package testing is a helper package for test packages in the CUE project.
Package testing is a helper package for test packages in the CUE project.
Package cueversion provides access to the version of the cuelang.org/go module.
Package cueversion provides access to the version of the cuelang.org/go module.
golangorgx
mod
Package par implements parallel execution helpers.
Package par implements parallel execution helpers.
Package source contains utility functions that standardize reading source bytes across cue packages.
Package source contains utility functions that standardize reading source bytes across cue packages.
Package task provides a registry for tasks to be used by commands.
Package task provides a registry for tasks to be used by commands.
Package tdtest provides support for table-driven testing.
Package tdtest provides support for table-driven testing.
Package value contains functions for converting values to internal types and various other Value-related utilities.
Package value contains functions for converting values to internal types and various other Value-related utilities.
Package vcs provides access to operations on the version control systems supported by the source field in module.cue.
Package vcs provides access to operations on the version control systems supported by the source field in module.cue.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳