diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-21 21:13:20 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-21 21:13:20 +1300 |
| commit | 6a27c77a03b64a838ba004ab87780113b5640cc9 (patch) | |
| tree | b5f144a2bedf185a8348290c847e61c71519cc8f /spec/parcom_spec.cr | |
| parent | 082d54e05a41cde31e2d8378503c4880eceb5c17 (diff) | |
Initial implementation for and_then, I'm not convinced it fully works
Diffstat (limited to 'spec/parcom_spec.cr')
| -rw-r--r-- | spec/parcom_spec.cr | 15 |
1 files changed, 15 insertions, 0 deletions
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 |
