UNPKG

parser-combinator

Version:
53 lines (30 loc) 1.22 kB
Parser Extensions ===== These functions allow users to quickly find letters or numbers in a standard text ### returns() * Forces a value * Does not consume a character ### lazy(parserFunction) * The point is that the parserFunction is not called immediately - Use `P.lazy( this.text )` and not `P.lazy( this.text() )` * The parserFunction will be called when needed - TODO : I have no clear explanation * One important use is when dealing with **recursion** expression() { return P.try( number() .thenLeft(plus()) .then(P.lazy( expression ) ) // <-- function is not called .map(values => values[0]+values[1]) ) .or(this.number()); } Important : Parsec is a streaming parser. [The grammar you make a parser for can NOT be left recursive.](https://github.com/d-plaindoux/parsec/issues/13) The good news is that any left recursive grammar can be rewritten to a form that parsec can handle. ### digit() ### letter() ### letters() ### string(value) ### lowerCase() ### upperCase()