source

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0, MIT Imports: 2 Imported by: 1 module, 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 source defines source locations, diagnostics, and resource limits.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

type Code string

Code is a stable diagnostic identifier. Codes may be added over time, but existing semantic meanings should remain stable.

const (
	CodeSyntax              Code = "syntax"
	CodeUnknownCommand      Code = "unknown-command"
	CodeUnknownSymbol       Code = "unknown-symbol"
	CodeMissingArgument     Code = "missing-argument"
	CodeUnclosedGroup       Code = "unclosed-group"
	CodeUnexpectedToken     Code = "unexpected-token"
	CodeUnsupported         Code = "unsupported"
	CodeInvalidValue        Code = "invalid-value"
	CodeInvalidEnvironment  Code = "invalid-environment"
	CodeUnknownVariable     Code = "unknown-variable"
	CodeDuplicateLabel      Code = "duplicate-label"
	CodeUnresolvedReference Code = "unresolved-reference"
	CodeMissingGlyph        Code = "missing-glyph"
	CodeInsufficientStretch Code = "insufficient-stretch"
	CodeTextUnsupported     Code = "text-unsupported"
	CodeLimitExceeded       Code = "limit-exceeded"
	CodeCanceled            Code = "canceled"
	CodeInternal            Code = "internal"
	CodeDeprecated          Code = "deprecated"
)

type Diagnostic

type Diagnostic struct {
	Range    Range
	Severity Severity
	Code     Code
	Message  string
	Args     []string
	Hints    []string
}

Diagnostic describes a recoverable source problem.

func NormalizeDiagnostics

func NormalizeDiagnostics(in []Diagnostic) []Diagnostic

NormalizeDiagnostics filters invalid ranges, copies the slice, and returns a deterministic ordering by source position, severity, code, and message.

func NormalizeDiagnosticsFor

func NormalizeDiagnosticsFor(in []Diagnostic, sourceLen int) []Diagnostic

NormalizeDiagnosticsFor filters diagnostics whose ranges fall outside a source string, copies retained data, and returns a deterministic ordering.

func (Diagnostic) Clone

func (d Diagnostic) Clone() Diagnostic

Clone returns an independent copy.

func (Diagnostic) Error

func (d Diagnostic) Error() string

Error returns the English diagnostic message.

type Limits

type Limits struct {
	MaxSourceBytes     int
	MaxTokens          int
	MaxNesting         int
	MaxNodes           int
	MaxMacroExpansions int
	MaxExpandedTokens  int
	MaxCallDepth       int
	MaxTableCells      int
	MaxAssemblyRepeats int
	MaxTextBytes       int
	MaxOutputItems     int
	MaxPathSegments    int
	MaxDimension       int64
}

Limits bound work for untrusted input. Zero fields are replaced with Default Limits by WithDefaults. Negative fields are also replaced with defaults so a zero-value Limits cannot accidentally become unbounded.

Enforcement is split by layer: parsers enforce token, expansion, call, and table-cell limits; ir.Validate enforces source, node, nesting, text, and dimension limits; internal/layout enforces output-item and path-segment limits. Font assembly adapters enforce MaxAssemblyRepeats.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns conservative limits suitable for interactive formulas.

func (Limits) WithDefaults

func (l Limits) WithDefaults() Limits

WithDefaults returns a copy where non-positive fields use defaults.

type Range

type Range struct {
	Start int
	End   int
}

Range is a half-open UTF-8 byte range in a source string.

The zero Range denotes the empty range at the start of a source. A detached range has Start and End both negative.

func Detached

func Detached() Range

Detached returns a range that is not associated with source text.

func Merge

func Merge(a, b Range) Range

Merge returns the smallest range containing both inputs. Detached inputs are ignored. If both inputs are detached, the result is detached.

func NewRange

func NewRange(start, end int) Range

NewRange returns a source range.

func (Range) Contains

func (r Range) Contains(pos int) bool

Contains reports whether pos lies inside r. End is exclusive.

func (Range) ContainsRange

func (r Range) ContainsRange(inner Range) bool

ContainsRange reports whether inner lies entirely within r.

func (Range) IsDetached

func (r Range) IsDetached() bool

IsDetached reports whether r is not associated with source text.

func (Range) IsValid

func (r Range) IsValid() bool

IsValid reports whether r is either detached or a valid half-open range.

func (Range) IsValidFor

func (r Range) IsValidFor(sourceLen int) bool

IsValidFor reports whether r is detached or lies within a source string of sourceLen bytes.

func (Range) Len

func (r Range) Len() int

Len returns the byte length of the range.

func (Range) Slice

func (r Range) Slice(src string) []byte

Slice returns the bytes selected by r. Invalid and detached ranges return nil.

type Severity

type Severity uint8

Severity is the importance of a diagnostic.

const (
	SeverityError Severity = iota
	SeverityWarning
	SeverityInfo
)

Jump to

Keyboard shortcuts

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