Documentation
¶
Overview ¶
Package calcmark provides a clean, idiomatic Go API for evaluating CalcMark expressions and documents.
CalcMark is a calculation-oriented markup language that combines markdown with inline calculations.
Basic usage:
result, err := calcmark.Eval("1 + 1")
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Value) // 2
Stateful sessions (for live editors):
session := calcmark.NewSession()
session.Eval("x = 10")
result, _ := session.Eval("x + 5")
fmt.Println(result.Value) // 15
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Convert ¶ added in v1.9.0
Convert processes CalcMark input and returns formatted output.
In CM mode, the entire input is parsed as a CalcMark document, evaluated, and formatted to the requested output format.
In Embedded mode, the input is scanned for cm/calcmark fenced code blocks. Each block is evaluated independently and replaced with its formatted output. Surrounding Markdown prose passes through unchanged. Embedded mode supports "md" and "html" formats only.
HTML output returns a fragment by default (no <html>/<head>/<body> wrapper). When Template is set, the fragment is wrapped using the provided Go template.
In Embedded mode, Convert may return both a non-empty result and a non-nil error when some CalcMark blocks fail evaluation. The result contains inline error markers (blockquotes in Markdown, or their HTML rendering) and is still useful for display. The error reports the count of failed blocks.
Types ¶
type Diagnostic ¶
type Diagnostic struct {
Severity Severity
Code string
Message string
Detailed string // Detailed explanation with context and guidance
}
Diagnostic represents a semantic issue (error, warning, or hint).
type Options ¶ added in v1.9.0
type Options struct {
Mode Mode // CM or Embedded (default: CM)
Format string // Output format: "html", "md", "text", "json" (default: "html")
Template string // Go template content for wrapping HTML output (optional)
Locale string // BCP 47 locale for number formatting (default: "en-US")
}
Options configures the Convert pipeline.
type Result ¶
type Result struct {
// Value is the final computed value (for single expressions).
// For multi-line documents, this is the last value.
Value types.Type
// AllValues contains all computed values (for multi-line documents).
AllValues []types.Type
// Diagnostics contains any errors, warnings, or hints from semantic analysis.
Diagnostics []Diagnostic
}
Result contains the evaluation results and any diagnostics.
func Eval ¶
Eval evaluates a CalcMark expression or document and returns the result. For single-line expressions, returns the computed value. For multi-line documents, returns per-line results.
Example:
result, err := calcmark.Eval("100 + 20")
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Value) // 120
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session maintains state for live editor use. Variables persist across Eval calls within the same session.
func NewSession ¶
func NewSession() *Session
NewSession creates a new stateful evaluation session. Variables are preserved across Eval calls.
Example:
session := calcmark.NewSession()
session.Eval("x = 10")
result, _ := session.Eval("x + 5")
fmt.Println(result.Value) // 15
func (*Session) Eval ¶
Eval evaluates an expression in this session's context. Variables are preserved across calls.
func (*Session) GetVariable ¶
GetVariable retrieves a variable value by name. Returns the value and true if found, nil and false otherwise.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
calcmark
command
|
|
|
calcmark/config
Package config provides configuration management for the CalcMark TUI/CLI.
|
Package config provides configuration management for the CalcMark TUI/CLI. |
|
calcmark/filecheck
Package filecheck validates that file content is safe to interpret as CalcMark.
|
Package filecheck validates that file content is safe to interpret as CalcMark. |
|
calcmark/tui/editor
Package editor provides the TUI editor for CalcMark documents.
|
Package editor provides the TUI editor for CalcMark documents. |
|
calcmark/tui/editor/store
Package store defines the interface for remote document storage backends.
|
Package store defines the interface for remote document storage backends. |
|
calcmark/tui/geometry
Package geometry provides pure layout computation for two-column terminal rendering.
|
Package geometry provides pure layout computation for two-column terminal rendering. |
|
doceval
command
Command doceval scans Hugo markdown files for ```calcmark code blocks, evaluates each through the CalcMark interpreter, and writes the results to site/data/cm_results.json.
|
Command doceval scans Hugo markdown files for ```calcmark code blocks, evaluates each through the CalcMark interpreter, and writes the results to site/data/cm_results.json. |
|
docgen
command
Command docgen generates site/data/features.json from the features registry.
|
Command docgen generates site/data/features.json from the features registry. |
|
Package constants provides common constants used throughout go-calcmark
|
Package constants provides common constants used throughout go-calcmark |
|
display
Package display provides human-readable formatting for CalcMark types.
|
Package display provides human-readable formatting for CalcMark types. |
|
impl
|
|
|
cmd/calcmark
command
|
|
|
embedded
Package embedded scans standard markdown documents for cm/calcmark fenced code blocks and splits the input into passthrough and CalcMark segments.
|
Package embedded scans standard markdown documents for cm/calcmark fenced code blocks and splits the input into passthrough and CalcMark segments. |
|
interpreter
Package interpreter provides the CalcMark expression interpreter.
|
Package interpreter provides the CalcMark expression interpreter. |
|
types
Package types defines the CalcMark type system
|
Package types defines the CalcMark type system |
|
Package lsp bridges CalcMark's spec/impl/format layers to the Language Server Protocol.
|
Package lsp bridges CalcMark's spec/impl/format layers to the Language Server Protocol. |
|
spec
|
|
|
ast
Package ast defines the Abstract Syntax Tree node types for CalcMark
|
Package ast defines the Abstract Syntax Tree node types for CalcMark |
|
classifier
Package classifier implements line classification for CalcMark
|
Package classifier implements line classification for CalcMark |
|
document
Package document defines the CalcMark document structure with blocks.
|
Package document defines the CalcMark document structure with blocks. |
|
features
Package features provides a searchable catalog of CalcMark features for help systems, autocompletion, and documentation generation.
|
Package features provides a searchable catalog of CalcMark features for help systems, autocompletion, and documentation generation. |
|
identifiers
Package identifiers provides the canonical set of named values accepted by CalcMark functions.
|
Package identifiers provides the canonical set of named values accepted by CalcMark functions. |
|
lexer
Package lexer implements the CalcMark lexer/tokenizer.
|
Package lexer implements the CalcMark lexer/tokenizer. |
|
parser
Package parser provides the CalcMark parser implementation.
|
Package parser provides the CalcMark parser implementation. |
|
semantic
Package semantic provides semantic analysis for CalcMark programs.
|
Package semantic provides semantic analysis for CalcMark programs. |
|
transform
Package transform applies document-level post-evaluation transforms (scale, convert_to) to CalcMark evaluation results.
|
Package transform applies document-level post-evaluation transforms (scale, convert_to) to CalcMark evaluation results. |
|
types
Package types defines the CalcMark type system.
|
Package types defines the CalcMark type system. |
|
units
Package units provides canonical unit name mappings based on UCUM and NIST standards.
|
Package units provides canonical unit name mappings based on UCUM and NIST standards. |

