aboutsummaryrefslogtreecommitdiff
path: root/src/__OLD_parcom/many.cr
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-19 23:02:29 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-19 23:02:29 +1300
commit9734fa2d530b9496b70a388a117ea57fe5730772 (patch)
tree78a42db1e64e5148edfa96cb2a451a17ef362485 /src/__OLD_parcom/many.cr
parent2ef8841e9c7a48eea0f66cfe09d8fe996f43c2b2 (diff)
Remove old files
Diffstat (limited to 'src/__OLD_parcom/many.cr')
-rw-r--r--src/__OLD_parcom/many.cr36
1 files changed, 0 insertions, 36 deletions
diff --git a/src/__OLD_parcom/many.cr b/src/__OLD_parcom/many.cr
deleted file mode 100644
index a734c63..0000000
--- a/src/__OLD_parcom/many.cr
+++ /dev/null
@@ -1,36 +0,0 @@
-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
-
- loop do
- result = @p.parse?(tokens)
- break unless !result.nil? && result.tokens != tokens
-
- parsed << result.value
- tokens = result.tokens
- end
-
- Result.new(tokens, parsed)
- rescue ex : ParserFail
- raise ParserFail.new("Many: #{ex.message}")
- end
- end
-end
-