Skip to content

fix: match an indented template line's indent exactly (#30) - #125

Merged
roc-ops merged 2 commits into
mainfrom
fix/30-exact-indent
Nov 28, 2026
Merged

roc-ops merged 2 commits into
mainfrom
fix/30-exact-indent

Conversation

@roc-ops

@roc-ops roc-ops commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Summary

An indented template line now matches data with exactly that indent, as in Python TTP 0.10.1, which builds the regex as \n + the template's leading whitespace + the rest of the line.

template line        before                     after = TTP 0.10.1
"  {{ v }}"          ^[ \t]+(\S+)[\t ]*$        ^  (\S+)[\t ]*$
"\t{{ t }}"          ^[ \t]+(\S+)[\t ]*$        ^\t(\S+)[\t ]*$
"    x  {{ y }}"     ^[ \t]+x[ \t]+(\S+)...     ^    x[ \t]+(\S+)...
"H {{ _start_ }}"    unchanged

Data H, a, b, \tc, x against H {{ _start_ }} / {{ v | joinmatches }} (the #30 repro):

v
before "a\nb\nc\nx"
after "a"
TTP 0.10.1 "a"

The fix is in internal/pattern/engine.go, GenerateRegexFromVariables. The leading whitespace used to go through escapeText, which turns every run of spaces or tabs into [ \t]+. It is now split off and emitted literally (spaces and tabs need no escaping), and the rest of the line is built as before. Whitespace inside a line still matches any run of spaces and tabs, as in TTP. Every compile path goes through this function, and all runtime match loops keep the data line's leading whitespace (they only right-trim it), so nothing else needed changing.

Left as they were:

Evidence

Merge Danger

Fixes #30

🤖 Generated with Claude Code

roc-ops and others added 2 commits November 27, 2026 19:47
GenerateRegexFromVariables ran the line's leading whitespace through
escapeText, which turns any run of spaces or tabs into [ \t]+, so a line
indented by two spaces also matched one space, four spaces or a tab.
Python TTP rebuilds the indent verbatim ("\n" + indent + ...). The
indent is now emitted literally and the rest of the line is built as
before.

Suite cases filed under #30 now fail later: test_issue_45* at #28,
test_slack_answer_2 at #63, and the route-target cases at three new
issues (#118, #119, #120).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
So the editor matches indented template lines the same way as the library
and CLI after the #30 fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@roc-ops
roc-ops force-pushed the fix/30-exact-indent branch from 85133de to 7a36ac0 Compare November 28, 2026 01:50
@roc-ops

roc-ops commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

Rebased onto main after #116 (#35) merged. Changes:

  • CHANGELOG.md: kept both entries.
  • known_failures.json: removed test_answers_and_docs/test_issue_50, which passes once both fixes are in.
  • test/ttpsuite/README.md: regenerated the per-issue table from known_failures.json, and updated the counts to suite pass 49 / skipped-by-issue 147 / design 4 and repros pass 3 / 7.
  • Rebuilt editor/gottp.wasm and editor/js/gottp.wasm (identical), so the editor uses exact-indent matching too.

Ran locally: go vet, go test, go test -race (without test/memory), staticcheck and the wasm build. All pass.

@roc-ops
roc-ops merged commit 1ed4ea0 into main Nov 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indented template lines match data at any indentation

1 participant