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

fix: correct regexp slash escapes #149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

JoshuaKGoldberg
Copy link

@JoshuaKGoldberg JoshuaKGoldberg commented Oct 31, 2024

Fixes #68 in support of eslint/eslint#16555.

This solution is a kind of hacky workaround based on #68's comments. It "encodes" all backslash-escaped forward slashes ('\\' + '/') with a backslash and an equivalent unicode character ('\\' + '\\x2F').

I think it would be much better to work within the PEG grammar in grammar.pegjs. Unfortunately, there is no backtracking or other nontrivial regular expression techniques in PEG.js. Expressions like d:[^\/]+ ("capture any number of characters other than /, under the name d") don't have a way I could find to, say, skip past a character like \.

& { predicate } and ! { predicate } with matchers like "/" d:.+ { ... } "/" or just "/" d:.+ { ... } also seemed promising. But then I couldn't figure out how to get it to match non-greedily: i.e. the full /foo\/bar/ instead of just /foo\/.

I don't often work with PEGs and am not confident I didn't miss some obvious technique. I hope someone who's more experienced in these matters will point something out that's more PEG-oriented. 🙂

grammar.pegjs Outdated Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review November 4, 2024 19:26
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.

RegExp slash escapes not parsed correctly
1 participant