Documentation
¶
Index ¶
- Constants
- Variables
- func NewDirectiveResolver(fm *document.Frontmatter) interpreter.DirectiveResolver
- type BlockDiagnostic
- type CalculationIndicator
- type DiagnosticSeverity
- type Evaluator
- func (e *Evaluator) Diagnostics() []BlockDiagnostic
- func (e *Evaluator) Evaluate(doc *document.Document) error
- func (e *Evaluator) EvaluateAffectedBlocks(doc *document.Document, blockIDs []string) error
- func (e *Evaluator) EvaluateBlock(doc *document.Document, blockID string) error
- func (e *Evaluator) GetDisplayFormatter() display.Formatter
- func (e *Evaluator) GetEnvironment() *interpreter.Environment
- func (e *Evaluator) SetDisplayFormatter(df display.Formatter)
Constants ¶
const ( // DiagLikelyCalculation indicates a line that looks like an assignment // but failed to parse as a calculation. DiagLikelyCalculation = "LIKELY_CALCULATION" )
Diagnostic codes
Variables ¶
var ErrPartialEvaluation = errors.New("partial evaluation: one or more blocks had errors")
ErrPartialEvaluation is returned when evaluation continued past errors. Callers can check errors.Is(err, ErrPartialEvaluation) to distinguish partial evaluation (some blocks failed) from total failure.
Functions ¶
func NewDirectiveResolver ¶ added in v1.6.2
func NewDirectiveResolver(fm *document.Frontmatter) interpreter.DirectiveResolver
NewDirectiveResolver creates an interpreter.DirectiveResolver that adapts *document.Frontmatter for @directive resolution. Used by both the document evaluator and the top-level Eval API.
Types ¶
type BlockDiagnostic ¶
type BlockDiagnostic struct {
BlockID string // ID of the block containing the issue
Line int // Line number within block (1-indexed)
Severity DiagnosticSeverity // Warning or Error
Code string // Diagnostic code (e.g., "LIKELY_CALCULATION")
Message string // Human-readable message
Source string // The problematic line content
}
BlockDiagnostic represents a warning or error for a specific line in a block.
type CalculationIndicator ¶
type CalculationIndicator struct {
Name string // Short name for the indicator
Description string // Human-readable description
Check func(tokens []lexer.Token) bool // Returns true if pattern matches
}
CalculationIndicator defines a pattern that suggests a line was intended to be a calculation. Each indicator has a check function and description.
func GetCalculationIndicators ¶
func GetCalculationIndicators() []CalculationIndicator
GetCalculationIndicators returns the list of patterns used to detect likely calculation attempts. This is useful for documentation and debugging.
type DiagnosticSeverity ¶
type DiagnosticSeverity int
DiagnosticSeverity indicates the severity of a diagnostic.
const ( // Warning indicates a potential problem that doesn't prevent evaluation. Warning DiagnosticSeverity = iota // Error indicates a problem that prevents evaluation. Error )
func (DiagnosticSeverity) String ¶
func (s DiagnosticSeverity) String() string
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates CalcMark documents using the interpreter. This lives in impl/ because it performs execution, not just validation.
func (*Evaluator) Diagnostics ¶
func (e *Evaluator) Diagnostics() []BlockDiagnostic
Diagnostics returns warnings and errors collected during evaluation. This includes warnings about TextBlock lines that look like failed calculations.
func (*Evaluator) Evaluate ¶
Evaluate evaluates all blocks in the document in dependency order. CalcBlocks are evaluated top-down with accumulated environment. TextBlocks are checked for lines that look like failed calculations.
Returns an error if any CalcBlock fails to evaluate. Use Diagnostics() to get warnings about TextBlocks with likely calculation errors.
func (*Evaluator) EvaluateAffectedBlocks ¶
EvaluateAffectedBlocks efficiently re-evaluates only the specified blocks. This is the surgical API for WYSIWYG editors that need minimal updates.
Usage:
result, _ := doc.InsertBlock(afterID, BlockCalculation, source) orderedBlocks := doc.GetBlocksInDependencyOrder(result.AffectedBlockIDs) eval.EvaluateAffectedBlocks(doc, orderedBlocks)
The blocks should be in dependency order (use GetBlocksInDependencyOrder). The environment is NOT reset - it maintains accumulated state from previous evaluations.
func (*Evaluator) EvaluateBlock ¶
EvaluateBlock evaluates a single block and re-evaluates all blocks for reactive semantics. This is the simple API for REPL usage where full consistency is needed.
For WYSIWYG editors that need surgical updates, use EvaluateAffectedBlocks instead with the AffectedBlockIDs from InsertBlock/ReplaceBlockSource.
func (*Evaluator) GetDisplayFormatter ¶ added in v1.8.4
GetDisplayFormatter returns the evaluator's display formatter for use by output formatters. After Evaluate(), this includes measurement conventions wired from frontmatter.
func (*Evaluator) GetEnvironment ¶
func (e *Evaluator) GetEnvironment() *interpreter.Environment
GetEnvironment returns the interpreter's environment. Useful for accessing current variable values.
func (*Evaluator) SetDisplayFormatter ¶ added in v1.8.0
SetDisplayFormatter sets the display formatter used for {{var}} interpolation in TextBlocks. If not set, a default en-US formatter is used.