Esempio n. 1
0
        private static IEnumerable <IReadOnlyList <SyntaxNode> > RevertParseForIncompleteGroups(this IEnumerable <SyntaxNode> tags, LanguageSyntax syntax)
        {
            var groups = tags.CutToGroups(syntax).ToList();

            foreach (var group in groups)
            {
                if (group.First().IsRawString || syntax.GetTag(group.First().TagName).GroupName == null)
                {
                    foreach (var node in group)
                    {
                        yield return(new List <SyntaxNode> {
                            node
                        });
                    }
                }
                else
                {
                    var groupName = syntax.GetTag(group.First().TagName).GroupName;
                    var expected  = syntax.GetTagInGroup(groupName);
                    if (group.Count != expected.Count())
                    {
                        var str = group.Select(syntax.Build).SequenceToString("", "", "");
                        yield return(new List <SyntaxNode> {
                            SyntaxNode.CreateRawString(str)
                        });
                    }
                    else
                    {
                        yield return(group);
                    }
                }
            }
        }
Esempio n. 2
0
        private static IEnumerable <IReadOnlyList <SyntaxNode> > CutToFullGroups(this List <SyntaxNode> group, LanguageSyntax syntax)
        {
            if (group.Count == 0)
            {
                return(new List <IReadOnlyList <SyntaxNode> >());
            }
            var groupName = group.First().IsRawString ? null : syntax.GetTag(group.First().TagName).GroupName;

            if (groupName == null)
            {
                return new[] { group.ToList() }
            }
            ;
            var expected = syntax.GetTagInGroup(groupName).Select(t => t.Name).ToList();
            var tags     = group.ToList();

            if (tags.Count < expected.Count)
            {
                return new[] { group.ToList() }
            }
            ;

            var isFullCombination = tags.IsFullCombination(expected);
            var length            = isFullCombination ? expected.Count : 1;

            var result = new List <IReadOnlyList <SyntaxNode> >();

            result.Add(tags.SubEnumerable(0, length).ToList());
            result.AddRange(tags.SubEnumerable(length, tags.Count - length).ToList().CutToFullGroups(syntax));

            return(result);
        }