Skip to main content

Module statement_edit

Module statement_edit 

Source
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):

  • replace rewrites only the statement’s own tokens; a leading "…" annotation in the same chunk stays.
  • delete removes 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.
  • insert writes 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 conditions section creates the section immediately before actions (or the rule’s closing brace when there is no actions section).
  • Deleting the last statement leaves the empty section in place; it reparses with an empty list.

Structs§

StatementAddress
The (rule, list, index) address of a statement edit, by position in the public crate::Rule model — the same order rule-content-v1 exports.

Enums§

StatementEdit
One edit against a rule statement list, addressed by StatementAddress. The payload nodes are rule-content-v1 statement documents — {"value": …} for conditions, {"call": id, "args": […]} for actions — converted through statement_from_content.
StatementEditError
Why Program::edit_statements refused an edit. Every refusal produces no crate::source::SourceEdit.
StatementList
The rule statement list a statement edit addresses.