scriptconst

package
v1.137.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package scriptconst reads the names a managed script defines once, at module level, from literals, and renders an expression as the text it evaluates to when every part of it is known from the source.

Two readers of a script's source need the same answer. scriptrun.Validate reports the connections, tools and destinations a script names, and a script that writes WAREHOUSE = "warehouse" and then connection=WAREHOUSE names the warehouse connection as plainly as one that writes the string at the call. The flow graph (internal/platform/scriptflow) shows the same value on the step. One resolver keeps the two from disagreeing about what a name is.

A constant is decided from the resolved syntax tree, never from spelling: an identifier refers to a module constant only when the Starlark resolver bound it at module scope, so a function parameter or a local that happens to share the constant's name is not read as the constant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsModuleName

func IsModuleName(id *syntax.Ident) bool

IsModuleName reports whether the resolver bound an identifier at module scope.

Types

type Namer

type Namer func(id *syntax.Ident) (string, bool)

Namer renders one identifier: its text, and whether that text is the value rather than a stand-in for a computed one.

type Renderer

type Renderer struct {
	// Name renders an identifier. Nil renders every identifier as {name}.
	Name Namer
	// Source returns an expression's source text, for the {…} stand-in. Nil
	// writes {…}.
	Source func(syntax.Expr) string
	// contains filtered or unexported fields
}

Renderer renders an expression as text. Literals and the names its Namer knows are written as their values; string concatenation, "...".format(...), "..." % (...) and sep.join([...]) are rendered with each part filled in, and template.replace(...) as the template, computed; any part that cannot be read from the source is written as {its source text}.

func (*Renderer) Nested

func (r *Renderer) Nested(e syntax.Expr) (string, bool)

Nested renders e one level deeper, for a Namer that renders a variable by rendering the expression it was assigned.

func (*Renderer) Render

func (r *Renderer) Render(e syntax.Expr) (string, bool)

Render renders e, reporting whether every part of it was known.

type Table

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

Table holds a file's module constants by name.

func Collect

func Collect(file *syntax.File) Table

Collect returns the module constants of a parsed and resolved file.

A name is a constant when the module binds it exactly once, with a plain assignment written directly in the file's top-level statements, to an expression that renders fully from literals and constants bound before it. Every other binding of the name anywhere in the module counts against it, so a name reassigned, augmented, or also bound by a top-level for loop is not a constant. An assignment inside a top-level if or for is not a candidate either: whether it ran is a run-time fact.

The file must have been resolved (resolve.File, or starlark.FileProgram); on an unresolved file no identifier carries a module binding and the table resolves nothing, which is the safe answer.

func (Table) Len

func (t Table) Len() int

Len reports how many constants the table holds.

func (Table) String

func (t Table) String(e syntax.Expr) (string, bool)

String returns the text an expression is known to be from the source alone: a string literal, a module constant, or string building over those ("prod-" + REGION, "{}-drop".format(ACME)). A part that is computed at run time, or a value that is not a string, reports false.

func (Table) Value

func (t Table) Value(id *syntax.Ident) (string, bool)

Value returns the constant an identifier refers to. It reports false for an identifier the resolver did not bind at module scope, whatever its name.

Jump to

Keyboard shortcuts

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