ZeParser JavaScript Parser

0.0.7 · abandoned · verified Sun Apr 19

ZeParser is an early-stage JavaScript parser, last published as version 0.0.7 in June 2013. Developed by Peter van der Zee, it was designed to convert JavaScript input into a 'parse tree' (an array of arrays with tokens as leaves) or various token streams, including a 'white tree' (all tokens, including whitespace) and a 'black tree' (token stream without whitespace). The package also offered a `createParser` method to instantiate a parser with parsed input and access these tree structures directly. It featured simple and extended parsing modes, with the extended mode providing richer meta-information. While historically relevant for JavaScript parsing benchmarks, the project has been abandoned since its last release, meaning it does not support modern JavaScript syntax (ES2015+), lacks ongoing maintenance, and has no defined release cadence. An experimental v2 (`zeparser2`) was later introduced but also appears to be unmaintained.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `ZeParser.parse()` to get a basic parse tree and `ZeParser.createParser()` to access detailed token streams (including and excluding whitespace/comments). It highlights the CommonJS `require` syntax.

const ZeParser = require('zeparser');

const inputCode = `
  function greet(name) {
    // A simple comment
    return 'Hello, ' + name + '!';
  }
  var message = greet('World');
`;

console.log('--- Parsing with ZeParser.parse() ---');
const parseTree = ZeParser.parse(inputCode);
// The parse tree is an array of arrays representing the AST structure.
// It includes tokens as leaf nodes.
console.log('Parse Tree (excerpt):', JSON.stringify(parseTree, null, 2).substring(0, 500) + '...');

console.log('\n--- Using ZeParser.createParser() for detailed token streams ---');
const parserInstance = ZeParser.createParser(inputCode);

// .wtree (white tree) includes all tokens, including whitespace and comments
console.log('White Tree (first 5 tokens):', parserInstance.wtree.slice(0, 5));

// .btree (black tree) is the token stream without whitespace, line terminators, or comments
console.log('Black Tree (first 5 tokens):', parserInstance.btree.slice(0, 5));

// Accessing a token's properties, e.g., the first token in the black tree
if (parserInstance.btree.length > 0) {
  const firstToken = parserInstance.btree[0];
  console.log('First token in black tree (type, value):', firstToken.type, firstToken.value);
}

view raw JSON →