aboutsummaryrefslogtreecommitdiff
path: root/src/parcom.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/parcom.cr')
-rw-r--r--src/parcom.cr12
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