GithubHelp home page GithubHelp logo

node-abnf's Introduction

Parse ABNF grammars

For more information on the flavor of ABNF (Augmented Backus-Naur Form) supported by this project, see RFC 5234 and RFC 7405.

Installation:

npm install -g abnf

Example:

import { parseFile } from "abnf";
const rules = await parseFile("myfile.abnf");

CLI

There are a few binaries included:

abnf_check

Check the given ABNF file for correctness.

abnf_ast

Output the generated abstract syntax tree for the ABNF input. This output is mostly diagnostic in nature, not really meant to be parsed.

abnf_gen

Generate a Peggy grammar from the ABNF. The idea is that you could then annotate this grammar with actions in order to create a useful parser.

abnf_test

Using an ABNF, test inputs to see if they match. Returns the Peggy parse tree, which will likely be somewhat confusing until you're familiar with Peggy.

Workflow

$ cat << EOF > foo.abnf
f = "abc"
EOF
$ abnf_gen foo.abnf
$ cat foo.peggy
f
  = "abc"i
$ abnf_test foo.abnf -t abc
'abc'
$ abnf_test foo.peggy -t ab
Error: Expected "abc" but "a" found.
 --> command line:1:1
  |
1 | ab
  | ^

API

.parseFile(input)

Parse the file with the given name, returning a promise for a Rules object.

.parseString(input, grammarSource = "unknown")

Parse the given string and return a Rules object. The grammarSource is the name of the file that the input came from.

.parseStream(stream, grammarSource = "stdin")

Read the stream, parse it, and return a promise for a Rules object. The grammarSource is the name of the file that the input came from.

Returned Rules object shape

Rules.first

The name of the first rule in the input grammar.

Rules.defs

A hash of Rule objects indexed by uppercase rulename.

Rules.refs

An array of RuleRef objects.

Rule.name

The name of the rule

Rule.loc

The Peggy location in the input file where the rule name was defined

Rule.def

The definition of the rule. More information forthcoming.

RuleRef.name

The name of the rule that was referenced

RuleRef.loc

The Peggy location in the input file where the rule name was referenced.


Tests codecov

node-abnf's People

Contributors

hildjj avatar jfhbrook avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

node-abnf's Issues

Rewrite with Peggy

This will be a major version change.

reparse was last updated 12 years ago - not that it needed anything, necessarily.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.