Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parsing of lookarounds #4

Merged
merged 11 commits into from
Mar 13, 2025

Conversation

shilangyu
Copy link
Collaborator

No description provided.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This pull request adds parsing, AST generation, HIR translation, and testing support for lookaround assertions (specifically lookbehinds) in regular expressions. Key changes include:

  • Updating the parser (and related group parsing functions) to handle lookaround syntax.
  • Implementing HIR translation for the new LookAround AST node.
  • Adding and updating tests for lookaround parsing and printing.

Reviewed Changes

File Description
regex-syntax/src/hir/print.rs Updated lookaround tests by removing the ignore attribute and introducing a dedicated test helper function.
regex-syntax/src/ast/parse.rs Modified group parsing (renamed to grouping) to support lookaround syntax and added error handling for unsupported lookahead.
regex-syntax/src/hir/translate.rs Implemented HIR translation for LookAround AST nodes with separate handling for positive and negative lookbehinds.
regex-syntax/src/ast/mod.rs Introduced a new LookAroundUnclosed error variant and updated function naming for consistency.
regex-syntax/src/hir/literal.rs Updated tests to validate lookaround handling in literal printing.
regex-syntax/src/hir/mod.rs Minor comment updates reflecting the new "look-around" terminology in the HIR module.

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (3)

regex-syntax/src/hir/print.rs:489

  • [nitpick] Consider rephrasing the comment for clarity. For example, 'We do not perform a roundtrip for lookarounds because they cannot contain capture groups, which are unsupported by the parser.'
// we do not want to do a roundtrip: printed lookarounds are not
// can contain capture groups which are unsupported by the parser.

regex-syntax/src/hir/translate.rs:449

  • [nitpick] Ensure that the translation logic for LookAround covers both positive and negative lookbehinds in all edge cases; consider adding a clarifying comment to explain the branching logic.
Ast::LookAround(ref x) => {

regex-syntax/src/hir/literal.rs:2458

  • [nitpick] Verify that the tests for lookaround in literal handling accurately reflect the intended behavior, and consider adding tests for lookarounds with non-empty sub-patterns.
fn lookaround() { assert_eq!(exact(["ab"]), e(r"a(?<=qwe)b")); ... }

Base automatically changed from feat/cl_lb-ast to captureless-lookbehinds March 11, 2025 14:59
@shilangyu shilangyu force-pushed the feat/cl_lb-parsing branch from 0b66651 to b2e3222 Compare March 11, 2025 20:32
Copy link
Owner

@Multimodcrafter Multimodcrafter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Multimodcrafter Multimodcrafter merged commit f87b5c0 into captureless-lookbehinds Mar 13, 2025
@Multimodcrafter Multimodcrafter deleted the feat/cl_lb-parsing branch March 13, 2025 08:10
@shilangyu shilangyu mentioned this pull request Mar 18, 2025
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.

2 participants