Result represents the outcome of parsing: success carries a value and the number of input characters consumed, while failure carries a parse error. section 9.6.2
A parser Result records the information needed to continue sequencing:
- Success(get, charsConsumed) returns the parsed value together with the input length consumed. section 9.6.2
- Failure(get) reports a ParseError when parsing does not succeed. section 9.6.2
- The consumer uses charsConsumed to update the parser's Location state before running the next parser. section 9.6.2
Sequencing parsers
For string("abra") ** string("cadabra"), a successful first Result marks "abra" as consumed, allowing the second parser to inspect the remaining input. section 9.6.2
opaque type Parser[+A] = Location => Result[A] #1 enum Result[+A]: case Success(get: A, charsConsumed: Int) #2 case Failure(get: ParseError) extends Result[Nothing] #3
Inspect the initial Scala representation of Parser and its Success and Failure Result cases. section 9.6.2
