diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-13 13:17:03 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-13 13:17:03 +1300 |
| commit | dafeff8d652f07fca61ad6a2f601f0ceb550ab70 (patch) | |
| tree | c3a9c4d9c2d1cfd3d167b9576ab3c8f017b7004b /src | |
| parent | c2197ee71ac1cc3cb2ad3bf8a93b579f7251316e (diff) | |
Documentation for Many
Diffstat (limited to 'src')
| -rw-r--r-- | src/parcom/many.cr | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/parcom/many.cr b/src/parcom/many.cr index dbe3b13..d76fc91 100644 --- a/src/parcom/many.cr +++ b/src/parcom/many.cr @@ -1,10 +1,21 @@ require "./parser.cr" module Parcom + # `Many` is a `Parser` that repeatedly tries to parse with another parser. + # The `Many` object will collect all success values in an array, and return + # them with the final state of the input stream. If the wrapped parser ever + # fails or succeeds without parsing any input, the `Many` object will stop + # attempting to parse will will return the array of prrevious successes. + # + # `Many` will return an empty array if the parser never succeeds or consumes + # input. For cases where at least one parserr success is needed, use `Some`. class Many(T, V) < Parser(T, Array(V)) + # Accepts the parser to use. def initialize(@p : Parser(T, V)) end + # Continuously parses with the wrapped parser, returns all successes. + # Parsing stops when the parser fails, or succeeds without consuming input. def parse(tokens : Tokens(T)) : Result(T, Array(V)) parsed = [] of V |
