From 6a27c77a03b64a838ba004ab87780113b5640cc9 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Tue, 21 Mar 2023 21:13:20 +1300 Subject: Initial implementation for and_then, I'm not convinced it fully works --- spec/parcom_spec.cr | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec/parcom_spec.cr') diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index 76be4c2..c586a7c 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -409,6 +409,21 @@ describe Parser do end end + describe "#and_then" do + p_string = ->(s : String) do + Parser.token_sequence(s.chars).map(&.join) + end + p_any_word = Parser(Char, Array(Char)).satisfy(&.letter?).some.map(&.join) + space = Parser(Char, Array(Char)).satisfy(&.whitespace?).some + # Parses two of the same word, with whitespace between: + two_words = (p_any_word << space).and_then(p_string) + + tokens = Tokens.from_string("foo foo") + result = two_words.parse(tokens) + + result.value.should eq("foo") + end + describe "#many" do p = Parser(Char, Char).token('a').many -- cgit v1.2.1