Read the world’s shortest complete monadic parsing tutorial in the Quick Start section of the README for purescript-parsing GitHub - purescript-contrib/purescript-parsing: A parser combinator library based on Parsec
It’s great to see more docs! Good job.
It might be helpful to clarify:
That operator will first try the left parser and if that fails, then it will backtrack the input string and try the right parser.
This is a common point of confusion in newcomers, who often assume that parsers always backtrack on an error. However, this is a great way to get really terrible parser errors! The current implementation only backtracks as long as no input was consumed. Otherwise you need to explicitly opt-in to backtracking via try
on the minimal lookahead you need to commit to a branch. try
will reset the parser input state on failure, allowing alt
to backtrack.
It might be helpful to clarify:
The current implementation only backtracks as long as no input was consumed .
I added that clarification to the README.
https://pursuit.purescript.org/packages/purescript-parsing
I also added more explanation about this in the documentation for the Alt
instance.
https://pursuit.purescript.org/packages/purescript-parsing/docs/Text.Parsing.Parser#t:ParserT