-
-
Notifications
You must be signed in to change notification settings - Fork 42
Add browser-based WASM playground for fancy-regex with enhanced configurability and proper flag handling #181
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 browser-based WASM playground for fancy-regex with enhanced configurability and proper flag handling #181
Conversation
Co-authored-by: keith-hall <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, looks good! A few things to fix and improve but this is a great start! 🎉
… new features Co-authored-by: keith-hall <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more changes needed. In particular it makes sense to promote code-reuse where possible and ensure that documentation is up-to-date.
…e footer info, automate version Co-authored-by: keith-hall <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more small comments, keep up the good work!
…, improve capture names Co-authored-by: keith-hall <[email protected]>
for better transparency of what is deployed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done a quick pass and added some comments. Haven't looked through the JS and HTML in detail yet.
uses: actions/checkout@v5 | ||
|
||
- name: Setup Rust | ||
uses: actions-rs/toolchain@v1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is no longer maintained, we should use e.g. https://github.com/dtolnay/rust-toolchain instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, updated
wasm-pack build --target web --out-dir pkg --release | ||
cp -r pkg/ web/ | ||
touch web/.nojekyll | ||
rm web/pkg/.gitignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Maybe it should be excluded somewhere else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GitHub Action for deploying to GitHub Pages respects .gitignore
, but we don't want to commit the compiled WASM stuff to git normally - just for the gh-pages branch. So this was the easiest solution I could think of, maybe there is a better way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was still confused why the .gitignore
is there in the first place, but now ran this locally. Even other files like README.md
are there:
❯ ls -a web/pkg/
./ fancy_regex_playground_bg.wasm.d.ts package.json
../ fancy_regex_playground.d.ts README.md
.gitignore fancy_regex_playground.js
fancy_regex_playground_bg.wasm LICENSE
Maybe instead of doing cp -r pkg/ web/
we could just do cp -r pkg/fancy_regex* web/pkg/
? Ah but then pkg
would need to be not ignored 🤔. Maybe it's fine the way it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this to gh-pages
, as it deploys the whole page (clean: true
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this crate going to be published when we run cargo publish
in the root of the repository? If yes, can we exclude it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question 🙂 I did a cargo publish --dry-run
on the root of the repository and it only wanted to publish fancy-regex, not the playground 👍
playground/build.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this is for. If for local development, we don't need the version stuff.. And if so, maybe the README should just defer to this one.. Or maybe we just leave the stuff in the readme and get rid of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's for local development, and I updated CI/CD to re-use it too, to make it easier to maintain and be confident that the GitHub Actions work as expected. I therefore removed the manual instructions in the readme.
both the readme and CI/CD now use build.sh for consistency
don't require callers to analyze to do the logic of determining the start group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more comments. Still some things we could improve with the styling and UI, but I think it's good enough to merge once comments are addressed!
playground/README.md
Outdated
- Named capture groups (`(?<name>...)` and `\k<name>`) | ||
- Lookahead and lookbehind assertions | ||
- All other fancy-regex features | ||
- **Real-time Highlighting**: Visual highlighting of matches and capture groups in the test text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having tried it out, it doesn't actually highlight capture groups, only matches?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed, I have now corrected the readme
playground/web/index.html
Outdated
<input type="checkbox" id="flag-ignore-whitespace"> | ||
<label for="flag-ignore-whitespace">Ignore whitespace</label> | ||
</div> | ||
<div class="flag-group" style="display: none;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
display: none;
is one way to remove this 😆.. Can you clean this and the corresponding code up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
playground/web/index.html
Outdated
</div> | ||
|
||
<div class="input-group"> | ||
<label for="debounce-delay">Update Delay (ms):</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this really needs to be configurable in the UI? I would probably remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed :)
playground/web/index.html
Outdated
padding: 1rem; | ||
border-radius: 4px; | ||
white-space: pre-wrap; | ||
font-family: 'Courier New', monospace; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why they have a different monospace font here. In general the fonts are bit all over the place currently (e.g. the blue buttons have a different font from the rest). I think we should have:
- Set a generic non-monospace font for all the UI stuff (including the buttons)
- Only use monospace for the input and result text boxes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
playground/web/index.html
Outdated
<div class="panel-header">Input</div> | ||
<div class="panel-content"> | ||
<div class="input-group"> | ||
<label for="regex-input">Regular Expression:</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use "Title Case" anywhere, but instead just "Sentence case", so e.g. "Regular expression:", "Case insensitive" etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done :)
playground/web/index.html
Outdated
</head> | ||
<body> | ||
<div class="header"> | ||
<h1>🎯 fancy-regex Playground</h1> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the emoji personally.. Was wondering if we could use something that reminds us of regexes. Maybe /fancy-regex playground/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great idea, done :)
change playground page heading and title
change from title case to sentence case in the playground html
move styles to separate stylesheet
- Set a generic non-monospace font for all the UI stuff (including the buttons) - Only use monospace for the input and result text boxes (and parse tree/analysis output)
Make readme more accurate with regards to current features of the playground
remove debounce delay input
remove hidden unicode flag
…390d-3d28-4341-9de0-237db53e7177
This PR introduces a comprehensive browser-based playground for the fancy-regex crate, compiled to WebAssembly (WASM). The playground provides an interactive interface for testing and exploring advanced regex features like backreferences and lookaround assertions.
Features
🎯 Interactive Regex Testing
🔍 Advanced Analysis Tools
⚡ Performance & UX
Technical Implementation
WASM Module (
playground/src/lib.rs
)find_matches
,find_captures
,parse_regex
,analyze_regex
,is_match
parse_tree_with_flags
capture_names()
methodFrontend (
playground/web/
)Development & Deployment
serve.py
)build.sh
) with version injection from main Cargo.tomlExample Usage
The playground demonstrates fancy-regex capabilities with examples like:
Code Quality Improvements
Deployment
The playground can be deployed to GitHub Pages automatically via the included GitHub Actions workflow, making it accessible at
https://fancy-regex.github.io/fancy-regex/
.This addition significantly enhances the accessibility of fancy-regex by providing an interactive way for users to learn and experiment with advanced regex features without requiring local Rust installation.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.