Skip to content

Keep original text and origin spans on month range tokens - #65

Merged
vthorsteinsson merged 1 commit into
masterfrom
fix/month-range-original
Oct 15, 2026
Merged

vthorsteinsson merged 1 commit into
masterfrom
fix/month-range-original

Conversation

@vthorsteinsson

Copy link
Copy Markdown
Member

Problem

The review fixes for PR #63 (14c566c) built the three tokens of a month range such as mars-apríl (DATEREL, hyphen, DATEREL) from plain strings, instead of splitting the source token. The new tokens have original=None and no origin_spans, so with original=True:

  • the range disappears from the text reconstructed from the tokens (" mars-apríl" is lost), and
  • the character offsets of its parts are missing.

The regression is unreleased: 3.6.4 predates PR #63.

Fix

Split the source token with Tok.split() again, as the original PR #63 code did, keeping the walrus refactor from the review.

Testing

  • New test_month_range_original (hyphen and en-dash ranges): checks that the input is reconstructed from the tokens' original text and that each part has its original text and origin spans. It fails without the fix.
  • Full suite passes; mypy clean.
  • test/toktest_large.txt is now reconstructed exactly from its tokens' original text, except for the file's final newline: trailing whitespace at the end of the input belongs to no token, the same as in 3.6.4.
  • Merges cleanly with Speed up tokenization ~25%, add perf bench, clean up lint and the stale gold file #64.

🤖 Generated with Claude Code

Commit 14c566c (review fixes for the month range tokens of PR #63)
built the DATEREL, hyphen and DATEREL tokens of e.g. 'mars-apríl' from
plain strings instead of splitting the source token. The new tokens
had original=None and no origin spans, so with original=True the range
vanished from the reconstructed text and its character offsets were
lost. Split the token again, keeping the walrus refactor.

The regression is unreleased (3.6.4 predates PR #63). With the fix,
the original text of test/toktest_large.txt is reconstructed exactly
from its tokens, except for the final newline: trailing whitespace at
the end of the input belongs to no token, as in 3.6.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vthorsteinsson
vthorsteinsson merged commit be2c973 into master Oct 15, 2026
6 checks passed
@vthorsteinsson
vthorsteinsson deleted the fix/month-range-original branch October 15, 2026 15:05
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.

1 participant