Documentation
¶
Index ¶
- Constants
- func FieldName(e Expr, idx int) string
- func FormatValue(v Value) string
- func PrintTable(w io.Writer, headers []string, rows []TableRow)
- func Write(path FilePath, d *Document) error
- type AlterOp
- type AlterQuery
- type Assign
- type AssignOp
- type BinExpr
- type BinOp
- type Document
- type ExecOptions
- type Expr
- type Field
- type FieldExpr
- type FieldType
- type FilePath
- type FrontMatter
- type ListExpr
- type LitExpr
- type LiteralKind
- type Output
- type Program
- type Query
- type RenamePair
- type SelectQuery
- type SortTerm
- type Table
- type TableRow
- type UnaryExpr
- type UnaryOp
- type UpdateQuery
- type Value
Constants ¶
const DefaultMaxColumns = 20
DefaultMaxColumns is the column cap applied to `select *` output when ExecOptions does not set an explicit value.
Variables ¶
This section is empty.
Functions ¶
func FieldName ¶
FieldName returns a sensible column header for an expression. Field references use the field name; anything else falls back to a positional placeholder.
func FormatValue ¶
FormatValue renders a Value as a plain string for table output.
func PrintTable ¶
PrintTable writes a tab-separated table to w: filename column plus the supplied headers and the materialized values from each TableRow.
Types ¶
type AlterQuery ¶
type AlterQuery struct {
Op AlterOp
Drop []Field // populated when Op == AlterDrop
Rename []RenamePair // populated when Op == AlterRename
// contains filtered or unexported fields
}
AlterQuery represents: alter <globs> drop/rename ... [where <expr>]
func (AlterQuery) Eval ¶
func (q AlterQuery) Eval(fm FrontMatter) (*TableRow, error)
Eval drops or renames fields, then projects the affected fields. For drop, projection happens before deletion so dropped values are visible. For rename, projection happens after rename so headers match new names.
func (AlterQuery) IsMutation ¶
func (q AlterQuery) IsMutation() bool
type Assign ¶
Assign is one assignment in an update...set clause. Value is nil for the cast-only form (e.g. `set foo:int`).
func (Assign) Apply ¶
func (a Assign) Apply(fm FrontMatter) error
Apply evaluates a.Value (if present), casts to a.Field.Type, and writes the result into fm under a.Field.Name. A runtime cast failure is returned as an error so the caller can halt the current file per Manual.md.
type BinExpr ¶
BinExpr is a binary operation: Left Op Right.
func (BinExpr) Eval ¶
func (e BinExpr) Eval(fm FrontMatter) Value
type BinOp ¶
type BinOp int
BinOp is a binary operator, ordered by precedence group (lowest first).
const ( // Boolean connectives (lowest precedence). BinOr BinOp = iota // or BinAnd // and // Comparison operators. BinEq // = BinNe // != BinLt // < BinLe // <= BinGt // > BinGe // >= BinOverlap // <=> set overlap (lists share ≥1 element) // Arithmetic operators. BinAdd // + BinSub // - BinMul // * BinDiv // / )
type Document ¶
type Document struct {
FrontMatter FrontMatter
Body string
}
func ReadDocument ¶
ReadDocument loads a Markdown file and splits its YAML frontmatter from the body. A file without a leading `---\n` block is treated as body-only.
type ExecOptions ¶
type ExecOptions struct {
// DryRun runs all statements in memory but does not write mutated documents back to disk.
DryRun bool
// Silent suppresses all normal output (errors are still written to errOut).
Silent bool
// Verbose prints the affected fields after update or alter statements.
// Without this flag, mutation statements produce no output.
Verbose bool
// MaxColumns caps the number of frontmatter columns rendered for `select *`
// output. Zero means use DefaultMaxColumns. Excess columns are dropped from
// the printed table; row count is unaffected.
MaxColumns int
// IncludeHidden includes files whose basename begins with '.' in glob
// expansion. Default skips them.
IncludeHidden bool
}
ExecOptions controls how a Program is executed.
type Expr ¶
type Expr interface {
Eval(fm FrontMatter) Value
// contains filtered or unexported methods
}
Expr is the expression tree node interface.
type FieldExpr ¶
type FieldExpr struct {
Field Field
}
FieldExpr is a field reference atom. Evaluates to the field's value in the current file's frontmatter, or void if absent.
func (FieldExpr) Eval ¶
func (e FieldExpr) Eval(fm FrontMatter) Value
type FieldType ¶
type FieldType int
FieldType is the declared type of a frontmatter field.
const ( TypeAny FieldType = iota // default when no type annotation is given TypeString // string TypeBool // bool TypeInt // int TypeNumber // numeric (float) TypeDate // date (YYYY-MM-DD) TypeDatetime // datetime (ISO 8601 local time) TypeLink // [[ref]] or [[ref|title]] TypeMdLink // [title](ref) TypeList // list[:elemtype] )
type FilePath ¶
type FilePath = string
func ExpandGlobs ¶
ExpandGlobs expands the patterns to file paths. Bare paths that exist are passed through; tokens containing glob metacharacters are expanded via filepath.Glob. A bare-path token that does not exist is an error.
type FrontMatter ¶
type ListExpr ¶ added in v0.2.0
type ListExpr struct {
Elems []Expr
}
ListExpr is a bracketed list literal: [e1, e2, ...]. Evaluates element-wise.
func (ListExpr) Eval ¶ added in v0.2.0
func (e ListExpr) Eval(fm FrontMatter) Value
type LitExpr ¶
type LitExpr struct {
Kind LiteralKind
Value string
}
LitExpr is a literal constant atom. Value holds the raw source text: unquoted string content, digit string, "true", "false", or "null".
func (LitExpr) Eval ¶
func (e LitExpr) Eval(_ FrontMatter) Value
type LiteralKind ¶
type LiteralKind int
LiteralKind identifies the kind of a LitExpr.
const ( LitString LiteralKind = iota // quoted or raw string LitInt // decimal or 0x… integer LitNumeric // floating-point LitBool // true | false LitNull // null )
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output accumulates per-statement result tables across a multi-file evaluation.
func NewOutput ¶
NewOutput allocates one Table per statement, in source order. maxColumns caps the column count rendered for `select *` tables; non-star tables are unaffected.
func (*Output) Append ¶
Append stamps row with path, stores it in the i'th table, and returns true when no further input is needed for that statement.
func (*Output) Done ¶
Done reports whether statement i has collected enough rows to short-circuit remaining files (only true for select with limit and no sort).
type Program ¶
type Program struct {
Stmts []Query
}
func ParseProgram ¶
ParseProgram reads a sequence of statements from r and returns a Program. Statements are separated by ';'. '--' starts a line comment that runs to the next newline and is treated as whitespace. Consecutive ';' separators (including leading and trailing ones) are tolerated. An input that contains only whitespace and comments yields an empty Program.
func (Program) Run ¶
func (p Program) Run(opts ExecOptions, okOut, errOut io.Writer) (ok bool)
Run executes the program. For each file in the union of all statement globs, the document is read once, every applicable statement runs against the in-memory frontmatter, and the file is written back if any mutation succeeded. A failing statement halts further work on that file and cancels its write; the loop proceeds to the next file. Output for completed statements is preserved. Tables are written to okOut in source order; per-file errors are reported to errOut. The returned bool is false if any file failed to read, write, or evaluate.
type Query ¶
type Query interface {
Eval(fm FrontMatter) (*TableRow, error)
IsMutation() bool
Globs() []string
// contains filtered or unexported methods
}
type RenamePair ¶
RenamePair is one rename in an alter...rename clause.
type SelectQuery ¶
type SelectQuery = query
SelectQuery represents: select <exprs> from <globs> [where <expr>] [sort by <terms>] [limit <n>]
type SortTerm ¶
SortTerm is one key in a sort-by clause.
func (SortTerm) Eval ¶
func (s SortTerm) Eval(fm FrontMatter) Value
Eval is a thin wrapper around the underlying expression.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table holds the accumulated rows for one statement.
type TableRow ¶
type TableRow struct {
// contains filtered or unexported fields
}
TableRow is one projected row: the file it came from and the materialized values for the statement's Select and SortBy expressions. star is populated instead of print when the source statement was `select *`.
type UnaryExpr ¶
UnaryExpr is a unary operation: Op Operand.
func (UnaryExpr) Eval ¶
func (e UnaryExpr) Eval(fm FrontMatter) Value
type UpdateQuery ¶
type UpdateQuery struct {
Set []Assign
// contains filtered or unexported fields
}
UpdateQuery represents: update <globs> set <assigns> [where <expr>]
func (UpdateQuery) Eval ¶
func (q UpdateQuery) Eval(fm FrontMatter) (*TableRow, error)
Eval applies all assignments in order, then projects the affected fields. A failed assignment returns (nil, err); fm may be partially mutated. Caller is responsible for discarding the file on error.
func (UpdateQuery) IsMutation ¶
func (q UpdateQuery) IsMutation() bool
type Value ¶
Value is the runtime value produced by evaluating an expression. Null marks absence: a missing field or a cast that could not produce a value. Per Manual.md: null propagates through arithmetic; in boolean context it is falsey.