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/token_seq.cr | |
| parent | 2ef8841e9c7a48eea0f66cfe09d8fe996f43c2b2 (diff) | |
Remove old files
Diffstat (limited to 'src/__OLD_parcom/token_seq.cr')
| -rw-r--r-- | src/__OLD_parcom/token_seq.cr | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/src/__OLD_parcom/token_seq.cr b/src/__OLD_parcom/token_seq.cr deleted file mode 100644 index 45900f9..0000000 --- a/src/__OLD_parcom/token_seq.cr +++ /dev/null @@ -1,38 +0,0 @@ -require "./parser.cr" -require "./sequence.cr" - -module Parcom - # `TokenSeq` is a `Parser` that attempts to parse a specific - # string of tokens. If the expected tokens are not at the start - # of the input stream, the parser fails. - # - # Example: - # ``` - # parse_test = TokenSeq(Char).new("test".chars) - # tokens = Tokens.from_string("testing") - # - # result = parse_test.parse(tokens) - # - # puts result.value # => ['t', 'e', 's', 't'] - # puts result.tokens # => ['i', 'n', 'g'] - # ``` - class TokenSeq(T) < Parser(T, Array(T)) - @p : Sequence(T, T) - - # Accepts the tokens to try and parse, in order. - def initialize(expected : Iterable(T)) - ps = [] of Parser(T, T) - expected.each { |t| ps << Token.new(t) } - - @p = Sequence.new(ps) - end - - # Tries to parse the list of tokens. - def parse(tokens : Tokens(T)) : Result(T, Array(T)) - @p.parse(tokens) - rescue ex : ParserFail - raise ParserFail.new("TokenSeq: #{ex.message}") - end - end -end - |
