Skip to main content

Crate edikt_core

Crate edikt_core 

Source
Expand description

edikt core.

Home of the Value model, the Feature capability enum, and the expression language (lexer, parse, evaluator). The evaluator is built and tested here against a plain in-memory Value so the language is correct independent of any format-preserving CST; the format modules wire the same AST to their CSTs.

The format-agnostic Document and Convert seams arrive with the JSONC slice, once there is a concrete CST to shape them against.

Modules§

convert
Data-model helpers for format conversion.
wrap
Comment wrapping: the shared “use the space as it exists” rule.

Macros§

json
Construct a Value from JSON-ish literal syntax.

Structs§

Commented
A Value enriched with per-node comments: what conversion carries so a commented source survives -T into a commented target.
Comments
The comments attached to one node, by kind.
EditError
A format-preserving edit failure (bad path, wrong type for the operation, unsupported construct).
EvalError
An evaluation failure (type error, unknown function, arity mismatch).
FlatEntry
One flattened key = value line with the comments it carries: the shape the flat emitters (INI sections, .env) place comments through.
ParseError
A parse failure with a byte offset into the source expression.

Enums§

BinOp
A binary operator.
CommentKind
One of the three comment kinds in the uniform model. Which kinds a format supports is its comment capability: each format declares a COMMENT_KINDS: &[CommentKind] (empty => no comments, subsuming the boolean Feature::Comments). The # accessor addresses a node’s comment by kind.
CommentedNode
The shape of a Commented node, mirroring Value.
Expr
An expression node.
Feature
A capability a config format may or may not support.
Step
One navigation step within a path, applied to the current input.
Value

Traits§

Document
A parsed config document.

Functions§

apply_comment_mutation
Apply a comment-mutation expression via the document’s comment write methods, returning any warnings (layout expansion, kind remap). Comment-free mutations never reach here; the CLI routes on Expr::has_comment.
eval
Evaluate expr against input, returning the output stream.
eval_with_comments
Evaluate a query that may address comments (#) against the document’s commented projection. Comment-free sub-expressions fall back to the plain value evaluator; a comment path resolves the comment text of each selected node. Supported in v0.2 Phase 1 as a read surface: a comment path (.foo.#, .foo.#.inline, .items[].#) optionally piped or defaulted (| ascii_upcase, // "none"). Comment access after a value pipe, or as an assignment target, is not yet served and errors clearly.
expand_delete_paths
The concrete paths for a delete fan-out: expand_iter_paths reversed, so a caller deletes from the back forward and earlier concrete paths’ indices (or keys) stay valid as the collection shrinks under the splices.
expand_iter_paths
Expand a path containing Step::Iterate into concrete iterate-free paths, one per iterated element, against value. This is the edit-path analogue of Step::Iterate evaluation: an array iterate becomes .a[0], .a[1], …; an object iterate becomes .a."key", …, so a caller can apply a set/update per element with machinery that only handles index-keyed targets. A non-iterate step that misses (absent key, out-of-range index) yields no paths, like a query miss; stepping into the wrong type errors, matching evaluation.
flatten_commented
Flatten a commented tree to dotted-key entries (the commented analogue of crate::convert::flatten). A container’s own comments ride along: its head (and inline, which has no line of its own once flattened) prepend to its first entry’s head; its foot appends to its last entry’s foot. An empty container vanishes, its comments carried to… nowhere: the caller sees them dropped via Commented::has_comments on the re-projected result; in practice empty containers with comments are vanishingly rare.
hyphen_hint_for_unknown_function
The hyphenated-key hint for an unknown function \name`evaluation error, whennameis literally the tail of a hyphenated bare key insrc`.
line_index
The 0-based line index containing byte offset at.
parse
Parse a complete expression, consuming all of src.
place_line_comment
Place (or clear) an own-line comment block around a node’s line, on the source text, for the line-oriented formats (.env, INI). target_line is the 0-based index of the node’s own line; is_head puts the block above (else below, for foot). Contiguous existing comment lines on that side (detected by is_comment_line) are replaced; wrapped == None deletes. Untouched lines are preserved verbatim, so the moat holds.
render_path
Render a path of steps back to jq-ish source text (.a.b[0], .["a.b"]) for error messages. An empty path is . (identity).