Registry / serialization / reghex

reghex

JSON →
library3.0.2jsnpmunverified

Reghex is an experimental, actively developed JavaScript parser generator that leverages the power of sticky regular expressions and runtime code generation to allow developers to quickly define and build parsers. Currently at version 3.0.2, it enables parser creation using a regex-like Domain Specific Language (DSL) within tagged template literals. Reghex offers flexibility by supporting both build-time pre-compilation via an optional Babel plugin (or `babel-plugin-macros` integration) and Just-In-Time (JIT) compilation at runtime, which incurs minimal overhead. Its core differentiator is the use of JavaScript's sticky regexes (`/y` flag) as the fundamental parsing primitive, allowing for efficient, continuous pattern matching by internally managing `lastIndex`. While still in its early stages with a potentially evolving API and a slower, feature-driven release cadence marked by major versions, it provides a unique approach to parser construction in JavaScript. Performance on older browsers like IE11 may be reduced due to its sticky regex polyfill.

npm install reghex
INSTALL
IMPORT
SIG · REGHEX
R
reghex
serializationjavascriptv3.0.2
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

match, parse
✓ import { match, parse } from 'reghex';
✗ const { match, parse } = require('reghex');
Reghex is designed for ESM environments, using `import` for its primary API. While CJS might work in some transpiled setups, direct `require` is not the recommended or idiomatic approach.
reghex/babel
✓ {"plugins": ["reghex/babel"]}
✗ import 'reghex/babel';
This is a Babel plugin, not a runtime import. It's configured in your Babel config file (e.g., `.babelrc`) as a string in the plugins array, not imported as a module.
reghex/macro
✓ import macro from 'reghex/macro';
✗ import { reghex } from 'reghex/macro';
When using `babel-plugin-macros`, you import the macro's default export. The README implies usage like `parse(name)` after an `import { match, parse } from 'reghex';` which is then transformed by the macro. The `reghex/macro` import itself is typically for type inference or more advanced macro usage if not directly using `reghex` as the macro source.

This quickstart demonstrates how to define a simple parser using `match` with a tagged template literal and then use `parse` to apply it to an input string.

import { match, parse } from 'reghex'; // Define a matcher for a simple word, tagged with 'name' const name = match('name')` ${/\w+/} `; // Define a more complex matcher for a greeting pattern const greeting = match('greeting')` Hello, ${match('person')`${/\w+/}`} ! `; // Parse a simple string using the 'name' matcher const resultName = parse(name)('world'); console.log('Parsed name:', resultName); // Expected: [ "world", .tag = "name" ] // Parse a string using the 'greeting' matcher const resultGreeting = parse(greeting)('Hello, John!'); console.log('Parsed greeting:', resultGreeting); // Expected: [ "John", .tag = "person", ... ]
Debug
Known issues
breakingVersion 3.0.0 introduced breaking changes related to grammar interpolation inserts and the `+` operator's internal handling, potentially affecting existing parser definitions. The exact extent of the breaking change for 'Only consider' is not fully documented in the provided excerpt.
fix
Review existing parser grammars, especially those using interpolation predicates or the `+` operator, and adapt them to the new DSL behavior outlined in the v3.0.0 release notes.
affects: >=3.0.0
breakingVersion 2.0.0 involved an entire rewrite of the code generation, shifting from Babel AST types to JS string templating for JIT runtime compilation. This fundamentally changed how parsers are built and could break integrations relying on previous internal mechanisms or specific Babel AST transformations.
fix
Re-evaluate build processes and any custom tooling that interacted with Reghex's internal code generation, as the underlying architecture has been completely overhauled.
affects: >=2.0.0 <3.0.0
gotchaThe project is explicitly marked as 'experimental' and 'in its early stages'. The API may still change frequently, and stability is not guaranteed across minor or patch releases.
fix
Exercise caution when deploying `reghex` in production environments. Pin dependency versions tightly and thoroughly test after any updates. Monitor GitHub for announcements of API changes.
affects: >=1.0.0
gotchaReghex's reliance on sticky regexes (`/y` flag) is polyfilled for browsers that don't natively support it, such as Internet Explorer. This polyfill may lead to decreased parsing performance in these older environments.
fix
If targeting environments like IE11, benchmark parser performance and consider alternative parsing strategies or selective loading if performance is critical for those users.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Invalid regular expression: /.../: Nothing to repeat
A malformed regular expression segment was used within the `match` tagged template literal, often due to an empty group or quantifier applied to nothing.
fix
Review the regex patterns within your `match` definition. Ensure all quantifiers are applied to a valid character, group, or expression. For example, `(a)?*` is invalid.
TypeError: reghex.match is not a function
Attempting to use `reghex.match` directly when `match` is a named export, or incorrect module import method (e.g., CommonJS `require` in an ESM context).
fix
Ensure you are using `import { match, parse } from 'reghex';` for ESM. If using CommonJS, verify your transpilation setup or check if a default export exists (which it doesn't for the main API).
ReferenceError: require is not defined (when using 'const { match } = require("reghex");')
Attempting to use CommonJS `require` syntax in an ES Module environment (e.g., a modern Node.js project or browser with `type: "module"` in `package.json`).
fix
Switch to ES Module import syntax: `import { match, parse } from 'reghex';`.
Upgrade
Version history
3.0.2latest on npm
Audit
Dependencies
@babel/coreoptionalPeer dependency for the optional `reghex/babel` plugin to transpile tagged template literals at build time.
babel-plugin-macrosoptionalOptional peer dependency if using the `reghex/macro` integration instead of the direct Babel plugin.
Agent activity
6 hits · last 30 days
node
6
Resources
reghex — npm install reghex · libregistry