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 new XRegExp backend #1

Open
slevithan opened this issue Jun 4, 2012 · 1 comment
Open

Add new XRegExp backend #1

slevithan opened this issue Jun 4, 2012 · 1 comment

Comments

@slevithan
Copy link

Are you interested in adding an XRegExp backend (separate from the standard JavaScript backend)? It should be easy to do, since you already support JavaScript with Node.js. You'd probably just need to include XRegExp (var XRegExp = require('xregexp').XRegExp;, after installing with npm), add checkboxes for XRegExp's three nonnative flags (s, x, and n), and use XRegExp.replace/exec/test/split rather than the native methods, for testing.

Actually, since XRegExp compiles to native regexes, you don't even need to use XRegExp.exec/test/split. You do need XRegExp.replace, to use XRegExp's replacement text syntax. You'd probably also want to use XRegExp.exec, so that you get named backreferences on the result array.

If you have any questions or run into any issues, I'd be happy to help.

@slevithan
Copy link
Author

@fileformat I see you've added XRegExp support in commit e2333b8, and that the XRegExp version of the tester is now live. That's awesome!

A few issues to report about the XRegExp support, though.

Not specific to XRegExp:

  • Spaces in the input show up as + signs in the results (in the input, replace, split, and exec columns). Spaces are also replaced with pluses in the regex source, which sometimes leads to syntax errors.
  • The input.replace column should be labeled input.replace(), for consistency with the other columns.
  • The input.split column should be labeled input.split(), for consistency with the other columns.
  • The regex.exec()[] column should be labeled regex.exec(), unless the split column is labeled input.split()[].

Specific to XRegExp:

  • The page should run XRegExp.install('natives') when it first loads (if running the XRegExp tester rather than native JavaScript tester), to enable the XRegExp replacement text syntax. Alternatively, you could pass the input through XRegExp.replace instead of String.prototype.replace, in which case you wouldn't need the XRegExp.install('natives') line.
  • The XRegExp flags s, x, and n are never actually applied, even when their checkboxes are checked.
  • Remove the option for flag y. XRegExp supports flag y only in JavaScript environments that natively support it (i.e., Firefox 3+). Node.js/V8 does not support flag y, so it would cause an error if RegexPlanet actually applied it.

Feature requests, specific to XRegExp:

  • Display named backreferences in the regex.exec() column. To do this, you'd need to loop over properties of the result array. In order for named backreferences to actually show up on the result array, you'd need to either run the XRegExp.install('natives') line that I mentioned earlier (after loading XRegExp), or pass the input through XRegExp.exec rather than RegExp.prototype.exec.
  • Upgrade to the latest build of XRegExp 3.0.0-pre. Even though this is not yet ready for final release, the implemented changes are at release quality, and it is unlikely that any remaining changes will affect RegexPlanet's use of it. By upgrading to v3.0.0-pre, you get several syntax changes:
    • Support for the new flag A, and its corresponding support for supplementary/astral Unicode code points.
    • Using multiple groups with the same name is now an error.
    • Using the group name length or __proto__ is now an error.
    • Single-letter Unicode categories such as \p{L} can now be written as \pL.

The full list of changes is currently in the roadmap. The release of v3.0.0-final might be delayed for a while since I need to focus on other projects, which is why I think it makes sense to go ahead and upgrade early. Flag A, in particular, would be very useful to test with.

If you have any questions, I'd be happy to help!

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

No branches or pull requests

1 participant