コード例 #1
0
        public void Double_Optor()
        {
            Pattern pattern = Maybe(Maybe("Hello"));

            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Captures("", pattern.Consume("World"));
        }
コード例 #2
0
        public void ConsumeLiteral()
        {
            Pattern Negator = !(Pattern)"Hello";

            Assert.That.Fails(Negator.Consume("Hello"));
            Assert.That.Captures("World", Negator.Consume("World"));
        }
コード例 #3
0
        public void Neglect()
        {
            Pattern pattern = Not(Many(';'));

            ResultAssert.Captures("123456789", pattern.Consume("123456789;"));
            ResultAssert.Fails(pattern.Consume(";"));
        }
コード例 #4
0
        public void Consume()
        {
            Capture Capture;
            Pattern Capturer = (+Pattern.Letter).Capture(out Capture);
            Result  Result;

            Result = Capturer.Consume("Hello");
            Assert.That.Captures("Hello", Result);
            Assert.That.Captures("Hello", Capture);

            Pattern Start = "Hello " & (+Pattern.Letter).Capture(out Capture) & "!";

            Result = Start.Consume("Hello World!");
            Assert.That.Captures("Hello World!", Result);
            Assert.That.Captures("World", Capture);

            Pattern Stop = (Pattern)"Goodbye " & Capture & ".";

            Result = Stop.Consume("Goodbye World.");
            Assert.That.Captures("Goodbye World.", Result);

            Result = Start.Consume("Hello Range!");
            Assert.That.Captures("Hello Range!", Result);
            Assert.That.Captures("Range", Capture);

            Pattern Range = (Start, Stop);

            Result = Range.Consume("Hello Range! How are you today? Goodbye Range. Have a good day.");
            Assert.That.Captures("Range", Capture);
            Assert.That.Captures("Hello Range! How are you today? Goodbye Range.", Result);
        }
コード例 #5
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();"));
        }
コード例 #6
0
        public void Alternate_Spanner()
        {
            Pattern pattern = Many(SpaceSeparator.Or('\t'));

            ResultAssert.Captures("  \t ", pattern.Consume("  \t "));
            ResultAssert.Captures("  \t ", pattern.Consume("  \t hi"));
        }
コード例 #7
0
        public void Consume()
        {
            Pattern pattern = Maybe("Hello");

            ResultAssert.Captures("Hello", pattern.Consume("Hello World"));
            ResultAssert.Captures("", pattern.Consume("Goodbye World"));
        }
コード例 #8
0
        public void Neglect()
        {
            Pattern pattern = Not(Maybe("Hello"));

            ResultAssert.Captures("", pattern.Consume("Hello"));
            ResultAssert.Captures("World", pattern.Consume("World"));
        }
コード例 #9
0
        public void ConsumeRepeater()
        {
            Pattern Negator = !((Pattern)"Hi!" * 2);

            Assert.That.Fails(Negator.Consume("Hi!Hi!"));
            Assert.That.Captures("Oh!Oh!", Negator.Consume("Oh!Oh!"));
        }
コード例 #10
0
        public void ConsumeSpanner()
        {
            Pattern Negator = !+(Pattern)";";

            Assert.That.Fails(Negator.Consume(";"));
            Assert.That.Captures("123456789", Negator.Consume("123456789;"));
        }
コード例 #11
0
        public void Double_Negator()
        {
            Pattern pattern = Not(Not("Hello"));

            ResultAssert.Captures("Hello", pattern.Consume("Hello"));
            ResultAssert.Fails(pattern.Consume("World"));
        }
コード例 #12
0
        public void Optional_Spanner()
        {
            Pattern pattern = Maybe(Many(' '));

            ResultAssert.Captures("  ", pattern.Consume("  Hello"));
            ResultAssert.Captures("", pattern.Consume("Hello"));
        }
コード例 #13
0
ファイル: LiteralTests.cs プロジェクト: BaisilG/Patterns
        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"));
        }
コード例 #14
0
        public void OptorSpanner()
        {
            Pattern Pattern = - +(Pattern)" ";

            Assert.That.Captures("  ", Pattern.Consume("  Hello"));
            Assert.That.Captures("", Pattern.Consume("Hello"));
        }
コード例 #15
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"));
        }
コード例 #16
0
        public void Simple_Consume()
        {
            Pattern pattern = Range("Hello", ';');

            ResultAssert.Captures("Hello;", pattern.Consume("Hello;"));
            ResultAssert.Captures("Hello World;", pattern.Consume("Hello World;"));
        }
コード例 #17
0
        public void ReadUntilEndOfLine()
        {
            Pattern pattern = Many(Not(';' | LineTerminator));

            ResultAssert.Captures("hello", pattern.Consume("hello"));
            ResultAssert.Captures("hello", pattern.Consume("hello\nworld"));
        }
コード例 #18
0
        public void Number()
        {
            Result Result;

            Pattern NumeralPattern = Pattern.DecimalDigitNumber & - +("_" | Pattern.DecimalDigitNumber);

            Pattern ExtendedDigitPattern = Pattern.DecimalDigitNumber | "a" | "A" | "b" | "B" | "c" | "C" | "d" | "D" | "e" | "E" | "f" | "F";

            Pattern BasedNumeralPattern = ExtendedDigitPattern & +("_" | ExtendedDigitPattern);

            Pattern SignPattern = (Pattern)"+" | "-";

            Pattern ExponentPattern = ("E", StringComparison.OrdinalIgnoreCase) & -SignPattern & NumeralPattern;

            Pattern Numeral = NumeralPattern & -("." & NumeralPattern) & -ExponentPattern;

            Result = Numeral.Consume("42");
            Assert.That.Captures("42", Result);

            Result = Numeral.Consume("4_2");
            Assert.That.Captures("4_2", Result);

            Pattern Fraction = "." & Numeral;

            Result = Fraction.Consume(".0");
            Assert.That.Captures(".0", Result);

            Pattern RealNumeral = Numeral & -Fraction;

            Result = RealNumeral.Consume("42.0");
            Assert.That.Captures("42.0", Result);
        }
コード例 #19
0
        public void WebAddress()
        {
            Pattern Protocol = "http" & -(Pattern)"s" & "://";
            Pattern Host     = +(Pattern.Letter | Pattern.Number | "-") & "." & (Pattern.Letter * 3 & Source.End | +(Pattern.Letter | Pattern.Number | "-") & "." & Pattern.Letter * 3);
            Pattern Location = +("/" & +(Pattern.Letter | Pattern.Number | "-" | "_"));
            Pattern Address  = -Protocol & Host & -Location;
            Result  Result;

            Result = Protocol.Consume("http://");
            Assert.That.Captures("http://", Result);
            Result = Protocol.Consume("https://");
            Assert.That.Captures("https://", Result);

            Result = Host.Consume("google.com");
            Assert.That.Captures("google.com", Result);
            Result = Host.Consume("www.google.com");
            Assert.That.Captures("www.google.com", Result);

            Result = Location.Consume("/about");
            Assert.That.Captures("/about", Result);

            Result = Address.Consume("www.google.com");
            Assert.That.Captures("www.google.com", Result);
            Result = Address.Consume("http://www.google.com");
            Assert.That.Captures("http://www.google.com", Result);
            Result = Address.Consume("http://www.google.com/about");
            Assert.That.Captures("http://www.google.com/about", Result);
        }
コード例 #20
0
ファイル: RepeaterTests.cs プロジェクト: BaisilG/Patterns
        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! "));
        }
コード例 #21
0
        public void ConsumeChecker()
        {
            Pattern Negator = !(Pattern)(nameof(Negator), (Char) => 0x30 <= Char && Char <= 0x39);

            Assert.That.Fails(Negator.Consume("3"));
            Assert.That.Fails(Negator.Consume("7"));
            Assert.That.Captures("A", Negator.Consume("A"));
        }
コード例 #22
0
        public void ConsumeAlternator()
        {
            Pattern Negator = !((Pattern)"Hello" | "Goodbye");

            Assert.That.Fails(Negator.Consume("Hello"));
            Assert.That.Fails(Negator.Consume("Goodbye"));
            Assert.That.Captures("World", Negator.Consume("Worldeater"));
        }
コード例 #23
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"));
        }
コード例 #24
0
        public void ConsumeOptor()
        {
            Pattern Negator = !-(Pattern)"Hello";

            Assert.That.Captures("", Negator.Consume("Hello"));

            Assert.That.Captures("World", Negator.Consume("World"));
        }
コード例 #25
0
        public void Consume()
        {
            Pattern pattern = Many(' ');

            ResultAssert.Captures(" ", pattern.Consume(" Hi!"));
            ResultAssert.Captures("    ", pattern.Consume("    Hi!"));
            ResultAssert.Fails(pattern.Consume("Hi!  "));
        }
コード例 #26
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(""));
        }
コード例 #27
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"));
        }
コード例 #28
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"));
        }
コード例 #29
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\""));
        }
コード例 #30
0
ファイル: RepeaterTests.cs プロジェクト: BaisilG/Patterns
        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! "));
        }