From f7b089d954cb028ee3c46ad45f0f81ae2e5386cf Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Wed, 8 Mar 2023 20:11:24 +1300 Subject: Implement Phrase --- src/parcom.cr | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/parcom.cr') 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}) -- cgit v1.2.1