Repository navigation
fix(script): keep comma-grouped numbers whole in hyphenated words - #395
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
The number alternative in LEXICAL_UNIT matched a comma-grouped number but failed its lookahead when a hyphenated word followed, so "1,000-word" backtracked to the bare number "1" and split at the comma into "1," + "000-word". Split the alternative so a matched comma group keeps a trailing hyphenated word suffix in the same unit (mirroring what the word alternative already does for "2020-word"), while bare numbers still defer letter suffixes to the word alternative. Standalone "1,000" and plain "2020-word" are unchanged. Fixes hypit-ai#391 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Prose analysis split a comma-grouped number at the comma when a hyphenated word followed:
a 1,000-word essaybecame1,+000-word(two caption/speech words), and an inner Cue breaka 1,||000-word essaywas accepted. Plain2020-wordand standalone1,000were already correct.Why
In
LEXICAL_UNIT, the number alternative matched1,000but its trailing lookahead(?!\p{N}|-[\p{L}\p{M}])failed before-word. The comma-group alternative then died entirely, so the bare\p{N}+form matched just1and the word alternative re-matched000-word.Fix
packages/script/src/lexical.ts— split the number alternative into two:2020-word), so1,000-word,1,000-word, and123,456,789-pointare one unit;2020-wordstill falls through to the word alternative unchanged.Standalone
1,000,1,234.56, and list-like comma behavior are untouched.Tests
Added to
packages/script/test/script.test.ts(tokens + caption words for ASCII comma, full-width comma, and multi-group cases) andpackages/script/test/prose-boundaries.test.ts(1,||000-wordnow throwsSCRIPT_CAPTION_BREAK_TOKEN_BOUNDARYlike2020-||word). Both files pass vianode --test(23/23); both new cases fail on unfixed main.Fixes #391