Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bnf-parser

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bnf-parser

Deterministic BNF compiler/parser

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.8K
increased by11.74%
Maintainers
1
Weekly downloads
 
Created
Source

A simple library to parse input strings into token trees based on a BNF's description.

BNF trees must first be compiled before they can be used to parse syntax trees.

Compilation

let result = BNF.parse(file, BNF.syntax);
let tree = BNF.compile(result.tree);

A compiled BNF can be saved as a JSON file and reloaded later

// Store the compiled result for later use
fs.writeFileSync(path, JSON.stringify(tree));

// Load the compiled BNF
let tree = BNF.fromJSON(
  JSON.parse( fs.readFileSync(path, 'utf8') )
);

Parsing

Running parse will return a BNF_Parse object, which contains a tree structure of BNF_SyntaxNodes. How these nodes are structured depends on the compiled BNF used to parse the syntax.

BNF: Build

Provided with BNF data, this will return a BNF_Tree with error handling.

BNF: Syntax

The BNF used by this application is a dilect of regular extensions for BNF. Most noteably it adds the not (!) opperator.

The BNF outlining the syntax of BNFs used by this system can be found here.

BNF Opperator: Not

The not operator must be before a set of brackets, and will consume characters until either the quota is met, or the pattern within the brackets successfully matches.
The quota of the not operation can be defined the same was as constants and terms via the use of +, *, ? operators.

Keywords

FAQs

Package last updated on 03 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc