private void ProcessNode(Block block, NodeViewModel node)
        {
            block.AddNode(node);
            var areMoreMates = false;

            foreach (var mate in node.Mates)
            {
                if (areMoreMates)
                {
                    var parent = block.Parent;
                    block = new Block();
                    parent.AddChild(block);
                }

                block.AddNode(mate);

                if (!mate.HasChilds)
                {
                    continue;
                }

                foreach (var child in mate.Children)
                {
                    var newBlock = new Block();
                    block.AddChild(newBlock);

                    ProcessNode(newBlock, child);
                }

                areMoreMates = true;
            }
        }
示例#2
0
        private Node Block()
        {
            var sentence = Sentence();
            var block    = new Block(sentence);

            while (Tokens.Accept(TokenEnum.SentenceEnd))
            {
                block.AddNode(Sentence());
            }
            if (Tokens.IsEnd)
            {
                return(block.Sentences.Count == 1 ? block.Sentences[0] : block);
            }
            else
            {
                throw new UnexpectedTokenException(Tokens.PeekToken() ?? throw new Exception("[Parser] Tokens.IsEnd == false, but Tokens.PeekToken() == null."));
            }
        }