npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bennu

v17.3.0

Published

Parser Combinator Library

Downloads

2,053

Readme

About

Bennu is a Javascript parser combinator library based on Parsec.

Parser combinators allow complex parsers to be created from a set of simple building blocks. Compared to other parsing techniques, combinatorial parsers can be written more quickly and integrate better with the host language.

// Very simple Brainfuck Bennuu parser in Khepri

var op := oneOf '><+-.,';

var other := many <| noneOf "><+-.,[]"; // Brainfuck ignores any other characters

var block := \body ->
    between(character '[', character ']',
        body);

var program := rec\self -> // allows referencing `program` in parse definition.
    next(
        other,                   // consume non BF chars at start,
        eager <| sepEndBy(other, // and between instructions and ending program
            either(
                op,
                block self)));

Bennu provides many Parsec parser combinators. Bennu also provides functionality like memoization and running unmodified parser combinations incrementally..

Links

Examples

  • parse-pn - Very simple polish notation calculator.
  • parse-ecma - Combinatory parsers for lexing and parsing ECMAScript 5.1
  • khepri - Khepri language lexers and parsers.
  • parse-re - ECMAScript regular expression grammar parser and engine using Bennu parser combinators.
  • parse-ecma-incremental - Demonstrates using unmodified parsers to incrementally lex ECMAScript.

Using Bennu

To clone

git clone https://github.com/mattbierner/bennu bennu
cd bennu
git submodule update --init

With Node

$ npm install bennu

Use:

var parse = require('bennu').parse;
var text = require('bennu').text;


var aOrB = parse.either(
    text.character('a'),
    text.character('b'));

parse.run(aOrB, 'b'); // 'b'

With AMD

Include any AMD style module loader and load Bennu:

requirejs.config({
    paths: {
        'bennu': './dist',
        'nu-stream': './dependencies/nu/dist',
        'seshet': './dependencies/seshet/lib/seshet'
    }
});
require(['bennu/parse'], function(parse) {
    ...
});

Modules

All files live in the top level 'parse' module.

lib/parse - 'parse/parse'

Core functionality. Defines core parsers and data structures for creating and running parsers.

lib/text - 'parse/text'

Parsers for working specifically with text.

lib/lang - 'parse/lang'

Combinatory parsers for ordering parsers, like found in a language.

lib/incremental - 'parse/incremental'

Running parsers incrementally.

Fantasy Land

Bennu parsers implement [Fantasy Land's][fs] monad, applicative, monoid and chain interfaces.

This can be used to directly . chain parsers instead of nested function calls:

var p = digit
     .chain(\x ->
          always(parseInt(x)))
    .chain(\x->
        always(x + 5))
    .chain(\x->
        always(x / 2));

run(p, '3'); // 4

Code

Parse.js is written in Khepri. Khepri is an ECMAScript language focused on functional programming that compiles to Javascript. The dist directory contains the generated js library while the Khepri sources are in lib directory.