Exemplo n.º 1
0
        public void Double_Optor()
        {
            Pattern pattern = Maybe(Maybe("Hello"));

            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Captures("", pattern.Consume("World"));
        }
Exemplo n.º 2
0
        public void Neglect()
        {
            Pattern pattern = Not(Many(';'));

            ResultAssert.Captures("123456789", pattern.Consume("123456789;"));
            ResultAssert.Fails(pattern.Consume(";"));
        }
Exemplo n.º 3
0
        public void Alternate_Spanner()
        {
            Pattern pattern = Many(SpaceSeparator.Or('\t'));

            ResultAssert.Captures("  \t ", pattern.Consume("  \t "));
            ResultAssert.Captures("  \t ", pattern.Consume("  \t hi"));
        }
Exemplo n.º 4
0
        public void Neglect()
        {
            Pattern pattern = Not(Maybe("Hello"));

            ResultAssert.Captures("", pattern.Consume("Hello"));
            ResultAssert.Captures("World", pattern.Consume("World"));
        }
Exemplo n.º 5
0
        public void Consume_Insensitive()
        {
            Pattern pattern = "Hello".With(Case.Insensitive).Then(' '.With(Case.Insensitive)).Then("World".With(Case.Insensitive));

            ResultAssert.Captures("HELLO WORLD", pattern.Consume("HELLO WORLD"));
            ResultAssert.Captures("hello world", pattern.Consume("hello world"));
        }
Exemplo n.º 6
0
        public void Consume()
        {
            Pattern pattern = Maybe("Hello");

            ResultAssert.Captures("Hello", pattern.Consume("Hello World"));
            ResultAssert.Captures("", pattern.Consume("Goodbye World"));
        }
Exemplo n.º 7
0
        public void Nested_Consume()
        {
            Pattern pattern = NestedRange("if", "end if");

            ResultAssert.Captures("if\nif\nend if\nbacon\nend if", pattern.Consume("if\nif\nend if\nbacon\nend if\nfoobar"));
            ResultAssert.Fails(pattern.Consume("if\nif\nend if\nbacon\nfoobar"));
        }
Exemplo n.º 8
0
        public void Simple_Consume()
        {
            Pattern pattern = Range("Hello", ';');

            ResultAssert.Captures("Hello;", pattern.Consume("Hello;"));
            ResultAssert.Captures("Hello World;", pattern.Consume("Hello World;"));
        }
Exemplo n.º 9
0
        public void Consume()
        {
            Pattern pattern = "Hello".Or("Goodbye");

            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Captures("Goodbye", pattern.Consume("Goodbye"));
            ResultAssert.Fails(pattern.Consume("!"));
            ResultAssert.Fails(pattern.Consume("How are you?"));

            pattern = "Hello".Or("Hi").Or("Howdy");
            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Captures("Hi", pattern.Consume("Hi"));
            ResultAssert.Captures("Howdy", pattern.Consume("Howdy"));
            ResultAssert.Fails(pattern.Consume("Goodbye"));

            pattern = OneOf("Hello", "Hi", "Howdy");
            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Captures("Hi", pattern.Consume("Hi"));
            ResultAssert.Captures("Howdy", pattern.Consume("Howdy"));
            ResultAssert.Fails(pattern.Consume("Goodbye"));

            pattern = OneOf <Enum>();
            ResultAssert.Captures("First", pattern.Consume("First"));
            ResultAssert.Captures("Second", pattern.Consume("Second"));
            ResultAssert.Captures("Third", pattern.Consume("Third"));
            ResultAssert.Fails(pattern.Consume("Fourth"));
        }
Exemplo n.º 10
0
        public void Optional_Spanner()
        {
            Pattern pattern = Maybe(Many(' '));

            ResultAssert.Captures("  ", pattern.Consume("  Hello"));
            ResultAssert.Captures("", pattern.Consume("Hello"));
        }
Exemplo n.º 11
0
        public void ReadUntilEndOfLine()
        {
            Pattern pattern = Many(Not(';' | LineTerminator));

            ResultAssert.Captures("hello", pattern.Consume("hello"));
            ResultAssert.Captures("hello", pattern.Consume("hello\nworld"));
        }
Exemplo n.º 12
0
        public void Double_Negator()
        {
            Pattern pattern = Not(Not("Hello"));

            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Fails(pattern.Consume("World"));
        }
Exemplo n.º 13
0
        public void Comment()
        {
            Pattern pattern = LineComment("--");

            ResultAssert.Captures("--This is a comment", pattern.Consume("--This is a comment"));
            ResultAssert.Captures("--This is also a comment", pattern.Consume("--This is also a comment\nExample_Function_Call();"));
        }
Exemplo n.º 14
0
        public void Consume()
        {
            Pattern pattern = Many(' ');

            ResultAssert.Captures(" ", pattern.Consume(" Hi!"));
            ResultAssert.Captures("    ", pattern.Consume("    Hi!"));
            ResultAssert.Fails(pattern.Consume("Hi!  "));
        }
Exemplo n.º 15
0
        public void Neglect()
        {
            Pattern pattern = Not("Hello".Or("Goodbye"));

            ResultAssert.Captures("World", pattern.Consume("Worldeater"));
            ResultAssert.Fails(pattern.Consume("Hello"));
            ResultAssert.Fails(pattern.Consume("Goodbye"));
        }
Exemplo n.º 16
0
        public void Consume()
        {
            Pattern pattern = new Regex("^hello").AsPattern();

            ResultAssert.Captures("hello", pattern.Consume("hello"));
            ResultAssert.Captures("hello", pattern.Consume("hello world"));
            ResultAssert.Fails(pattern.Consume("hel"));
        }
Exemplo n.º 17
0
        public void Consume()
        {
            Pattern pattern = "Hi! ".AsPattern() * 2;

            ResultAssert.Captures("Hi! Hi! ", pattern.Consume("Hi! Hi! "));
            ResultAssert.Captures("Hi! Hi! ", pattern.Consume("Hi! Hi! Hi!"));
            ResultAssert.Fails(pattern.Consume("Hi! Bye! "));
        }
Exemplo n.º 18
0
        public void StoreAndRestore()
        {
            Source      source = new Source("hello world");
            SourceState state  = source.Store();

            ResultAssert.Captures("hello", "hello".Consume(ref source));
            source.Restore(state);
            ResultAssert.Captures("hello", "hello".Consume(ref source));
        }
Exemplo n.º 19
0
        public void Alternate_Repeater()
        {
            Pattern pattern = "Hi".Or("Bye").Then(' ').Repeat(2);

            ResultAssert.Captures("Hi Bye ", pattern.Consume("Hi Bye Hi "));
            ResultAssert.Captures("Hi Hi ", pattern.Consume("Hi Hi Hi "));
            ResultAssert.Captures("Hi Hi ", pattern.Consume("Hi Hi "));
            ResultAssert.Fails(pattern.Consume("Hi Hi"));
        }
Exemplo n.º 20
0
        public void Neglect()
        {
            Pattern pattern = Not("Hi! ".AsPattern() * 2);

            ResultAssert.Captures("Oh! No! ", pattern.Consume("Oh! No! "));
            ResultAssert.Captures("Oh? Hi! ", pattern.Consume("Oh? Hi! "));
            ResultAssert.Captures("Hi! Ho! ", pattern.Consume("Hi! Ho! "));
            ResultAssert.Fails(pattern.Consume("H! Hi! "));
        }
Exemplo n.º 21
0
        public void Escaped_Consume()
        {
            Pattern pattern = Range("\"", "\"", "\\\"");

            ResultAssert.Captures("\"\"", pattern.Consume("\"\""));
            ResultAssert.Captures("\"H\"", pattern.Consume("\"H\"i"));
            ResultAssert.Captures("\"Hello\"", pattern.Consume("\"Hello\""));
            ResultAssert.Captures("\"Hello\\\"Goodbye\"", pattern.Consume("\"Hello\\\"Goodbye\""));
        }
Exemplo n.º 22
0
        public void Double_Spanner()
        {
            Pattern pattern = Many(Many("hi"));

            ResultAssert.Captures("hi", pattern.Consume("hi"));
            ResultAssert.Captures("hihi", pattern.Consume("hihi"));
            ResultAssert.Captures("hihihi", pattern.Consume("hihihi"));
            ResultAssert.Fails(pattern.Consume(""));
        }
Exemplo n.º 23
0
        public void StringLiteral()
        {
            Pattern pattern = Pattern.StringLiteral("\"", "\\\"");

            ResultAssert.Captures("\"Hello World\"", pattern.Consume("\"Hello World\""));
            ResultAssert.Captures("\"Hello World\"", pattern.Consume("\"Hello World\" Bacon"));
            ResultAssert.Captures("\"Hello\\\"World\"", pattern.Consume("\"Hello\\\"World\""));
            ResultAssert.Captures("\"Hello\\\"World\"", pattern.Consume("\"Hello\\\"World\" Bacon"));
        }
Exemplo n.º 24
0
        public void Consume()
        {
            Pattern pattern = "Hello".Then(' ').Then("world");

            ResultAssert.Captures("Hello world", pattern.Consume("Hello world"));
            ResultAssert.Fails(pattern.Consume("Goodbye world"));
            pattern = "Goodbye".Then(' ').Then("world");
            ResultAssert.Captures("Goodbye world", pattern.Consume("Goodbye world"));
            ResultAssert.Fails(pattern.Consume("Hello world"));
        }
Exemplo n.º 25
0
        public void Consume()
        {
            Pattern pattern = Fuzzy("Bob");

            ResultAssert.Captures("Bob", pattern.Consume("Bob"));
            ResultAssert.Captures("bob", pattern.Consume("bob"));
            ResultAssert.Captures("Mob", pattern.Consume("Mob"));
            ResultAssert.Captures("mob", pattern.Consume("mob"));
            ResultAssert.Fails(pattern.Consume("Mom"));
        }
Exemplo n.º 26
0
        public void Backtracking()
        {
            Pattern end1   = "end".Then(Many(' ')).Then("first");
            Pattern end2   = "end".Then(Many(' ')).Then("second");
            Source  source = new Source("end second");

            //f backtracking doesn't occur, parsing end2 will fail, because "end" and the space will have been consumed
            ResultAssert.Fails(end1.Consume(ref source));
            ResultAssert.Captures("end second", end2.Consume(ref source));
        }
Exemplo n.º 27
0
        public void Mutate_And_Consume()
        {
            Pattern pattern = Mutable();

            pattern.Then("Hello").Then(' ').Then("world");
            ResultAssert.Captures("Hello world", pattern.Consume("Hello world"));
            Not(pattern).Seal();
            ResultAssert.Captures("Bacon cakes", pattern.Consume("Bacon cakes"));
            ResultAssert.Fails(pattern.Consume("Hello world"));
        }
Exemplo n.º 28
0
        public void Consume_Rune_FromSource()
        {
            Source source = new Source("hello");

            ResultAssert.Captures("h", new Rune('h').Consume(ref source));
            ResultAssert.Captures("ello", "ello".Consume(ref source));
            source = new Source("𝄞abc");
            ResultAssert.Captures("𝄞", new Rune(0x1D11E).Consume(ref source));
            ResultAssert.Captures("abc", "abc".Consume(ref source));
        }
Exemplo n.º 29
0
        public void Neglect()
        {
            Pattern pattern = Not("Hello");

            ResultAssert.Captures("Oh no", pattern.Consume("Oh no!"));
            ResultAssert.Captures("Oh no", pattern.Consume("Oh no?"));
            ResultAssert.Fails(pattern.Consume("Hello"));
            ResultAssert.Fails(pattern.Consume("Hello!"));
            ResultAssert.Fails(pattern.Consume("Hello."));
        }
Exemplo n.º 30
0
        public void Identifier()
        {
            Pattern pattern = Check(
                (c) => c.IsLetter(), true,
                (c) => c.IsLetter() || c == '_', true,
                (c) => c.IsLetter() || c == '_', false);

            ResultAssert.Captures("hello", pattern.Consume("hello"));
            ResultAssert.Captures("example_name", pattern.Consume("example_name"));
            ResultAssert.Fails(pattern.Consume("_fail"));
        }