aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthew Hall <hallmatthew314@gmail.com>2023-03-08 20:11:24 +1300
committerMatthew Hall <hallmatthew314@gmail.com>2023-03-08 20:11:24 +1300
commitf7b089d954cb028ee3c46ad45f0f81ae2e5386cf (patch)
tree3b079b43f1820676528baa1b7f74d7594477a4a4 /src
parent8835f1de0dbc6a059a42fad78d4acbb0984b94e2 (diff)
Implement Phrase
Diffstat (limited to 'src')
-rw-r--r--src/parcom.cr14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/parcom.cr b/src/parcom.cr
index 8d1d47b..4d49a97 100644
--- a/src/parcom.cr
+++ b/src/parcom.cr
@@ -166,7 +166,19 @@ module Parcom
end
end
- class Phrase
+ class Phrase(T, V)
+ def initialize(@p : Parser(T, V))
+ end
+
+ def parse(tokens : TokenStream(T)) : Result(T, V)
+ r = @p.parse(tokens)
+
+ unless r.tokens.empty?
+ raise ParserException.new("Phrase: some of the input was not parsed")
+ end
+
+ r
+ end
end
class Plus(T, V, U) < Parser(T, {V, U})