コード例 #1
0
 private static void GetDirectives(GreenNode node, List <DirectiveTriviaSyntax> directives)
 {
     if (node != null && node.ContainsDirectives)
     {
         var d = node as DirectiveTriviaSyntax;
         if (d != null)
         {
             directives.Add(d);
         }
         else
         {
             var t = node as SyntaxToken;
             if (t != null)
             {
                 GetDirectives(t.GetLeadingTrivia(), directives);
                 GetDirectives(t.GetTrailingTrivia(), directives);
             }
             else
             {
                 for (int i = 0, n = node.SlotCount; i < n; i++)
                 {
                     GetDirectives(node.GetSlot(i), directives);
                 }
             }
         }
     }
 }
コード例 #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++] = item;
            }
        }
コード例 #3
0
ファイル: GreenNode.cs プロジェクト: nullai/LeeLang
        private static bool EquivalentToInternal(GreenNode node1, GreenNode node2)
        {
            if (node1.RawKind != node2.RawKind)
            {
                // A single-element list is usually represented as just a single node,
                // but can be represented as a List node with one child. Move to that
                // child if necessary.
                if (node1.IsList && node1.SlotCount == 1)
                {
                    node1 = node1.GetSlot(0);
                }

                if (node2.IsList && node2.SlotCount == 1)
                {
                    node2 = node2.GetSlot(0);
                }

                if (node1.RawKind != node2.RawKind)
                {
                    return(false);
                }
            }

            if (node1._fullWidth != node2._fullWidth)
            {
                return(false);
            }

            var n = node1.SlotCount;

            if (n != node2.SlotCount)
            {
                return(false);
            }

            for (int i = 0; i < n; i++)
            {
                var node1Child = node1.GetSlot(i);
                var node2Child = node2.GetSlot(i);
                if (node1Child != null && node2Child != null && !node1Child.IsEquivalentTo(node2Child))
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #4
0
ファイル: ChildSyntaxList.cs プロジェクト: nullai/LeeLang
                public bool MoveNext()
                {
                    if (_node != null)
                    {
                        if (_list != null)
                        {
                            if (--_listIndex >= 0)
                            {
                                _currentChild = _list.GetSlot(_listIndex);
                                return(true);
                            }

                            _list      = null;
                            _listIndex = -1;
                        }

                        while (--_childIndex >= 0)
                        {
                            var child = _node.GetSlot(_childIndex);
                            if (child == null)
                            {
                                continue;
                            }

                            if (child.IsList)
                            {
                                _list      = child;
                                _listIndex = _list.SlotCount;
                                if (--_listIndex >= 0)
                                {
                                    _currentChild = _list.GetSlot(_listIndex);
                                    return(true);
                                }
                                else
                                {
                                    _list      = null;
                                    _listIndex = -1;
                                    continue;
                                }
                            }
                            else
                            {
                                _currentChild = child;
                            }

                            return(true);
                        }
                    }

                    _currentChild = null;
                    return(false);
                }
コード例 #5
0
        public static DirectiveStack ApplyDirectives(GreenNode node, DirectiveStack stack)
        {
            if (node.ContainsDirectives)
            {
                for (int i = 0, n = node.SlotCount; i < n; i++)
                {
                    var child = node.GetSlot(i);
                    if (child != null)
                    {
                        stack = ApplyDirectivesToListOrNode(child, stack);
                    }
                }
            }

            return(stack);
        }
コード例 #6
0
ファイル: GreenNode.cs プロジェクト: nullai/LeeLang
        private static int GetLastNonNullChildIndex(GreenNode node)
        {
            int n         = node.SlotCount;
            int lastIndex = n - 1;

            for (; lastIndex >= 0; lastIndex--)
            {
                var child = node.GetSlot(lastIndex);
                if (child != null)
                {
                    break;
                }
            }

            return(lastIndex);
        }
コード例 #7
0
ファイル: GreenNode.cs プロジェクト: nullai/LeeLang
        private static int GetFirstNonNullChildIndex(GreenNode node)
        {
            int n          = node.SlotCount;
            int firstIndex = 0;

            for (; firstIndex < n; firstIndex++)
            {
                var child = node.GetSlot(firstIndex);
                if (child != null)
                {
                    break;
                }
            }

            return(firstIndex);
        }
コード例 #8
0
ファイル: SyntaxParser.cs プロジェクト: nullai/LeeLang
        /// <summary>
        /// This function searches for the given location node within the subtree rooted at root node.
        /// If it finds it, the function computes the offset span of that child node within the root and returns true,
        /// otherwise it returns false.
        /// </summary>
        /// <param name="root">Root node</param>
        /// <param name="location">Node to search in the subtree rooted at root node</param>
        /// <param name="offset">Offset of the location node within the subtree rooted at child</param>
        /// <returns></returns>
        private bool FindOffset(GreenNode root, LeeSyntaxNode location, out int offset)
        {
            int currentOffset = 0;

            offset = 0;
            if (root != null)
            {
                for (int i = 0, n = root.SlotCount; i < n; i++)
                {
                    var child = root.GetSlot(i);
                    if (child == null)
                    {
                        // ignore null slots
                        continue;
                    }

                    // check if the child node is the location node
                    if (child == location)
                    {
                        // Found the location node in the subtree
                        // Initialize offset with the offset of the location node within its parent
                        // and walk up the stack of recursive calls adding the offset of each node
                        // within its parent
                        offset = currentOffset;
                        return(true);
                    }

                    // search for the location node in the subtree rooted at child node
                    if (this.FindOffset(child, location, out offset))
                    {
                        // Found the location node in child's subtree
                        // Add the offset of child node within its parent to offset
                        // and continue walking up the stack
                        offset += child.GetLeadingTriviaWidth() + currentOffset;
                        return(true);
                    }

                    // We didn't find the location node in the subtree rooted at child
                    // Move on to the next child
                    currentOffset += child.FullWidth;
                }
            }

            // We didn't find the location node within the subtree rooted at root node
            return(false);
        }
コード例 #9
0
ファイル: GreenNode.cs プロジェクト: nullai/LeeLang
        public 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 && !child.IsMissing)
                    {
                        nonmissingChild = child;
                        break;
                    }
                }
                node = nonmissingChild;
            }while (node?._slotCount > 0);

            return(node);
        }
コード例 #10
0
ファイル: GreenNode.cs プロジェクト: nullai/LeeLang
        public GreenNode GetLastTerminal()
        {
            GreenNode node = this;

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

            return(node);
        }
コード例 #11
0
ファイル: GreenNode.cs プロジェクト: nullai/LeeLang
        public 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);
        }
コード例 #12
0
ファイル: ChildSyntaxList.cs プロジェクト: nullai/LeeLang
            public bool MoveNext()
            {
                if (_node != null)
                {
                    if (_list != null)
                    {
                        _listIndex++;

                        if (_listIndex < _list.SlotCount)
                        {
                            _currentChild = _list.GetSlot(_listIndex);
                            return(true);
                        }

                        _list      = null;
                        _listIndex = -1;
                    }

                    while (true)
                    {
                        _childIndex++;

                        if (_childIndex == _node.SlotCount)
                        {
                            break;
                        }

                        var child = _node.GetSlot(_childIndex);
                        if (child == null)
                        {
                            continue;
                        }

                        if (child.RawKind == GreenNode.ListKind)
                        {
                            _list = child;
                            _listIndex++;

                            if (_listIndex < _list.SlotCount)
                            {
                                _currentChild = _list.GetSlot(_listIndex);
                                return(true);
                            }
                            else
                            {
                                _list      = null;
                                _listIndex = -1;
                                continue;
                            }
                        }
                        else
                        {
                            _currentChild = child;
                        }

                        return(true);
                    }
                }

                _currentChild = null;
                return(false);
            }
コード例 #13
0
ファイル: SyntaxTriviaList.cs プロジェクト: nullai/LeeLang
 private static GreenNode GetGreenNodeAt(GreenNode node, int i)
 {
     Debug.Assert(node.IsList || (i == 0 && !node.IsList));
     return(node.IsList ? node.GetSlot(i) : node);
 }