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/sep_by.cr | |
| parent | 2ef8841e9c7a48eea0f66cfe09d8fe996f43c2b2 (diff) | |
Remove old files
Diffstat (limited to 'src/__OLD_parcom/sep_by.cr')
| -rw-r--r-- | src/__OLD_parcom/sep_by.cr | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/src/__OLD_parcom/sep_by.cr b/src/__OLD_parcom/sep_by.cr deleted file mode 100644 index fa19027..0000000 --- a/src/__OLD_parcom/sep_by.cr +++ /dev/null @@ -1,38 +0,0 @@ -require "./parser.cr" -require "./map.cr" -require "./many.cr" - -module Parcom - # `SepBy` is a `Parser` that tries to parse one or more times with one - # parser, alternating with a second parser. - # - # Example: - # ``` - # letter_a = Token.new('a') - # letter_b = Token.new('b') - # p = SepBy(Char, Car, Char).new(letter_a, letter_b) - # tokens = Tokens.from_string("ababababa") - # - # result = p.parse(tokens) - # puts result.value # => ['a', 'a', 'a', 'a', 'a'] - # ``` - class SepBy(T, V, U) < Parser(T, Array(V)) - @p : Map(T, {V, Array(V)}, Array(V)) - - # Accepts the parser that parses the result values, and the - # parser that parses the sepatators. - def initialize(elem : Parser(T, V), sep : Parser(T, U)) - @p = (elem + Many(T, U).new(sep >> elem)).map do |tup| - [tup[0]] + tup[1] - end - end - - # Tries to parse, alternating the first and second parsers. - def parse(tokens : Tokens(T)) : Result(T, Array(V)) - @p.parse(tokens) - rescue ex : ParserFail - raise ParserFail.new("SepBy: #{ex.message}") - end - end -end - |
