diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-19 23:02:29 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-19 23:02:29 +1300 |
| commit | 9734fa2d530b9496b70a388a117ea57fe5730772 (patch) | |
| tree | 78a42db1e64e5148edfa96cb2a451a17ef362485 /src/__OLD_parcom/map.cr | |
| parent | 2ef8841e9c7a48eea0f66cfe09d8fe996f43c2b2 (diff) | |
Remove old files
Diffstat (limited to 'src/__OLD_parcom/map.cr')
| -rw-r--r-- | src/__OLD_parcom/map.cr | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/src/__OLD_parcom/map.cr b/src/__OLD_parcom/map.cr deleted file mode 100644 index 34961b5..0000000 --- a/src/__OLD_parcom/map.cr +++ /dev/null @@ -1,30 +0,0 @@ -require "./parser.cr" - -module Parcom - # `Map` is a `Parser` that tries to parse using another parser, - # and then changing the result of that parser to a different value. - # - # Example: - # ``` - # # Where `Digits` is some parser that returns an array of digit characters - # parse_i32 = Digits.new.map { |x| x.join.to_i32 } - # result = parse_i32.parse(Tokens.from_string("1234")) - # result.value # => 1234 (Int32) - # ``` - class Map(T, V, U) < Parser(T, U) - # Accepts the parser to use and the function to apply to the result. - def initialize(@p : Parser(T, V), &block : V -> U) - @f = block - end - - # Tries to parse with the given parser and applies the - # function to the result if successful. - def parse(tokens : Tokens(T)) : Result(T, U) - result = @p.parse(tokens) - Result.new(result.tokens, @f.call(result.value)) - rescue ex : ParserFail - raise ParserFail.new("Map: #{ex.message}") - end - end -end - |
