parser-combinator
Version:
Parser combinators
53 lines (30 loc) • 1.22 kB
Markdown
Parser Extensions
=====
These functions allow users to quickly find letters or numbers in
a standard text
* Forces a value
* Does not consume a character
* 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.
[](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.