Skip to content

Releases: 0no-co/reghex

v3.0.0

23 Feb 11:01
40dfd6d
Compare
Choose a tag to compare
  • Added tagged template literal support. The grammar now accepts interpolation(predicate) inserts and parse(node) can be called as a tagged template literal to parse strings interspersed with interpolations
  • Improved output for + operator by replacing its special logic with ${x} ${x}* matching.
  • Add lookahead shorthands that allow shorter grammars to be written for lookaheads and non-matching groups (See #13)
  • Breaking: Only consider null and undefined as not matching (See #12)
  • Fix edge cases for zero-length matches (See #14)
  • Improve Babel plugin output, e.g. share hoisted bindings (See 0082078)

JIT Runtime Only

05 Dec 11:14
52c6845
Compare
Choose a tag to compare

JIT Code Generation

This release sees an entire rewrite of the code generation, from Babel AST types to JS string templating.
RegHex now generates its code from JS strings which allows it to build its parsers at runtime! Not only is the readability of the codegen.js much better for future maintainability and accessibility of this codebase, this adds no additional performance overhead (in theory) apart from the initial build time on initialisation. Afterwards, due to how modern JS engines work, these parsers will be as fast as they are when they're pre-compiled. You may even find that a large parser is smaller when it's not pre-compiled, since RegHex's runtime itself only weighs 1.46kB gzip!

A small side-effect of this is that you may run into circular references in the same file now. This can happen if two or more matchers reference each other out of order; A simple fix for this now is to replace an interpolation of a matcher, like ${matcher} with ${() => matcher} when this becomes a problem.

Babel Plugin

The Babel plugin has been rewritten to use the same codegen.js file that the runtime uses, by utilising @babel/template. So there aren't two versions of the code generation phase; again RegHex 2 is much more maintainable.

Since it's very possible for some projects to favour size over performance, the Babel plugin now comes with a new { "codegen": false } option. This option doesn't pre-compile any matchers and instead minifies the matcher templates for RegHex. They'll still be valid DSL syntax, but will be smaller.

Breaking Changes

The match export is now a regular export rather than a default export. Practically, the README here was correct, but actually the core.js file didn't match this. I believe that it's not necessary to have a default export on this library in general, hence the move to fix this. If you're migrating from RegHex 1 you'll have to convert all default imports of match to regular import specifiers.

What's not in this release.

Unfortunately this relase doesn't yet include better error outputs (it doesn't throw a SyntaxError with more details and a nice message when a matcher fails) but that's on the horizon now.

Tagged template literal parsing support also isn't here yet, but it should be easier than ever to add this, thanks to a leaner codebase.