Skip to content

feat(match-input): replace regex parser with tokenizer, remove moment (#177, #230) - #231

Merged
pajoma merged 3 commits into
developfrom
feat/177-smart-input-tokenizer
Jun 1, 2026
Merged

feat(match-input): replace regex parser with tokenizer, remove moment (#177, #230)#231
pajoma merged 3 commits into
developfrom
feat/177-smart-input-tokenizer

Conversation

@pajoma

@pajoma pajoma commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces getExpression() regex dispatch in MatchInput with a left-to-right priority-ordered tokenizer (tokenizetokensToInput). Each recognizer is a pure function with explicit word-boundary checks via wordEnd() — closes the (?=\s|$) bug class from Wrong day is set when enter a new entry #170.
  • Removes import moment from match-input.ts; all date arithmetic replaced with getCurrentISOWeek + Date.UTC (moment remains in other files — Phase 3).
  • Adds ParseConfidence (resolved / ambiguous / text-only) on Input; QuickPick description prefixed with $(check) / $(warning) ThemeIcons for visual feedback.
  • Fixes Some issues extracing input from Smart Input #230 Bug 1 (week-token regex consumed first character of following text) — recognizeWeek uses zero-width lookahead by design; three regression tests added.

Related issues

Closes #177
Closes #230

Specs / Plans

Test plan

  • npm test -- --grep "MatchInput" — all vocab + regression tests pass (40+ scenarios)
  • npm test — 221 passing; 2 pre-existing failures unrelated to this PR (sync-note-links, issue-144-cmd) verified on develop before this branch
  • Manual: open QuickPick (Ctrl+Shift+J), type mon$(check) prefix; type di$(warning) prefix; type task week Buy groceries → task created on current week with full text preserved

🤖 Generated with Claude Code

Also closes #232

pajoma and others added 3 commits June 1, 2026 17:15
Steps 1-9 of plan #177:
- ParseConfidence type + optional confidence field on Input
- Token types, interfaces in match-input.ts
- weekdayVocab() / monthVocab() as string[] (stop joining to regex)
- Recognizer functions with wordEnd() boundary check
- tokenize() loop: explicit priority order, no alternation-order surprises
- tokensToInput() mapper replacing extractX / resolveX methods
- resolveRelatedWeekNM / resolveDayOfMonthNM replace moment calls
- Parallel phase in parseInput(): tokenizer runs alongside regex,
  logs divergences via logger.debug; regex still authoritative
- Dialogues: $(check)/$(warning) ThemeIcon prefix in description
  driven by parsed.confidence (QuickPick lacks validationMessage)
- match-input-vocab.test.ts: 40+ scenarios covering shortcuts, offsets,
  ISO forms, weekday/week/month+day, task flags, prefix collision guard,
  and vocab sweep for false-positive detection

#177
Step 10 of plan #177:
- parseInput() now calls tokenize() + tokensToInput() directly
- Deleted: getExpression(), getMonthPattern(), getWeekdayPattern(),
  extractText/Flags/Offset/Week/Tags, hasTemporalToken,
  resolveRelatedWeek, resolveNumberedWeek, resolveDayOfMonth,
  this.expr cache field
- Removed: import moment (no moment calls remain in this file)
- resolveRelatedWeekNM / resolveDayOfMonthNM are the authoritative
  week/month-day resolvers going forward

#177
Proves recognizeWeek uses zero-width lookahead — no character consumed
from following text. Covers: week+text, standalone week, w<num> priority.

#230

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pajoma pajoma self-assigned this Jun 1, 2026
@pajoma pajoma added this to the 1.1.0 milestone Jun 1, 2026
@pajoma

pajoma commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

Code review and test verification for PR #231 (Fixes #177, #230):

  1. Architecture: The transition from a monolithic regex to a priority-ordered tokenizer is a significant improvement in maintainability and robustness. Using wordEnd (lookahead-based boundary check) consistently prevents the collision issues identified in Wrong day is set when enter a new entry #170.
  2. Acceptance Criteria:
    • Week-token boundary (Some issues extracing input from Smart Input #230): Verified via new regression tests. ask week Finalize Shoppinglist correctly preserves the full text.
    • Moment removal: Confirmed moment is removed from match-input.ts, using native Date and the existing getCurrentISOWeek helper.
    • Confidence UI: ParseConfidence is correctly integrated with ThemeIcons ($(check) / $(warning)) in the QuickPick.
  3. Testing:
    • Ran 56 new scenarios in match-input-vocab.test.ts (100% pass).
    • Ran 27 existing scenarios in input.test.ts (100% pass).
    • Verified that no regression was introduced regarding Wrong day is set when enter a new entry #170 prefix collisions.

Approval Recommendation: The PR is technically sound, well-tested, and addresses the root causes of multiple reported issues. Recommending approval and merge.

@pajoma

pajoma commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

CI Failure Analysis:
The failing test OpenNextEntryCommand in calendar mode creates the next-day entry appears to be a pre-existing flake or environmental issue. It failed with ENOENT on a temporary path /tmp/issue144-cmd-.../2026/06/01.md.

Crucially, all MatchInput tests (including the 56 new tokenizer tests) passed in CI. I've verified that the same #144 failure occurs on the develop branch.

PR #231 is safe to merge.

@pajoma
pajoma merged commit cd19a4f into develop Jun 1, 2026
0 of 2 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

1 participant