feat(rules): implement pattern string lexer for tokenization#4
Conversation
The pattern parser needs a lexer that splits pattern strings like "curl -X|--request POST *" into raw tokens as its first stage. Without this, the parser cannot recognize the different syntactic elements (alternation, wildcards, negation, etc.) in rule patterns. The lexer recognizes: - Pipe-separated alternation (-X|--request, POST|PUT|PATCH) - Wildcard (*) and negation (!value, !a|b|c) - Optional group brackets ([...]) with nesting validation - Angle-bracket placeholders (<cmd>, <path:name>) - Quoted strings (single and double) with proper whitespace handling - Error reporting for unclosed brackets, quotes, and invalid syntax Co-Authored-By: Claude Opus 4.6 <[email protected]>
The lexer accepted patterns like "a||b", "-X|", "|--request" without error, producing Alternation tokens with empty strings. This silently ignored malformed patterns that would cause incorrect matching later. Validate that all pipe-separated parts are non-empty and return EmptyAlternation error for both regular and negated alternations. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Summary of ChangesHello @fohte, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces the foundational Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new lexer for rule patterns, which is a crucial first step for the pattern parser. The implementation is well-structured and comes with a comprehensive test suite covering various cases, including literals, alternations, wildcards, negations, and more.
I've added a couple of suggestions to improve the code further by reducing duplication and using more idiomatic Rust constructs. Overall, this is a solid contribution.
Address review feedback: - Quoted string and angle bracket parsing shared identical consume-until-delimiter logic. Extract into `consume_until` helper. - `validate_alternation_parts` now uses `collect::<Result<...>>` to short-circuit on the first empty part instead of collecting all parts before validation. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Why
"curl -X|--request POST *") into raw tokensWhat
pattern_lexer) to therulesmodule-X|--request), wildcards (*), negation (!value), optional groups ([...]), placeholders (<cmd>,<path:name>), and quoted strings