| ▲ | rhdunn 6 hours ago | ||||||||||||||||
There are three return states that a parser (or partial parser) can return: 1. an item (`T`) for a successful parse; 2. an error (`ParseError`) for an unrecoverable parse error; 3. a partial item (`T with ParseError`) for a recoverable parse error or warning (known statically). You may also want to differentiate between: 1. leaf nodes (numbers, identifiers, string literals, etc.); 2. composite/nested nodes (addition, multiplication, variable assignment, etc.). | |||||||||||||||||
| ▲ | raddan 5 hours ago | parent [-] | ||||||||||||||||
You don’t need 2 and 3. You can express them just with with T. For example, you could use an Either type for “good, here’s your value/bad, here’s your error.” If you want to get more sophisticated, you can add a type with extra error cases. In my own combinator libraries, I also include extra failure information to make diagnosing failed parses easy (and to generate pretty output). This does not change the fact that T is sufficient. | |||||||||||||||||
| |||||||||||||||||