Beispiel #1
0
        public void SpecifyingConversionShouldReturnNewParserWithIndependentTagging()
        {
            var parser = new Parser<Token>(
                (token, ctx, args) => token,
                new ParseRule("A", new PatternTerminal("[0-9]+")))
                .Tagging("A", () => "tag 1");

            Parser<string> convertedParser = parser.ConvertingResultUsing(token => token.Tag.ToString());
            convertedParser.Tagging("A", () => "tag 2");

            Assert.Equal("tag 1", parser.Parse("123").Tag);
            Assert.Equal("tag 2", convertedParser.Parse("123"));
        }
Beispiel #2
0
        public void SpecifyingConversionShouldReturnNewParserWithConversion()
        {
            var parser = new Parser<Token>(
                (token, ctx, args) => token,
                new ParseRule("A", new PatternTerminal("[0-9]+")));

            Parser<int> convertedParser = parser.ConvertingResultUsing((token, ctx, args) => int.Parse(ctx.MatchedText(token)));

            Assert.Equal(123, convertedParser.Parse("123"));
        }