Skip to content

Document resyntax/grimoire/string-replacement#790

Draft
jackfirth wants to merge 4 commits into
masterfrom
grimoire-string-replacement
Draft

Document resyntax/grimoire/string-replacement#790
jackfirth wants to merge 4 commits into
masterfrom
grimoire-string-replacement

Conversation

@jackfirth

Copy link
Copy Markdown
Owner

Continues the grimoire documentation effort (#785, #787, #789) by documenting the string replacement API — the lowest-level form that Resyntax's suggestions take before being written to files.

Three commits:

  • Move: resyntax/private/string-replacement moves into the resyntax/grimoire collection, with requires updated in its five users.
  • Docs: a new grimoire section covering all 21 exports, including the piece model (inserted vs. copied strings, with copies allowed from anywhere in the original — which is what lets replacements move text), the constructor's normalization and its equal? consequences, half-open zero-based positions, and a cross-reference tying copied pieces to the formatting-preservation mechanism documented in the syntax paths section.
  • Fixes: two error-reporting bugs found while verifying doc claims: string-replacement-render reported its errors under the name string-apply-replacement, and required-length didn't account for the #:end position, so applying a replacement to a string shorter than its replaced region died inside make-string instead of raising the friendly contract error. Both have regression tests.

One known design wart deliberately left alone for now: union-into-string-replacement reduces from an empty replacement at position 0, so reducing even a single replacement produces a structurally different (though behaviorally equivalent) replacement, and the union operation has no identity element up to equal? — unlike source groups. Documented as-is; deciding whether to rework it is future work.

🤖 Generated with Claude Code

jackfirth and others added 3 commits July 5, 2026 21:06
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The string-too-short error in string-replacement-render was reported
under the name string-apply-replacement, a copy-paste slip.

Additionally, a replacement's required length now accounts for its end
position, not just the positions its copied pieces refer to. Applying
a replacement to a string shorter than the replaced region previously
skipped the friendly error and failed inside make-string with a
confusing contract violation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jackfirth jackfirth added the documentation Improvements or additions to documentation label Jul 7, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 5 files in this pull request and found no issues.

@coveralls

coveralls commented Jul 7, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 94.0% (+0.1%) from 93.878% — grimoire-string-replacement into master

The pieces making up a string replacement's contents are now called
string pieces, with a string-piece struct supertype underneath both
kinds and a public string-piece? predicate. The pieces aren't
exclusively tied to replacements --- syntax-replacement uses their
spans directly when narrowing replacement focus --- so the
replacement-string-span operation is now string-piece-span, and
contracts say string-piece? instead of enumerating the two kinds.

Also converts copied-string from define-tuple-type to a plain struct,
matching inserted-string.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 5 files in this pull request and found no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants