Example #1
0
        public override void ProcessTree()
        {
            if (Root == null || Root.Items.Count == 0)
            {
                return;
            }
            List <ANY_TreeNode> Nodes  = new List <ANY_TreeNode>();
            List <SourceEntity> Result = new List <SourceEntity>();

            foreach (ANY_TreeNode node in Root.Items)
            {
                if (node.Value.Count == 0)
                {
                    continue;
                }
                if (node is CommentStart)
                {
                    Nodes.Add(node);
                }
                if (node is CommentEnd)
                {
                    int startIndex;
                    for (startIndex = Nodes.Count - 1; startIndex >= 0; --startIndex)
                    {
                        if (node.Value[0] == Nodes[startIndex].Value[0])
                        {
                            break;
                        }
                    }
                    if (startIndex < 0)
                    {
                        continue;
                    }
                    ANY_TreeNode newNode = new ANY_TreeNode(Nodes[startIndex].Value, Nodes[startIndex].Location.Merge(node.Location));
                    for (int i = startIndex + 1; i < Nodes.Count; ++i)
                    {
                        if (Nodes[i].GetType() == typeof(ANY_TreeNode))
                        {
                            newNode.Items.Add(Nodes[i]);
                        }
                    }
                    Nodes.RemoveRange(startIndex, Nodes.Count - startIndex);
                    Nodes.Add(newNode);
                }
            }
            foreach (ANY_TreeNode node in Nodes)
            {
                if (node.GetType() == typeof(ANY_TreeNode))
                {
                    Result.Add(node);
                }
            }
            Root.Items = Result;
        }
Example #2
0
        protected override void DoAction(int action)
        {
            CurrentSemanticValue = new ValueType();
#pragma warning disable 162, 1522
            switch (action)
            {
            case 2: // TextLine -> _Tk_listNE
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 1].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddValue(ValueStack[ValueStack.Depth - 1].type_ANY_TreeNode);
            }
            break;

            case 3: // CommentStart -> _StarRopen, TextLine
            {
                CurrentSemanticValue.type_CommentStart = new CommentStart(new List <string>(), LocationStack[LocationStack.Depth - 2].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_CommentStart.Location;
                CurrentSemanticValue.type_CommentStart.AddValue(ValueStack[ValueStack.Depth - 1].type_ANY_TreeNode);
            }
            break;

            case 4: // CommentEnd -> _StarRclose, TextLine
            {
                CurrentSemanticValue.type_CommentEnd = new CommentEnd(new List <string>(), LocationStack[LocationStack.Depth - 2].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_CommentEnd.Location;
                CurrentSemanticValue.type_CommentEnd.AddValue(ValueStack[ValueStack.Depth - 1].type_ANY_TreeNode);
            }
            break;

            case 5: // Program -> _ProgramNode_list
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 1].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddSubItems(ValueStack[ValueStack.Depth - 1].type_ANY_TreeNode);
                root = CurrentSemanticValue.type_ANY_TreeNode;
            }
            break;

            case 6: // ProgramNode -> CommentStart
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 1].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddItem(ValueStack[ValueStack.Depth - 1].type_CommentStart);
                errBegin = CurrentLocationSpan;
            }
            break;

            case 7: // ProgramNode -> CommentEnd
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 1].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddItem(ValueStack[ValueStack.Depth - 1].type_CommentEnd);
                errBegin = CurrentLocationSpan;
            }
            break;

            case 8: // ProgramNode -> TextLine
            { CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode();
              if (CurrentLocationSpan == null)
              {
                  CurrentLocationSpan = new LexLocation(1, 0, 1, 0);
              }
              errBegin = CurrentLocationSpan; }
              break;

            case 9: // ProgramNode -> NewLine
            { CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode();
              if (CurrentLocationSpan == null)
              {
                  CurrentLocationSpan = new LexLocation(1, 0, 1, 0);
              }
              errBegin = CurrentLocationSpan; }
              break;

            case 10: // ProgramNode -> error
            {
                CurrentLocationSpan = new LexLocation(errBegin.EndLine, errBegin.EndColumn, LocationStack[LocationStack.Depth - 1].StartLine, LocationStack[LocationStack.Depth - 1].StartColumn);
                ANY_TreeNode err = new ANY_TreeNode((Scanner as Scanner).errorMsg, CurrentLocationSpan);
                Errors.Add(err);
                errBegin = CurrentLocationSpan;
            }
            break;

            case 11: // _Tk_listNE -> Tk
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 1].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddValue(ValueStack[ValueStack.Depth - 1].type_Token);
                CurrentSemanticValue.type_ANY_TreeNode.AddItem(ValueStack[ValueStack.Depth - 1].type_Token);
            }
            break;

            case 12: // _Tk_listNE -> _Tk_listNE, Tk
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 2].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddValue(ValueStack[ValueStack.Depth - 2].type_ANY_TreeNode);
                CurrentSemanticValue.type_ANY_TreeNode.AddValue(ValueStack[ValueStack.Depth - 1].type_Token);
                CurrentSemanticValue.type_ANY_TreeNode.AddSubItems(ValueStack[ValueStack.Depth - 2].type_ANY_TreeNode);
                CurrentSemanticValue.type_ANY_TreeNode.AddItem(ValueStack[ValueStack.Depth - 1].type_Token);
            }
            break;

            case 13: // _ProgramNode_list -> /* empty */
            { CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode();
              if (CurrentLocationSpan == null)
              {
                  CurrentLocationSpan = new LexLocation(1, 0, 1, 0);
              }
            }
            break;

            case 14: // _ProgramNode_list -> _ProgramNode_list, ProgramNode
            {
                CurrentSemanticValue.type_ANY_TreeNode = new ANY_TreeNode(new List <string>(), LocationStack[LocationStack.Depth - 2].Merge(LocationStack[LocationStack.Depth - 1]));
                CurrentLocationSpan = CurrentSemanticValue.type_ANY_TreeNode.Location;
                CurrentSemanticValue.type_ANY_TreeNode.AddValue(ValueStack[ValueStack.Depth - 2].type_ANY_TreeNode);
                CurrentSemanticValue.type_ANY_TreeNode.AddValue(ValueStack[ValueStack.Depth - 1].type_ANY_TreeNode);
                CurrentSemanticValue.type_ANY_TreeNode.AddSubItems(ValueStack[ValueStack.Depth - 2].type_ANY_TreeNode);
                CurrentSemanticValue.type_ANY_TreeNode.AddSubItems(ValueStack[ValueStack.Depth - 1].type_ANY_TreeNode);
            }
            break;
            }
#pragma warning restore 162, 1522
        }