Пример #1
0
        public SourceWithMarkedNodes(string markedSource, Func <string, SyntaxTree> parser, Func <string, int> getSyntaxKind)
        {
            Source = ClearTags(markedSource);
            Tree   = parser(Source);

            SpansAndKinds = ImmutableArray.CreateRange(
                from match in MarkerPattern.Matches(markedSource).ToEnumerable()
                let markedSyntax = match.Groups["MarkedSyntax"]
                                   let syntaxKindOpt = match.Groups["SyntaxKind"].Value
                                                       let parsedKind = string.IsNullOrEmpty(syntaxKindOpt) ? 0 : getSyntaxKind(syntaxKindOpt)
                                                                        select ValueTuple.Create(new TextSpan(markedSyntax.Index, markedSyntax.Length), parsedKind));
        }
Пример #2
0
        private static IEnumerable <ValueTuple <TextSpan, int> > GetSpansRecursive(string markedSource, int offset, Func <string, int> getSyntaxKind)
        {
            foreach (var match in MarkerPattern.Matches(markedSource).ToEnumerable())
            {
                var markedSyntax   = match.Groups["MarkedSyntax"];
                var syntaxKindOpt  = match.Groups["SyntaxKind"].Value;
                var parsedKind     = string.IsNullOrEmpty(syntaxKindOpt) ? 0 : getSyntaxKind(syntaxKindOpt);
                int absoluteOffset = offset + markedSyntax.Index;

                yield return(ValueTuple.Create(new TextSpan(absoluteOffset, markedSyntax.Length), parsedKind));

                foreach (var nestedSpan in GetSpansRecursive(markedSyntax.Value, absoluteOffset, getSyntaxKind))
                {
                    yield return(nestedSpan);
                }
            }
        }