public void GetWellFormedValues_ShouldBehaveAsExpected(string input, string wellFormed) { // General var terminalLexerFactory = new TerminalLexerFactory(); var alternativeLexerFactory = new AlternativeLexerFactory(); var sequenceLexerFactory = new ConcatenationLexerFactory(); var repetitionLexerFactory = new RepetitionLexerFactory(); // SP var spaceLexerFactory = new SpaceLexerFactory(terminalLexerFactory); // HTAB var horizontalTabLexerFactory = new HorizontalTabLexerFactory(terminalLexerFactory); // WSP var whiteSpaceLexerFactory = new WhiteSpaceLexerFactory( spaceLexerFactory, horizontalTabLexerFactory, alternativeLexerFactory); // CR var carriageReturnLexerFactory = new CarriageReturnLexerFactory(terminalLexerFactory); // LF var lineFeedLexerFactory = new LineFeedLexerFactory(terminalLexerFactory); // CRLF var endOfLineLexerFactory = new EndOfLineLexerFactory( carriageReturnLexerFactory, lineFeedLexerFactory, sequenceLexerFactory); // LWSP var linearWhiteSpaceLexerFactory = new LinearWhiteSpaceLexerFactory( whiteSpaceLexerFactory, endOfLineLexerFactory, sequenceLexerFactory, alternativeLexerFactory, repetitionLexerFactory); var linearWhiteSpaceLexer = linearWhiteSpaceLexerFactory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = linearWhiteSpaceLexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(wellFormed, result.Element.GetWellFormedText()); } }
public static IEnumerable <object[]> GetTestData() { var factory = new TerminalLexerFactory(); var foo = factory.Create("foo", StringComparer.OrdinalIgnoreCase); var bar = factory.Create("bar", StringComparer.OrdinalIgnoreCase); var charlie = factory.Create("charlie", StringComparer.OrdinalIgnoreCase); var listItemLexer = new AlternationLexer(foo, bar, charlie); yield return(new object[] { "foo,bar", "foo, bar", listItemLexer }); yield return(new object[] { "foo ,bar,", "foo, bar", listItemLexer }); yield return(new object[] { "foo , ,bar,charlie ", "foo, bar, charlie", listItemLexer }); }
public void ReadSuccess(string input) { // General var terminalLexerFactory = new TerminalLexerFactory(); var alternativeLexerFactory = new AlternativeLexerFactory(); var sequenceLexerFactory = new ConcatenationLexerFactory(); var repetitionLexerFactory = new RepetitionLexerFactory(); // SP var spaceLexerFactory = new SpaceLexerFactory(terminalLexerFactory); // HTAB var horizontalTabLexerFactory = new HorizontalTabLexerFactory(terminalLexerFactory); // WSP var whiteSpaceLexerFactory = new WhiteSpaceLexerFactory( spaceLexerFactory, horizontalTabLexerFactory, alternativeLexerFactory); // CR var carriageReturnLexerFactory = new CarriageReturnLexerFactory(terminalLexerFactory); // LF var lineFeedLexerFactory = new LineFeedLexerFactory(terminalLexerFactory); // CRLF var endOfLineLexerFactory = new EndOfLineLexerFactory( carriageReturnLexerFactory, lineFeedLexerFactory, sequenceLexerFactory); // LWSP var linearWhiteSpaceLexerFactory = new LinearWhiteSpaceLexerFactory( whiteSpaceLexerFactory, endOfLineLexerFactory, sequenceLexerFactory, alternativeLexerFactory, repetitionLexerFactory); var linearWhiteSpaceLexer = linearWhiteSpaceLexerFactory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = linearWhiteSpaceLexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }
public void ReadSuccess(string input) { var valueRangeLexerFactory = new ValueRangeLexerFactory(); var digitLexerFactory = new DigitLexerFactory(valueRangeLexerFactory); var terminalLexerFactory = new TerminalLexerFactory(); var alternativeLexerFactory = new AlternativeLexerFactory(); var factory = new HexadecimalDigitLexerFactory(digitLexerFactory, terminalLexerFactory, alternativeLexerFactory); var lexer = factory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = lexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }
public void ReadSuccess(string input) { var terminalsLexerFactory = new TerminalLexerFactory(); var sequenceLexerFactory = new ConcatenationLexerFactory(); var carriageReturnLexerFactory = new CarriageReturnLexerFactory(terminalsLexerFactory); var lineFeedLexerFactory = new LineFeedLexerFactory(terminalsLexerFactory); var factory = new EndOfLineLexerFactory(carriageReturnLexerFactory, lineFeedLexerFactory, sequenceLexerFactory); var endOfLineLexer = factory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = endOfLineLexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }
public void ReadSuccess(string input) { var terminalLexerFactory = new TerminalLexerFactory(); var spaceLexerFactory = new SpaceLexerFactory(terminalLexerFactory); var horizontalTabLexerFactory = new HorizontalTabLexerFactory(terminalLexerFactory); var alternativeLexerFactory = new AlternativeLexerFactory(); var whiteSpaceLexerFactory = new WhiteSpaceLexerFactory(spaceLexerFactory, horizontalTabLexerFactory, alternativeLexerFactory); var whiteSpaceLexer = whiteSpaceLexerFactory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = whiteSpaceLexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }
public void ReadSuccess(string input) { var terminalsLexerFactory = new TerminalLexerFactory(); var sequenceLexerFactory = new ConcatenationLexerFactory(); var carriageReturnLexerFactory = new CarriageReturnLexerFactory(terminalsLexerFactory); var lineFeedLexerFactory = new LineFeedLexerFactory(terminalsLexerFactory); var factory = new EndOfLineLexerFactory(carriageReturnLexerFactory, lineFeedLexerFactory, sequenceLexerFactory); var endOfLineLexer = factory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = endOfLineLexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }
public void ReadSuccess(string input) { var valueRangeLexerFactory = new ValueRangeLexerFactory(); var digitLexerFactory = new DigitLexerFactory(valueRangeLexerFactory); var terminalLexerFactory = new TerminalLexerFactory(); var alternativeLexerFactory = new AlternativeLexerFactory(); var factory = new HexadecimalDigitLexerFactory(digitLexerFactory, terminalLexerFactory, alternativeLexerFactory); var lexer = factory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = lexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }
public void ReadSuccess(string input) { var terminalLexerFactory = new TerminalLexerFactory(); var spaceLexerFactory = new SpaceLexerFactory(terminalLexerFactory); var horizontalTabLexerFactory = new HorizontalTabLexerFactory(terminalLexerFactory); var alternativeLexerFactory = new AlternativeLexerFactory(); var whiteSpaceLexerFactory = new WhiteSpaceLexerFactory(spaceLexerFactory, horizontalTabLexerFactory, alternativeLexerFactory); var whiteSpaceLexer = whiteSpaceLexerFactory.Create(); using (var scanner = new TextScanner(new StringTextSource(input))) { var result = whiteSpaceLexer.Read(scanner); Assert.NotNull(result); Assert.True(result.Success); Assert.NotNull(result.Element); Assert.Equal(input, result.Element.Text); } }