public void passing_left_and_failing_right_side_fails() { var subject = new Sequence(__this__, __wally__); var result = subject.TryMatch(scanner); Assert.That(result.Success, Is.False); }
public void passing_left_and_passing_right_side_passes_and_captures_both() { var subject = new Sequence(__this__, __is_my__); var result = subject.TryMatch(scanner); Assert.That(result.Success, Is.True); Assert.That(result.Value, Is.EqualTo("this is my")); }
public void a_recursive_parser_pattern() { // Build a parser for patterns of nested square brackets subject = Recursion.Over(recursive => { var left = new LiteralCharacter('['); var right = new LiteralCharacter(']'); var mrec = new Repetition(recursive, 0, int.MaxValue); var lrec = new Sequence(left, mrec); var lr = new Sequence(lrec, right); return lr; }); valid_recursive = new ScanStrings("[[[][]]]"); valid_simple = new ScanStrings("[]"); invalid_recursive = new ScanStrings("[[[][[[]]]"); // unbalanced invalid_simple = new ScanStrings("hello, world"); }