Commit Graph

2 Commits

Author SHA1 Message Date
Levi Neely 4cdd762bb6 sam: ^/$ are per-line (MultilineOption), matching plan9 regexp(7)
Verified against plan9port: regexp(7) defines ^ as 'beginning of a line'
and $ as 'end of a line', and sam's regexp.c BOL (p==0 || prev=='\\n') /
EOL (next char '\\n') confirm per-line anchoring. The engine was matching
with buffer-wide anchors, so ,s/^/> /g only touched the first line and the
sam idiom ,x/.+/ s/^/> / failed to prefix each line.

Fix: compile every pattern with QRegularExpression::MultilineOption. '.'
still does not cross newlines (sam-faithful; PCRE default). Add 3 regression
tests (caretIsPerLine, dollarIsPerLine, samAnchorIdiom); 30/30 engine tests.

Docs: correct docs/SAM.md — ^/$ per-line is faithful, not a deviation;
reframe PCRE extras as an escape hatch (prefer structural composition), not
'free upgrades'. Fix the panel hint and PLAN.md accordingly.
2026-10-08 14:29:19 +02:00
Levi Neely 997055f0b5 docs(sam): document PCRE deviations + implications for katesam usage
Add docs/SAM.md — a user-facing reference for the regex deviation, with
examples verified against the engine:
  - leftmost-greedy (PCRE) vs leftmost-longest (sam): diverges only on
    overlapping alternation (a|ab); order alternatives longest-first.
  - ^/$ anchor buffer-wide, not per-line, by default. Workarounds:
    structural ,x/.+/ … (preferred) or the (?m) inline flag.
  - identical behaviour table (. and newlines, empty-match advance, &/\N).
  - PCRE bonuses sam lacks: \d \w \b, lookahead, non-greedy, (?i)(?m)(?s).

Cross-link from PLAN.md and surface the two biggest gotchas (buffer-wide
anchors, alternation order) directly in the Sam panel hint label.
2026-10-08 14:03:55 +02:00