Exemple #1
0
        public void NonGreedyContentStopsMatchingWhenFollowingTokensMatch()
        {
            // It's likely we'll only be able to get one or two tokens into
            // the "following" list, since they effectively become "mandatory"
            var following = new[]
            {
                new SimplePatternElement(Matchers.LiteralText(" (")),
                new SimplePatternElement(Matchers.Identifier, "last"),
                new SimplePatternElement(Matchers.LiteralText(")"))
            };

            var pattern = new NameValueExtractor(new[]
            {
                new SimplePatternElement(Matchers.Identifier, "first"),
                new SimplePatternElement(Matchers.LiteralText(" ")),
                new SimplePatternElement(Matchers.NonGreedyContent(following), "content"),
            }.Concat(following));

            var frame = "abc def ghi (jkl)";

            var(properties, remainder) = pattern.ExtractValues(frame);
            Assert.Null(remainder);
            Assert.Equal("abc", properties["first"].ToString());
            Assert.Equal("def ghi", properties["content"].ToString());
            Assert.Equal("jkl", properties["last"].ToString());
        }
Exemple #2
0
        public void SingleLineContentMatchesUntilEol()
        {
            var pattern = new NameValueExtractor(new[]
            {
                new SimplePatternElement(Matchers.Identifier, "first"),
                new SimplePatternElement(Matchers.LiteralText(" ")),
                new SimplePatternElement(Matchers.SingleLineContent, "content"),
                new SimplePatternElement(Matchers.LiteralText(" (")),
                new SimplePatternElement(Matchers.Identifier, "last"),
                new SimplePatternElement(Matchers.LiteralText(")"))
            });

            var frame = "abc def ghi (jkl)";

            var(properties, remainder) = pattern.ExtractValues(frame);
            Assert.Null(remainder);
            Assert.Equal("abc", properties["first"].ToString());
            Assert.Equal("def ghi (jkl)", properties["content"].ToString());
        }
        public async Task <ReadResult> TryReadAsync()
        {
            var frame = await _reader.TryReadAsync();

            if (!frame.HasValue)
            {
                return(new ReadResult(null, frame.IsAtEnd));
            }

            if (frame.IsOrphan)
            {
                throw new InvalidDataException($"A line arrived late or could not be parsed: `{frame.Value.Trim()}`.");
            }

            var(properties, remainder) = _nameValueExtractor.ExtractValues(frame.Value);
            var evt = LogEventBuilder.FromProperties(properties, remainder);

            return(new ReadResult(evt, frame.IsAtEnd));
        }