Registry / devops / bgex-compiler

bgex-compiler

JSON →
library0.0.26jsnpmunverified

BGEX (Better Grammar EXtractor) is a language and compiler for defining and generating context-free grammar parsers. v0.0.26 compiles BGEX source into TypeScript parsers that export typed AST nodes. It relies on TypeScript >=5.0 as a peer dependency. Differentiators include native ESM, full TypeScript support, and lightweight output with no runtime dependencies.

npm install bgex-compiler
INSTALL
IMPORT
SIG · BGEX-COMPILER
B
bgex-compiler
devopsjavascriptv0.0.26
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

compile
import { compile } from 'bgex-compiler'
const compile = require('bgex-compiler')
ESM-only package; CommonJS require is unsupported.
type ASTNode
import type { ASTNode } from 'bgex-compiler'
parse
import { parse } from 'bgex-compiler'

Shows how to define a simple arithmetic grammar and parse an input string into an AST using BGEX.

import { compile, parse } from 'bgex-compiler'; const grammar = ` expr = term ('+' term)* term = factor ('*' factor)* factor = '(' expr ')' | NUMBER NUMBER = [0-9]+ `; const parser = compile(grammar); const ast = parser.parse('3+4*5'); console.log(ast); // Example output: { type: 'expr', left: { type: 'term', ... }, right: ... }
bgex --version
Debug
Known issues
breakingAPI changed in v0.0.20: compile() now returns an object with parse() instead of direct function.
fix
Update to use const parser = compile(grammar); const ast = parser.parse(input);
affects: <0.0.20
gotchaGrammar line endings must be Unix-style LF; Windows CRLF causes parse errors.
fix
Convert input to LF before passing to compile().
affects: >=0.0.0
deprecatedThe 'grammar' option in compile() is deprecated; pass grammar string directly.
fix
Use compile(grammar) instead of compile({ grammar }).
affects: >=0.0.20 <0.1.0
gotchaCompiled parsers are not serializable; cannot be passed across worker threads.
fix
Recompile grammar in each worker.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: compile is not a function
Importing default export instead of named export.
fix
Use import { compile } from 'bgex-compiler' instead of import compile from 'bgex-compiler'.
Error: Invalid grammar: unexpected token at line 1
Grammar string contains trailing spaces or CRLF line endings.
fix
Trim input and replace \r\n with \n before passing to compile().
Cannot find module 'bgex-compiler' or its corresponding type declarations.
TypeScript project not configured for ESM or missing module resolution.
fix
Ensure tsconfig.json has 'moduleResolution': 'node16' or 'bundler' and 'module': 'ESNext'.
SyntaxError: Named export 'compile' not found. The requested module 'bgex-compiler' is a CommonJS module.
Running in CJS context; bgex-compiler is ESM-only.
fix
Set package.json type: 'module' or use dynamic import().
Upgrade
Version history
0.0.26latest on npm
Audit
Dependencies
typescriptrequiredpeer dependency for compilation and type generation
Agent activity
15 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources