internal static void CollectConstituentTokensAndDiagnostics(this GreenNode node, InternalSyntax.SyntaxListBuilder <SyntaxToken.Green> tokenListBuilder, IList <DiagnosticInfo> nonTokenDiagnostics)
        {
            if (node == null)
            {
                return;
            }

            if (node.IsToken)
            {
                tokenListBuilder.Add((SyntaxToken.Green)node);
                return;
            }

            DiagnosticInfo[] diagnostics = node.GetDiagnostics();
            if (diagnostics != null && diagnostics.Length > 0)
            {
                foreach (var diag in diagnostics)
                {
                    nonTokenDiagnostics.Add(diag);
                }
            }

            // Recurse to subtrees.
            for (var i = 0; i < node.SlotCount; i++)
            {
                var green = node.GetSlot(i);
                if (green != null)
                {
                    green.CollectConstituentTokensAndDiagnostics(tokenListBuilder, nonTokenDiagnostics);
                }
            }
        }
Exemple #2
0
        public void Add(GreenNode item)
        {
            if (item == null)
            {
                return;
            }

            if (item.IsList)
            {
                int slotCount = item.SlotCount;

                // Necessary, but not sufficient (e.g. for nested lists).
                EnsureAdditionalCapacity(slotCount);

                for (int i = 0; i < slotCount; i++)
                {
                    this.Add(item.GetSlot(i));
                }
            }
            else
            {
                EnsureAdditionalCapacity(1);

                _nodes[Count++].Value = item;
            }
        }
Exemple #3
0
        internal GreenNode GetLastNonmissingTerminal()
        {
            GreenNode node = this;

            do
            {
                GreenNode nonmissingChild = null;
                for (int i = node.SlotCount - 1; i >= 0; i--)
                {
                    var child = node.GetSlot(i);
                    if (child != null)
                    {
                        nonmissingChild = child;
                        break;
                    }
                }
                node = nonmissingChild;
            }while (node?.SlotCount > 0);

            return(node);
        }
Exemple #4
0
        internal GreenNode GetFirstTerminal()
        {
            GreenNode node = this;

            do
            {
                GreenNode firstChild = null;
                for (int i = 0, n = node.SlotCount; i < n; i++)
                {
                    var child = node.GetSlot(i);
                    if (child != null)
                    {
                        firstChild = child;
                        break;
                    }
                }
                node = firstChild;
            } while (node?.SlotCount > 0);

            return(node);
        }