8000 Replace regex with parser by jpsca · Pull Request #119 · jpsca/jinjax · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace regex with parser #119

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

Merged
merged 2 commits into from
May 11, 2025
Merged

Replace regex with parser #119

merged 2 commits into from
May 11, 2025

Conversation

jpsca
Copy link
Owner
@jpsca jpsca commented May 11, 2025

My quick-and-dirty regex for parsing component tags finally backfired when I tried to add a Stimulus action

<Button data-action="click->hello#greet">Greet</Button>

... and JinjaX treated the > in click-> as the closing tag. 🤦‍♂️

So I had to write a real parser. While adding tests, I found the old code also allowed syntax errors like unmatched quotes or braces. The new parser fixes all that so is another win 👍.

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.

Pull Request Overview

This PR replaces a fragile regex-based approach for parsing component tags with a dedicated parser to prevent misinterpretation of embedded characters and syntax errors.

  • Introduces comprehensive test cases for both valid and invalid component tags.
  • Refactors JinjaX methods to use new functions (replace_raw_blocks, process_tags, restore_raw_blocks) and a new parser for opening tags.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/test_extension.py Added extensive test cases covering different component tag scenarios including nested and invalid cases.
src/jinjax/jinjax.py Replaces regex parsing with a new parser implementation and refactors private methods to public ones with updated naming.
Comments suppressed due to low confidence (1)

src/jinjax/jinjax.py:129

  • The variable name 'max' shadows the built-in function 'max'. Consider renaming it (for example, 'source_length') for better clarity and to avoid potential issues.
max = len(source)

@jpsca jpsca merged commit 6d4e947 into main May 11, 2025
4 checks passed
@jpsca jpsca deleted the parser branch May 11, 2025 04:08
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.

1 participant
0