Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CHSTRING – String Replacement Using a Changes File

Status: Current Last updated: 2026-05-27 10:06 EDT

Purpose

Reimplements CLAN’s chstring command, which reads a changes file containing find/replace pairs (alternating lines) and applies text substitutions to main-tier words. Replacements are applied to all word nodes, including words inside annotated groups, replacement forms, and bracketed groups.

See the CLAN manual for the original command documentation.

Usage

chatter-clan chstring --changes changes.cut file.cha

Options

OptionTypeDefaultDescription
-c, --changespath(required)Path to the changes file containing find/replace pairs
-o, --outputpathstdoutOutput CHAT file path

CLAN +-flag coverage audit

CHSTRING is a transform: it mutates CHAT input and writes CHAT output. It does not emit a banner and does not share CommonAnalysisArgs (no speaker/role/gem/range filters apply). The flag set is entirely command-specific.

Sources: OSX-CLAN/src/clan/chstring.cpp::usage, crates/talkbank-clan/src/transforms/chstring.rs, crates/talkbank-cli/src/cli/args/clan_commands.rs::Chstring.

(Status legend: same as FREQ.)

CHSTRING-specific +-flags (from chstring.cpp::usage)

CLAN flagMeaningChatterStatusNotes
+bWork only on text right of the colon (CHAT format)(default)DoneCLAN: chstring.cpp:1120 (case 'b': lineonly = TRUE; no_arg_option(f)). chatter’s chstring already mutates only main-tier word content (never speaker codes or dependent-tier text), so +b is semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs consumes-and-drops +b so it doesn’t fall through to the positional <PATH> slot.
+cF / -cDictionary file path / do not change inside [...] codes--changes <PATH> (file form only)Partialchatter requires the path explicitly (no changes.cut-in-cwd default). The -c inside-codes guard is implicit, chatter’s AST-based replacement only touches word leaves, never code-bracket content.
+dDo not re-wrap tiers,MissingBare-only per OSX-CLAN/src/clan/chstring.cpp:1087 (NO_CHANGE = TRUE + no_arg_option(f)). chatter never wraps on output, so semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs passes the token through so clap reports the literal +d argument rather than the misleading --display-mode rewrite.
+lWork only on codes left of colon (speaker tag),Missing
+lxDo not show the list of changes(default)DoneCLAN: chstring.cpp:1108-1111 (case 'l': if (*f == 'x') DispChanges = FALSE). chatter never prints a changes-list (silent by design), so +lx is semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs consumes-and-drops the specific lx form so it doesn’t fall through to the positional <PATH> slot. Bare +l (headeronly = TRUE) is genuinely unimplemented and falls through to clap.
+qClean up tiers (add tabs after colons, remove blank spaces),MissingTier-cleanup pass.
+q1Clean up tiers for CORELEX,Missing
+sS SInline find/replace pair,MissingAll replacements must come via --changes.
-wString-oriented search and replacement(default)DoneCLAN: chstring.cpp:1145-1147 (case 'w': if (*f == EOS) stringOriented = 1). chatter’s word-leaf replacement is already string-oriented by default, so -w is semantically a no-op. Per-CHSTRING rewriter arm in clan_args.rs consumes-and-drops bare -w so it doesn’t fall through to clap as an unknown short flag. CLAN’s -w1 (stringOriented = 2) is not documented in this audit and is left to fall through.
+xInterpret *, _, \ as literal characters,Missingchatter’s matcher does not yet expose wildcard-vs-literal switching.

Audit summary

BucketCount
Done3
Partial1
Missing6

CHSTRING is intentionally a thin transform in chatter, the typed-AST design eliminates several CLAN flags by construction (+b, -c inside-codes guard, +lx). The remaining gaps are mostly orthogonal niceties (+q tier-cleanup, +sS inline pair, +x literal-character mode); none change correctness of the default file → file transform.

Changes File Format

The changes file contains alternating lines of find and replace strings:

find_text1
replace_text1
find_text2
replace_text2

The file must have an even number of non-empty lines. CLAN looks for changes.cut in the current directory by default; chatter-clan chstring requires the path to be passed explicitly via --changes.

Behavior

For each utterance in the file, the transform walks all word nodes on the main tier – including words inside annotated groups, replacement forms, and bracketed groups – and applies find/replace substitutions from the changes file.

Differences from CLAN

  • Operates on the parsed AST rather than raw text, ensuring structural integrity of the CHAT file after substitution.
  • Does not support CLAN’s regex-based pattern matching in the changes file.
  • Uses the framework transform pipeline (parse -> transform -> serialize -> write).
  • Golden test parity: Verified against CLAN C binary output.