Socket
Socket
Sign inDemoInstall

happy-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    happy-parser

Package for easy parsing using a monadic parser combinator


Version published
Maintainers
1
Install size
107 kB
Created

Readme

Source

Node parser combinator

travis-ci

Immutable monadic parser combinator for node javascript.

Example

const parsec = require('happy-parser');

const sum = (x, y) => x + y, 
      rest = (x, y) => x - y

const
  termOperations = parsec.Parser.operations([ parsec.char('+'), sum ], [ parsec.char('-'), rest ]).trim(),
  factorOperations = parsec.Parser.operations([ parsec.char('^'), Math.pow.bind() ]).trim()

const factor = parsec.lazy(() => 
            parsec.int.or(expr.between(parsec.char('('), parsec.char(')'))).trim()
          ),
      term = parsec.lazy(() => factor.chainRight(factorOperations)),
      expr = term.chain(termOperations).trim()

console.log(expr.parse(' 3^2 + (4 - 7) '))

Check also the documentation and tests

Keywords

FAQs

Last updated on 18 Dec 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc