public void Double_Optor() { Pattern pattern = Maybe(Maybe("Hello")); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Captures("", pattern.Consume("World")); }
public void ConsumeLiteral() { Pattern Negator = !(Pattern)"Hello"; Assert.That.Fails(Negator.Consume("Hello")); Assert.That.Captures("World", Negator.Consume("World")); }
public void Neglect() { Pattern pattern = Not(Many(';')); ResultAssert.Captures("123456789", pattern.Consume("123456789;")); ResultAssert.Fails(pattern.Consume(";")); }
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); }
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();")); }
public void Alternate_Spanner() { Pattern pattern = Many(SpaceSeparator.Or('\t')); ResultAssert.Captures(" \t ", pattern.Consume(" \t ")); ResultAssert.Captures(" \t ", pattern.Consume(" \t hi")); }
public void Consume() { Pattern pattern = Maybe("Hello"); ResultAssert.Captures("Hello", pattern.Consume("Hello World")); ResultAssert.Captures("", pattern.Consume("Goodbye World")); }
public void Neglect() { Pattern pattern = Not(Maybe("Hello")); ResultAssert.Captures("", pattern.Consume("Hello")); ResultAssert.Captures("World", pattern.Consume("World")); }
public void ConsumeRepeater() { Pattern Negator = !((Pattern)"Hi!" * 2); Assert.That.Fails(Negator.Consume("Hi!Hi!")); Assert.That.Captures("Oh!Oh!", Negator.Consume("Oh!Oh!")); }
public void ConsumeSpanner() { Pattern Negator = !+(Pattern)";"; Assert.That.Fails(Negator.Consume(";")); Assert.That.Captures("123456789", Negator.Consume("123456789;")); }
public void Double_Negator() { Pattern pattern = Not(Not("Hello")); ResultAssert.Captures("Hello", pattern.Consume("Hello")); ResultAssert.Fails(pattern.Consume("World")); }
public void Optional_Spanner() { Pattern pattern = Maybe(Many(' ')); ResultAssert.Captures(" ", pattern.Consume(" Hello")); ResultAssert.Captures("", pattern.Consume("Hello")); }
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")); }
public void OptorSpanner() { Pattern Pattern = - +(Pattern)" "; Assert.That.Captures(" ", Pattern.Consume(" Hello")); Assert.That.Captures("", Pattern.Consume("Hello")); }
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")); }
public void Simple_Consume() { Pattern pattern = Range("Hello", ';'); ResultAssert.Captures("Hello;", pattern.Consume("Hello;")); ResultAssert.Captures("Hello World;", pattern.Consume("Hello World;")); }
public void ReadUntilEndOfLine() { Pattern pattern = Many(Not(';' | LineTerminator)); ResultAssert.Captures("hello", pattern.Consume("hello")); ResultAssert.Captures("hello", pattern.Consume("hello\nworld")); }
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); }
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); }
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! ")); }
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")); }
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")); }
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")); }
public void ConsumeOptor() { Pattern Negator = !-(Pattern)"Hello"; Assert.That.Captures("", Negator.Consume("Hello")); Assert.That.Captures("World", Negator.Consume("World")); }
public void Consume() { Pattern pattern = Many(' '); ResultAssert.Captures(" ", pattern.Consume(" Hi!")); ResultAssert.Captures(" ", pattern.Consume(" Hi!")); ResultAssert.Fails(pattern.Consume("Hi! ")); }
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("")); }
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")); }
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")); }
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\"")); }
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! ")); }