diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-09 16:52:30 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-09 16:52:30 +1300 |
| commit | 1a9792afb92e227adcb564a051b678faa9fe2036 (patch) | |
| tree | 5fe774808eaef5943adef601c95b85712f684335 /src/parcom.cr | |
| parent | 61f7421c2feb36b529a51589967efaa11e6a1814 (diff) | |
Implement Exactly + extra test for Sequence
Diffstat (limited to 'src/parcom.cr')
| -rw-r--r-- | src/parcom.cr | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/parcom.cr b/src/parcom.cr index d7e6682..c7f4012 100644 --- a/src/parcom.cr +++ b/src/parcom.cr @@ -295,7 +295,17 @@ module Parcom end end - class Exactly + class Exactly(T, V) < Parser(T, Array(V)) + @p : Sequence(T, V) + + def initialize(i : Int, p : Parser(T, V)) + i = i.negative? ? 0 : i + @p = Sequence.new(([p] of Parser(T, V)) * i) + end + + def parse(tokens : TokenStream(T)) : Result(T, Array(V)) + @p.parse(tokens) + end end class AtLeast |
