Documentation
¶
Index ¶
- Constants
- Variables
- func Format(spec string, args []starlark.Value) (string, error)
- func FormatArgs(value starlark.Value) []starlark.Value
- func IsPredeclared(name string) bool
- func IsReserved(name string) bool
- func IsUniversal(name string) bool
- func Str(value starlark.Value) string
- func Strftime(when gotime.Time, spec string) string
- func Truth(value starlark.Value) bool
- type Decimal
- func (dec Decimal) BigInt() *big.Int
- func (dec Decimal) Binary(op syntax.Token, operand starlark.Value, side starlark.Side) (starlark.Value, error)
- func (dec Decimal) CompareSameType(op syntax.Token, operand starlark.Value, depth int) (bool, error)
- func (dec Decimal) Float() float64
- func (dec Decimal) Freeze()
- func (dec Decimal) Hash() (uint32, error)
- func (dec Decimal) Neg() starlark.Value
- func (dec Decimal) Quantize(places int32) Decimal
- func (dec Decimal) String() string
- func (dec Decimal) Truth() starlark.Bool
- func (dec Decimal) Type() string
- func (dec Decimal) Unary(op syntax.Token) (starlark.Value, error)
- type Namespace
- type Program
- type Record
- func (record *Record) Attr(name string) (starlark.Value, error)
- func (record *Record) AttrNames() []string
- func (record *Record) Freeze()
- func (record *Record) Get(keyValue starlark.Value) (starlark.Value, bool, error)
- func (record *Record) Hash() (uint32, error)
- func (record *Record) Keys() []string
- func (record *Record) String() string
- func (record *Record) Truth() starlark.Bool
- func (record *Record) Type() string
Constants ¶
const FinalName = "FINAL"
FinalName is the namespace through which end-of-scope values are read.
Variables ¶
var PositionNames = []string{"VERTICAL_POSITION", "VERTICAL_SPACE"}
PositionNames are the two predefined names whose value depends on where in the frame a band lands. A band whose expressions read either is not cached.
var Predeclared = starlark.StringDict{ "math": starmath.Module, "time": timeModule, "strftime": starlark.NewBuiltin("strftime", builtinStrftime), "format": starlark.NewBuiltin("format", builtinFormat), "decimal": starlark.NewBuiltin("decimal", builtinDecimal), "quantize": starlark.NewBuiltin("quantize", builtinQuantize), "float": starlark.NewBuiltin("float", builtinFloat), "int": starlark.NewBuiltin("int", builtinInt), }
Predeclared is the fixed part of every expression's environment: the modules and the engine's own builtins. Names here resolve ahead of parameters, variables, and record fields, which is why a template may not reuse one.
var PredefinedNames = []string{
"THIS",
"ITEM_NUMBER",
"DATA_COUNT",
"REPORT_COUNT",
"PAGE_COUNT",
"COLUMN_COUNT",
"PAGE_NUMBER",
"COLUMN_NUMBER",
"VERTICAL_POSITION",
"VERTICAL_SPACE",
"BUILD_TIME",
"FINAL",
}
PredefinedNames are the names the engine supplies to every expression, per doc/expressions.md#predefined-variables. Per-group names -- <group>_COUNT and <group>_PAGE_NUMBER -- are added by the template.
Functions ¶
func Format ¶
Format applies a %-style specification to the arguments.
This is the engine's formatter, reached from a field's or barcode's `format=` property and from the `format` builtin. Unlike Starlark's own `%` operator it supports the full set of flags, width, and precision, which is why numeric presentation belongs here rather than inside an expression.
func FormatArgs ¶
FormatArgs turns an expression result into the argument list a format specification consumes. A tuple spreads positionally; anything else is a single argument.
func IsPredeclared ¶
IsPredeclared reports whether a name is supplied by the fixed environment.
func IsReserved ¶
IsReserved reports whether a name is unavailable for a parameter, variable, or group because resolution puts something else first.
func IsUniversal ¶
IsUniversal reports whether a name is a Starlark builtin the dialect keeps.
func Str ¶
Str renders a value the way %s does: a string is itself, everything else is its Starlark string form.
func Strftime ¶
Strftime formats a time with the familiar % directives. It is locale-independent: month and day names are English.
Types ¶
type Decimal ¶
Decimal is an exact decimal value, declared by member type="decimal".
Arithmetic between decimals, and between a decimal and an int, is exact; the result's scale is what exactness requires. Division quantizes to six fractional digits, rounding half away from zero. Mixing a decimal with a float is an error rather than a silent conversion.
func NewDecimal ¶
NewDecimal wraps a decimal.Decimal as a Starlark value.
func ParseDecimal ¶
ParseDecimal parses plain decimal text.
func (Decimal) Binary ¶
func (dec Decimal) Binary( op syntax.Token, operand starlark.Value, side starlark.Side, ) (starlark.Value, error)
Binary implements decimal arithmetic.
func (Decimal) CompareSameType ¶
func (dec Decimal) CompareSameType( op syntax.Token, operand starlark.Value, depth int, ) (bool, error)
Cmp orders decimals against decimals and ints.
func (Decimal) String ¶
String renders the value as plain decimal text, with no exponent.
The scale is preserved rather than trimmed: exactness decides how many fractional digits a result has, so adding two 2-place values shows two places and multiplying them shows four.
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace is a fixed set of named values reachable by attribute, used for FINAL.
func NewNamespace ¶
NewNamespace builds a namespace.
type Program ¶
type Program struct {
// Source is the expression as written.
Source string
// Where names the template file, node path, and property, for diagnostics.
Where string
// Params are the free names, in the order the function takes them.
Params []string
// FinalNames are the names read through FINAL.
FinalNames []string
// UsesFinal reports whether FINAL appears at all.
UsesFinal bool
// UsesPosition reports whether the expression reads VERTICAL_POSITION
// or VERTICAL_SPACE, which is what makes a band's measurement uncacheable.
UsesPosition bool
// contains filtered or unexported fields
}
Program is one compiled template expression.
Compilation happens once, at template load. The expression becomes a function whose parameters are exactly the names it references, so an evaluation costs one call with those values and nothing scales with the number of columns in the data.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is a data record, or a nested JSON object declared type="object".
It supports both attribute access and subscripting, so a field is reachable as THIS.amount and as THIS["odd name"]. It is immutable, and true whenever it exists — an empty record is still true, which is why record truth is defined as "not None".
func (*Record) Get ¶
Get implements subscripting, which is how a field whose name is not a valid identifier, or one that `records` does not declare, is reached.