refactor(message-parser): simplify Any fallback to reduce URL/phone parse attempts#39294
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
|
WalkthroughThe grammar file is refactored to replace specific URL and phone detection rules with more generic composite rules (AnyPhone, AnyURL, and related prefixes), broadening the pattern matching for autolinked content while preserving surrounding text handling logic. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/message-parser/src/grammar.pegjs (1)
809-809: UseDigit |1..3|instead ofDigits |1..3|for clearer intent and better performanceOn line 809,
Digits |1..3|is less precise becauseDigitsis defined as$Digit+(a greedy match of one or more digits). When applied with the quantifier, the first invocation consumes all consecutive digits, making the repetition bound ambiguous. Replacing withDigit |1..3|explicitly matches 1–3 individual digit characters, eliminating backtracking ambiguity and improving parser selectivity. This pattern is consistent with other uses in the grammar (e.g.,Digit |2|,Digit |4|).Proposed change
- / Digits |1..3| "." Digits |1..3| "." + / Digit |1..3| "." Digit |1..3| "."🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/message-parser/src/grammar.pegjs` at line 809, Replace the use of the `Digits |1..3|` quantified symbol with `Digit |1..3|` to avoid greedy consumption by the `Digits` rule; locate the rule containing the sequence `/ Digits |1..3| "." Digits |1..3| "."` in grammar.pegjs and change both occurrences to `Digit |1..3|` so each quantifier applies to individual digit characters (referencing the `Digit` and `Digits` rules) to improve selectivity and eliminate ambiguous backtracking.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/message-parser/src/grammar.pegjs`:
- Line 809: Replace the use of the `Digits |1..3|` quantified symbol with `Digit
|1..3|` to avoid greedy consumption by the `Digits` rule; locate the rule
containing the sequence `/ Digits |1..3| "." Digits |1..3| "."` in grammar.pegjs
and change both occurrences to `Digit |1..3|` so each quantifier applies to
individual digit characters (referencing the `Digit` and `Digits` rules) to
improve selectivity and eliminate ambiguous backtracking.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/message-parser/src/grammar.pegjs
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: cubic · AI code reviewer
🔇 Additional comments (1)
packages/message-parser/src/grammar.pegjs (1)
797-805: Good perf-oriented guardrails in fallback parsingThe new
AnyPhone/AnyURLprefix-gated fallback on Lines 797-805 is a solid optimization and keeps expensive URL/phone attempts off plain-text-heavy paths.
Summary
Anyfallback in grammar by gating URL/phone attempts with cheap prefix checks.+.Problem
Anyfallback attempted optional phone/URL parsing on fallback characters, which can add unnecessary parsing work on plain-text-heavy inputs.Changes
Anyoptional calls toAutolinkedPhone/URLwith guardedAnyPhone/AnyURL.AnyURLPrefixrules for scheme/host hints before invoking fullURL.Verification
Fix #39295
Summary by CodeRabbit
Release Notes