A functionnal parser written in Javascript.
npm install funparserjs
anyChar
: parse any character in a stringfail
: parser that always failedsuccess(v)
: parser that always success and return valternate(p1,...p2)
: parser that run the first parser executable in parameterscombine(p,f)
: parser that combine a parser and a function that return a parsercombines(p, ...f)
: parser that combine recursively with the result of the previous function,charCond(cond)
: parser that success if the character condition is good else failchar
: parse a characterstring
: parse a stringoneOrMore(p)
: parser that try to run parser p one time or morezeroOrMore(p)
: parser that try to run parser p one time or moredigit
: parse a digitnumber
: parse a number and return a list of digitint
: parse an integer
const parser = require('funparserjs');
parser.runParser(char, 'Test');
// Will return ['T', 'est']
parser.runParser(success('OK'), 'Test');
// Will return ['OK', 'Test']
const parser = require('funparserjs');
const fooParser = string('foo');
// Will return a parser of string that match foo
const anyCharBis = combine(anyChar, c => success(c));
// Will return a parser that parse anyChar and success with the char (same as anyChar)
const testParser = combine(char('t'),
_ => char('e'),
_ => char('s'),
_ => char('t'),
_ => success(true))
// Will return a parser that parse the string "test" and the result is true