npm.io
3.0.0 • Published 11 years ago

parsly

Licence
MIT
Version
3.0.0
Deps
1
Vulns
0
Weekly
0
Stars
4

Parsly

A small PEG based parser library.
An opinionated JavaScript port of Parslet.

NPM version Build Status

Install

npm install --save parsly

Usage

// There is 2 ways to access Parsly APIs.

// Parser API:
import {Parser} from 'parsly'
import {alt, seq, match, str, any, custom, lazy} from 'parsly/parser'

// Transform API:
import {Transformer} from 'parsly'
import Transformer, {simple, sequence, subtree} from 'parsly/transformer'

Parser API

Atoms
  • alt(...parsers)
  • seq(...parsers)
  • match(expr)
  • str(string)
  • any()
  • custom(fn)
  • lazy(fn)
Chain
  • as(name)
  • maybe()
  • many()
  • times(n)
  • repeat(min, max)

Transform API

  • Transform
  • Node
  • simple(node)
  • sequence(node)
  • subtree(node)
Transform class
  • Transform(rules)
  • Transform#rule(matchFn, transformFn)
  • Transform#run(ast, context)