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

@anonimitoraf/bnf

v1.0.1

Published

BNF Compiler, parser, and interpreter framework.

Downloads

273

Readme

BNF

BNF is a script language parsing library for JavaScript and tested with NodeJS. Re-writen from scatch to allow for ABNF and to utilize ECMA 6+.

Description

BNF is both a framework for an interpreter, BNF compiler, and a language parser. It can use BNF, ABNF, or a blend of the two. The prior version used a custom JavaScript mark-up which was molded after BNF to interpret script files, this feature was removed in favor of inline compiling.


Predefined Rules

  • BLANK : ''
  • CR : '\r'
  • LF : '\n'
  • CRLF : CR LF | CR | LF
  • DIGIT : 1-0
  • DIGITS : 1*DIGIT
  • NUMBER : DIGITS [ "." DIGITS ] | "." DIGITS
  • WSP : 1*(SPACE | TAB)
  • TAB : '\t'
  • SPACE : ' '
  • OWSP : WSP | BLANK
  • ANYWSP : *( CRLF | WSP )
  • ALPHA : A-Z a-z
  • SYMBOL : !@#$%^&...ect. Does not include '', ''', '"', or '`'
  • ESCAPE : ''
  • QUOTE : '"'
  • SQUOTE : '''
  • AQUOTE : '`'
  • ANYCHAR : CHAR | DIGIT | SYMBOL
  • SQLITERAL : SQUOTE *( ( ESCAPE SQUOTE ) | ANYCHAR | QUOTE | AQUOTE | ESCAPE ) SQUOTE
  • QLITERAL : QUOTE *( ( ESCAPE QUOTE ) | ANYCHAR | SQUOTE | AQUOTE| ESCAPE ) QUOTE
  • AQLITERAL : AQUOTE *( ( ESCAPE AQUOTE ) | ANYCHAR | SQUOTE | QUOTE | CRLF| ESCAPE ) AQUOTE
  • LITERAL : SQLITERAL | QLITERAL
  • ANYLITERAL : AQLITERAL | SQLITERAL | QLITERAL
  • EOF : End of the file.
  • SCRIPT : The whole script, which is SYNTAX EOF.
  • SYNTAX : The syntax body for the script. The BNF script must declare this.

Supported Syntax

  • BNF

    • <rule> ::= <expression> | "literal"
  • ABNF

    • rule = expression / "literal"
  • Groups

    • rule = ( expression | ... )
  • Optional

    • rule = [ expression ... ]
  • Repeats

    • rule = 1*2expression
    • rule = *2expression
    • rule = 1*expression
  • Char Lookups

    • rule = %x0-ff
    • rule = %xff
  • Not ( Should be used in an AND where a char is allowed so long as it is not a sequence )

    • rule = !"}}" %x7d

Example of Use

Install:

npm install bnf

Basic setup and usage:

let compiler = new Compiler();
compiler.AddLanguage( `
  <SYNTAX> ::= <evaluation> | <evaluation> <CRLF> <SYNTAX>
  <evaluation> ::= <number> <OWSP> <type> <OWSP> <number>
  <number> ::= <DIGITS>
  <type> ::= "+" | "-" | "/" | "*"
`, "testLang" );
compiler.SetRuleEvents({
  evaluation( token ){
    console.log( "evaluation token found answer:", eval( token.value ) );
  }
});

compiler.ParseScript( `
5456 / 13
11 + 3
10 * 8
`.trim() );

Multiple scripting language in one script:

In the first versions of BNF it was supported to be able to change in and out of languges though the course of a single script. This feature will be kept, the following is the plan for use, however not implmented yet.

compiler.AddLanguage( ..., "otherScript" );

<SYNTAX> ::= <myscript> #otherScript | <myscript>

See examples:


Status

The BNF and ABNF parser and compiler work great!

With the following caviot: custom BNF rules can be written into the engine, however the way tokens work with rules is going to be changing over the course of this minor version. This will break and uses of custom rules. At the end of this major version custom rules will be fully supported.

@LHF

This is a part of the code that has a weak level of optimizations and is considered low hanging fruit for fixes that can improve performance.