Expand description
Statement-level edits for raw Workshop source.
Program::edit_statements is the write direction of the
workshop-rs/rule-content-v1 statement contract
(crate::rules::statement): given a parsed program, it produces the
checked crate::source::SourceEdit that inserts statement nodes before
a statement index, replaces the statement at an index, or deletes it,
inside one rule’s conditions or actions section. Inserted and
replacement statements are emitted canonically in locale and indented
like the surrounding source. Bytes outside the returned edit’s range are
unchanged, and the edit itself re-verifies them when applied.
Addresses are positional: StatementAddress names a rule, a statement
list, and an index into the public crate::Rule model — the same
order rule-content-v1 exports. The call is fail-closed: an
out-of-range or stale address (the public model no longer matching the
retained source at that position), a node
statement_from_content refuses, an emission failure, or a rule with
no retained source produces an error and no edit.
Layout and comment rules, in terms of a statement chunk (one statement
plus the standalone "…" annotations directly attached to it):
replacerewrites only the statement’s own tokens; a leading"…"annotation in the same chunk stays.deleteremoves the chunk: the statement and its leading"…"annotations. A chunk alone on its line takes the whole line, with a//tail comment; a chunk that shares its line takes only its own bytes and one adjacent whitespace run.insertwrites no comments. Inserted rows take the anchor line’s indentation;//line comments are unowned positional trivia and are never counted as part of a statement.- Inserting into a rule with no
conditionssection creates the section immediately beforeactions(or the rule’s closing brace when there is noactionssection). - Deleting the last statement leaves the empty section in place; it reparses with an empty list.
Structs§
- Statement
Address - The
(rule, list, index)address of a statement edit, by position in the publiccrate::Rulemodel — the same orderrule-content-v1exports.
Enums§
- Statement
Edit - One edit against a rule statement list, addressed by
StatementAddress. The payload nodes arerule-content-v1statement documents —{"value": …}for conditions,{"call": id, "args": […]}for actions — converted throughstatement_from_content. - Statement
Edit Error - Why
Program::edit_statementsrefused an edit. Every refusal produces nocrate::source::SourceEdit. - Statement
List - The rule statement list a statement edit addresses.