whynot.js is a generic, VM-based framework for matching formal languages, drawing inspiration from systems like Russ Cox's regular expression engine. It operates by considering all possible branches of a program in parallel, enabling efficient implementation of various language matching tasks, including regular expressions and XML schemas. A key differentiator is its ability to record program progress through input and grammar, providing detailed feedback on *why* an input might not match a given grammar. The current stable version is 5.0.0, with releases focusing on performance, memory optimization, and module compatibility (ESM/CJS). While there isn't a strict release cadence, updates address bug fixes, dependency bumps, and significant architectural improvements.
npm install whynotVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates defining a basic VM program using `Instruction`s, initializing a `VM` with it, and executing an input array to check for a match. It shows both a matching and non-matching scenario.
Ensure your bundler or environment correctly resolves `whynot` or update any direct import paths to the UMD bundle if you are targeting older CJS environments and not using ESM.
Verify your bundler (e.g., Webpack, Rollup) is configured to correctly select the appropriate module entry point. You may need to update `main` or `module` fields in package.json if manually overriding module resolution.
Update all calls to `vm.execute()` to pass an array of input items (e.g., `vm.execute(['a', 'b'])`) instead of a function.
Refactor code that accessed `trace.records`. If you need to record progress, ensure your program explicitly uses `Instruction.record` and retrieve trace information through other means if available, or reconsider the design of your program.
Avoid accessing `trace.head`. For recorded paths, rely on explicit `Instruction.record` and check `trace.records` for `null` before iterating.
For older browser support, integrate a transpilation step (e.g., Babel with appropriate presets) into your build pipeline to down-level whynot's output to your target ECMAScript version.
Ensure your environment supports ESM imports (`import ... from 'whynot';`). If you must use CommonJS, ensure your bundler is configured to pick up `whynot.umd.js` or that Node.js is running in an ESM-compatible context for imported modules.
Change your `vm.execute()` call to pass an array of input items, e.g., `vm.execute(['item1', 'item2'])`.
Always check if `trace.records` is not `null` before attempting to iterate or access its elements, e.g., `if (trace.records) { trace.records.forEach(...) }`.Remove any code that attempts to access `trace.head`. You will need to find alternative ways to determine the start of a trace if that was its purpose.
No dependency data recorded yet.