0.6.0 • Published 7 years ago

parser-lib v0.6.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

#Parser Lib

Goal of this library is to create enable easy and type safe creation of parsers runable in all javascript environments. It is inspired by haskell parsec library.

Build Status dependencies Status devDependencies Status npm

##Examples

###Parsing simple integer

const num = integer
    .parseText('11')
    .map(state => state.result)
    .getOrElse(0);
    
console.log(num); // 11

###Simple mathematical interpreter

let lvl3: Parser<any, number>;

const atom: Parser<any, number> = or(
  number,
  lazy(() =>
    between(
      keyword('(', false),
      keyword(')', false),
      lvl3
    )
  )
);

const lvl1: Parser<any, number> = chainRight(
  atom,
  operator('^', Math.pow)
);

const lvl2Op = or(
  operator('*', (a: number, b: number) => a * b),
  operator('/', (a: number, b: number) => a / b)
);

const lvl2: Parser<any, number> = chainLeft(lvl1, lvl2Op);

const lvl3Op = or(
  operator('+', (a: number, b: number) => a + b),
  operator('-', (a: number, b: number) => a - b)
);

lvl3 = chainLeft(lvl2, lvl3Op);

For more example look in test/ directory. Test cases should be simple enough to read.

0.6.0

7 years ago

0.5.1

8 years ago

0.4.0

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago