exprs

package
v0.0.0-...-3d60dd8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exprs answers, without the values, what go-tony evaluates in a charter's strings: which expressions a string holds, and which names each one reads.

A charter's values are expanded by go-tony (eval.ExpandStringWithOptions for text, eval.ExpandIRWithOptions for a value that is one `.[…]`), and a firing binds the names they read. Several things are decided before there are values to evaluate against: whether a value is bound at all (Templated), which part of the subject a firing has to read at a revision (Reads), and, at install, what a derive or a ceiling may assume about a value it cannot know yet. Each of those asks this package, so that what is decided and what is evaluated are the same expressions.

Index

Constants

View Source
const Env = "$env"

Env is expr-lang's name for the environment itself. `$env["pr-number"]` is a read of `pr-number`, and `$env` alone, or under a step that is not a constant, reads every name.

Variables

This section is empty.

Functions

func Templated

func Templated(v string) bool

Templated is whether v holds an expression a firing replaces: a `$[…]`, or a v that is one `.[…]` and nothing else (Whole). A `$` that opens none is text, as it is where the value is used: `$HOME`, `$5`; and so is a `.[` in a value it is not the whole of.

It is the cheap test, and errs toward bound: `$$[` and a `$[` nothing closes are text to the expansion and Templated here. Expressions is the exact one.

func Whole

func Whole(v string) bool

Whole is whether v is one `.[…]` and nothing else, which a firing replaces whole with the expression's value: the test the expansion makes (eval.GetRaw).

Types

type Path

type Path []string

Path is a name an expression reads from its environment, then each field or index under it that the expression names as a constant: `subject.value.round` and `subject?.value["round"]` are [subject value round], `items[0].id` is [items 0 id], and `items[i].id` is [items], since which element is not known until the expression runs (and `i` is a read of its own).

func Reads

func Reads(expr string) ([]Path, error)

Reads is every name expr reads from its environment, as a Path each, in the order they are written; a name read twice is there twice.

A name the expression binds itself is not a read: one a `let` declares, within the expression the `let` is over, and `#` and the `.field` shorthand inside a predicate (`filter`, `map`, `all`, …), which are the element being walked. So `data.findings | filter(.status == "open")` reads `data.findings`, and nothing named `status`. A function's name is not a read either.

An expression that does not parse answers the parser's error, and no reads.

func ReadsIn

func ReadsIn(s string) ([]Path, error)

ReadsIn is Reads over every expression of s (Expressions), the first error stopping it.

type Span

type Span struct {
	Expr       string
	Start, End int
}

Span is one expression in a string: its text as the evaluator gets it, escapes undone and trimmed, and where it stands, Start at its `$[` or `.[` and End just past its `]`.

func Expressions

func Expressions(s string) []Span

Expressions is each expression go-tony's expansion evaluates in s, in order: s whole, where it is one `.[…]` and nothing else (Whole), and otherwise each `$[…]`. `$$[` is a literal `$[`, and a `$[` that nothing closes is text to the end of s.

The scan is go-tony's own (eval's scanExpression, which is unexported: tony-format issue y5n12a3gh12kraxfx5n0 asks for it), copied rather than approximated, so a nested bracket, a `]` in a quoted string and an escaped `\]` end an expression here where they end it there.

Jump to

Keyboard shortcuts

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