Beispiel #1
0
        private static void TestScenario(string grammar, HighlightRuleCollection <Token> rules, string subject, IEnumerable <HighlightedSegment <Token> > result)
        {
            var compiled = PegCompiler.Compile(new PegParser().Parse(grammar));
            var parser   = CodeCompiler.Compile <string>(compiled);

            parser.Parse(subject, null, out var lexicalElements);

            var highlighter = new SyntaxHighlighter <Token>(rules);
            var tokens      = highlighter.GetTokens(lexicalElements);

            tokens = highlighter.AddDefaultTokens(tokens, subject.Length, Token.Unknown);
            tokens = highlighter.SplitOnWhiteSpace(tokens, subject);

            Assert.That(ToAssertString(tokens), Is.EqualTo(ToAssertString(result)));
        }
Beispiel #2
0
        private static void TestScenario(string grammar, HighlightRuleCollection <Token> rules, TokenList tokens)
        {
            var result  = new List <HighlightedSegment <Token> >();
            var subject = new StringBuilder();

            foreach (var token in tokens)
            {
                var start = subject.Length;
                subject.Append(token.Item1);
                var end = subject.Length;

                result.Add(new HighlightedSegment <Token>(start, end, token.Item2));
            }

            TestScenario(grammar, rules, subject.ToString(), result);
        }