Registry / serialization / simple-parser

simple-parser

JSON →
library0.0.0jsnpmunverified

A lightweight, minimalistic parser for simple grammars, currently at version 0.0.0. It aims to provide a straightforward API for tokenizing and parsing input strings with user-defined rules. Unlike more complex parser generators (e.g., ANTLR, PEG.js), simple-parser focuses on simplicity and zero dependencies, making it suitable for small projects or educational use. The release cadence is not yet established as it is in early development. Key differentiators include a tiny footprint and an intuitive rule definition syntax.

npm install simple-parser
INSTALL
IMPORT
SIG · SIMPLE-PARSER
S
simple-parser
serializationjavascriptv0.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

Parser
import Parser from 'simple-parser'
const Parser = require('simple-parser')
ESM-only; no CommonJS support.
Token
import { Token } from 'simple-parser'
import Token from 'simple-parser'
Token is a named export, not default.
Rule
import { Rule } from 'simple-parser'
TypeScript type export, not available at runtime.

Creates a parser for simple arithmetic expressions using digit and plus rules, then parses a string.

import Parser from 'simple-parser'; const parser = new Parser(); parser.define('DIGIT', /[0-9]/); parser.define('PLUS', /\+/); parser.define('expr', ['DIGIT', 'PLUS', 'DIGIT']); const result = parser.parse('3+5'); console.log(result); // ['3', '+', '5']
Debug
Known issues
deprecatedMethod `parseAll` has been deprecated in favor of `parse`.
fix
Replace `parser.parseAll(input)` with `parser.parse(input)`.
affects: <=0.0.0
gotchaRules are defined with arrays, not strings; using strings silently fails.
fix
Always use array syntax: `parser.define('ruleName', ['TOKEN1', 'TOKEN2'])`.
affects: >=0.0.0
gotchaParser does not support regex flags like 'g' or 'i' in token definitions.
fix
Use simple regex patterns without flags; pre-transform input if case-insensitivity needed.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: Parser is not a constructor
Importing incorrectly (CommonJS usage).
fix
Use import Parser from 'simple-parser' (ESM).
ReferenceError: Token is not defined
Attempting to use Token as a runtime value when it is a type-only export.
fix
Remove Token from runtime imports; it's only for TypeScript types.
Error: Rule 'xxx' is not a string or array
Passing a string to define() instead of an array of token names.
fix
Change parser.define('rule', 'TOKEN') to parser.define('rule', ['TOKEN']).
Upgrade
Version history
0.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
Amazon
1
Resources
simple-parser — npm install simple-parser · libregistry