GithubHelp home page GithubHelp logo

mykhailo-ivankiv / llkp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from c5f7c9/llkp

1.0 2.0 0.0 519 KB

LL(k) Parsers: ABNF, EBNF, PEG, etc.

Home Page: https://neformal13.github.io/llkp/

License: MIT License

JavaScript 100.00%

llkp's Introduction

llkp - LL(k) parsers

Build Status

The goal of this library is to provide API that would look like the built-in RegExp class and would let easily write parsers for structures that cannot be parsed with regular expressions, such as XML-like structures, the e-mail pattern, data URL, URI and so on.

Examples

To parse a list of comma separated key-value pairs with a parser written as ABNF:

var ABNF = require('llkp/abnf');

var p = new ABNF('1*{","}(key "=" val)', { key: /\w+/, val: /\w+/ }).join(0, 2);
var r = p.exec('charset=utf8,type=text,subtype=html');

assert.deepEqual(r, { charset: 'utf8', type: 'text', subtype: 'html' });

To parse a list of comma separated key-value pairs with a parser written as PEG:

var PEG = require('llkp/peg');

var p = new PEG('(key "=" val)<",">+', { key: /\w+/, val: /\w+/ }).join(0, 2);
var r = p.exec('charset=utf8,type=text,subtype=html');

assert.deepEqual(r, { charset: 'utf8', type: 'text', subtype: 'html' });

Tests

Unit tests were written in the mocha's TDD style:

npm install -g mocha
mocha -u tdd

They can be run with npm:

npm test

Coverage

istanbul can be used with mocha's unit tests in the following way (figure out the full path to _mocha):

npm install -g istanbul
istanbul cover .../npm/node_modules/mocha/bin/_mocha -- -u tdd

It will produce an output like:

Statements   : 98.89% ( 356/360 )
Branches     : 92.97% ( 172/185 )
Functions    : 100% ( 96/96 )
Lines        : 98.8% ( 328/332 )

Static analysis

Static analysis is done by JSHint:

npm install -g jshint
jshint --verbose .

This command is mentioned in package.json so it's enough to run npm test:

npm test

Documentation

Check out the wiki page.

License

MIT

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.