ES RegExp processor

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ES RegExp processor

Dmitry Soshnikov
(this is mostly an FYI post on JS regexes processing tool)

Recently I've been posting about ES RegExp parser[1], which eventually got evolved into a generic ES RegExp processor (called `regexp-tree`). This can be used for different kinds of purposes, and regarding ECMAScript spec -- it can be used to check/implement new proposals, new syntax, etc.

Currently the tool includes the following modules:

- Parser (including support for recent stage 3 proposals)
- Traversal
- Generic transformer
- Optimizer
- Compat-transpiler
- Interpreter (work in progress)

For example, the `optimizer`[2] module is capable of translating, and fixing your regexes from:

```js
/[a-zA-Z_0-9][A-Z_\da-z]*\e{1,}/
```

To equivalent:

```js
/\w+e+/
```

There is also an ESLint plugin with auto-fixing exist for it.

And the `compat-transpiler`[3] can be used to run/translate named capturing groups, "dotAll" flag, etc.

```js
/(?<value>a)\k<value>\1/
```

Translated into (with tracking group names for further runtime purposes):

```js
/(a)\1\1/
```

The `interpreter` module can be used to actually run new regexes, or check semantics of the spec, when new features are added. This may follow at implementation an actual ES spec (and other DFA/NFA engines can be built). Note: there is also a way to run newer regexes using compat-transpiler.

Please feel free to reach me in case you have any questions, or would like to add/implement any new feature in the tool.

Dmitry




_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Loading...