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 ¶
IsModuleName reports whether the resolver bound an identifier at module scope.
Types ¶
type Namer ¶
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}.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table holds a file's module constants by name.
func Collect ¶
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.