{"id":24998,"library":"bgex-compiler","title":"BGEX Compiler","description":"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.","status":"active","version":"0.0.26","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","typescript"],"install":[{"cmd":"npm install bgex-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add bgex-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add bgex-compiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for compilation and type generation","package":"typescript","optional":false}],"imports":[{"note":"ESM-only package; CommonJS require is unsupported.","wrong":"const compile = require('bgex-compiler')","symbol":"compile","correct":"import { compile } from 'bgex-compiler'"},{"symbol":"type ASTNode","correct":"import type { ASTNode } from 'bgex-compiler'"},{"symbol":"parse","correct":"import { parse } from 'bgex-compiler'"}],"quickstart":{"code":"import { compile, parse } from 'bgex-compiler';\n\nconst grammar = `\n  expr = term ('+' term)*\n  term = factor ('*' factor)*\n  factor = '(' expr ')' | NUMBER\n  NUMBER = [0-9]+\n`;\n\nconst parser = compile(grammar);\nconst ast = parser.parse('3+4*5');\nconsole.log(ast);\n// Example output: { type: 'expr', left: { type: 'term', ... }, right: ... }","lang":"typescript","description":"Shows how to define a simple arithmetic grammar and parse an input string into an AST using BGEX."},"warnings":[{"fix":"Update to use const parser = compile(grammar); const ast = parser.parse(input);","message":"API changed in v0.0.20: compile() now returns an object with parse() instead of direct function.","severity":"breaking","affected_versions":"<0.0.20"},{"fix":"Convert input to LF before passing to compile().","message":"Grammar line endings must be Unix-style LF; Windows CRLF causes parse errors.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use compile(grammar) instead of compile({ grammar }).","message":"The 'grammar' option in compile() is deprecated; pass grammar string directly.","severity":"deprecated","affected_versions":">=0.0.20 <0.1.0"},{"fix":"Recompile grammar in each worker.","message":"Compiled parsers are not serializable; cannot be passed across worker threads.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use import { compile } from 'bgex-compiler' instead of import compile from 'bgex-compiler'.","cause":"Importing default export instead of named export.","error":"TypeError: compile is not a function"},{"fix":"Trim input and replace \\r\\n with \\n before passing to compile().","cause":"Grammar string contains trailing spaces or CRLF line endings.","error":"Error: Invalid grammar: unexpected token at line 1"},{"fix":"Ensure tsconfig.json has 'moduleResolution': 'node16' or 'bundler' and 'module': 'ESNext'.","cause":"TypeScript project not configured for ESM or missing module resolution.","error":"Cannot find module 'bgex-compiler' or its corresponding type declarations."},{"fix":"Set package.json type: 'module' or use dynamic import().","cause":"Running in CJS context; bgex-compiler is ESM-only.","error":"SyntaxError: Named export 'compile' not found. The requested module 'bgex-compiler' is a CommonJS module."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}