Expand description
Incremental reparse: splice a small edit into the previous green tree instead of re-parsing the whole text.
§Contract
A successful reparse must produce the same green tree and SyntaxError
vector as a full parse of the edited text. Incremental reparse is only a
performance optimization; a failed proof falls back to a full parse.
Guards return None when they cannot prove equivalence. Extend them by
adding supported cases or conservative bailouts, never by weakening the oracle.
The previous-parse cache cannot affect the query result. A cold, stale, or evicted cache only forces a full parse.
§Design
The tiers sit strictly on top of parse_with_declarations_resolved and
[lex_with]. There is no incremental lexer, no token-stream reuse, no restarting
the grammar at an offset:
- the token tier relexes one leaf in isolation, proves the relex is a
single token of the same kind that joins to its neighbours the same way, and
splices with rowan’s [
SyntaxToken::replace_with], sharing every green node off the leaf-to-root path —O(depth), notO(file); - the protected-body tier splices the same way, but proves it differently: a raw capture cannot be relexed alone, so it relexes the leaf’s whole enclosing node with its delimiters and requires that to reproduce the tree’s own tokens;
- the math tier reparses the outermost enclosing delimiter-bearing math node, after the token tier declines a change to the virtual-atom partition;
- the region tier re-runs the ordinary parser over a substring and splices the
resulting children under
ROOT, using neighbour-sized boundary parses purely as proofs that the substring is decoupled from its context.
This avoids checkpointing lexer state, prescan indices, or forward shape-gate scans. The math and region tiers decline edits whose effects may escape their fragments.
Re-exports§
pub use crate::parser::edit::Edit;pub use crate::parser::edit::apply_edits;pub use crate::parser::edit::diff_edit;pub use crate::parser::edit::try_apply_edits;
Structs§
- Reparse
Base - The previous parse a reparse splices against.
- Reparsed
- A successful incremental reparse: the new whole-file green tree and its errors, both in the new text’s offsets.
Enums§
- Reparse
Tier - Which tier produced a
Reparsed. Surfaced for tests and benchmarks, which assert the tier a scenario reaches — a grammar change that silently downgrades one should fail loudly rather than quietly show up as a slower number.
Functions§
- reparse
- Attempt an incremental reparse of
baseunderedit, which transformsbase.textintonew_text.Nonemeans no tier applied and the caller must do a full parse. - reparse_
edits reparsefor a chain of edits, each expressed against the text its predecessors produced — the shape an LSPdidChangebatch arrives in.