aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parcom.cr17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/parcom.cr b/src/parcom.cr
index 8d7c754..6fc6339 100644
--- a/src/parcom.cr
+++ b/src/parcom.cr
@@ -228,6 +228,23 @@ module Parcom
end
end
+ class Sequence(T, V) < Parser(T, Array(V))
+ def initialize(@ps : Iterable(Parser(T, V)))
+ end
+
+ def parse(tokens : TokenStream(T)) : Result(T, Array(V))
+ parsed = [] of V
+
+ @ps.each do |p|
+ r = p.parse(tokens)
+ parsed << r.value
+ tokens = r.tokens
+ end
+
+ Result.new(tokens, parsed)
+ end
+ end
+
class Tokens(T) < Parser(T, Array(T))
def initialize(@expected : Iterable(T))
end