Example #1
0
        protected void ToDOTDefineEdges(object tree, ITreeAdaptor adaptor, StringTemplate treeST)
        {
            if (tree == null)
            {
                return;
            }
            int n = adaptor.GetChildCount(tree);

            if (n == 0)
            {
                // must have already dumped as child from previous
                // invocation; do nothing
                return;
            }

            string parentName = "n" + GetNodeNumber(tree);

            // for each child, do a parent -> child edge using unique node names
            string parentText = adaptor.GetNodeText(tree);

            for (int i = 0; i < n; i++)
            {
                object         child     = adaptor.GetChild(tree, i);
                string         childText = adaptor.GetNodeText(child);
                string         childName = "n" + GetNodeNumber(child);
                StringTemplate edgeST    = _edgeST.GetInstanceOf();
                edgeST.SetAttribute("parent", parentName);
                edgeST.SetAttribute("child", childName);
                edgeST.SetAttribute("parentText", parentText);
                edgeST.SetAttribute("childText", childText);
                treeST.SetAttribute("edges", edgeST);
                ToDOTDefineEdges(child, adaptor, treeST);
            }
        }
Example #2
0
        override public void ConsumeNode(object t)
        {
            int    ID   = adaptor.GetUniqueID(t);
            string text = adaptor.GetNodeText(t);
            int    type = adaptor.GetNodeType(t);

            Console.Out.WriteLine("ConsumeNode " + ID + " " + text + " " + type);
        }
Example #3
0
        public override void LT(int i, object t)
        {
            int           ID   = adaptor.GetUniqueID(t);
            string        text = adaptor.GetNodeText(t);
            int           type = adaptor.GetNodeType(t);
            StringBuilder buf  = new StringBuilder(50);

            buf.Append("LN\t");             // lookahead node; distinguish from LT in protocol
            buf.Append(i);
            SerializeNode(buf, t);
            Transmit(buf.ToString());
        }
        protected void ExtractInformationFromTreeNodeStream(IIntStream input)
        {
            ITreeNodeStream nodes = (ITreeNodeStream)input;

            this.node = nodes.LT(1);
            ITreeAdaptor adaptor = nodes.TreeAdaptor;
            IToken       payload = adaptor.GetToken(node);

            if (payload != null)
            {
                this.token = payload;
                if (payload.Line <= 0)
                {
                    // imaginary node; no line/pos info; scan backwards
                    int    i         = -1;
                    object priorNode = nodes.LT(i);
                    while (priorNode != null)
                    {
                        IToken priorPayload = adaptor.GetToken(priorNode);
                        if ((priorPayload != null) && (priorPayload.Line > 0))
                        {
                            // we found the most recent real line / pos info
                            this.line = priorPayload.Line;
                            this.charPositionInLine  = priorPayload.CharPositionInLine;
                            this.approximateLineInfo = true;
                            break;
                        }
                        --i;
                        priorNode = nodes.LT(i);
                    }
                }
                else
                {
                    // node created from real token
                    this.line = payload.Line;
                    this.charPositionInLine = payload.CharPositionInLine;
                }
            }
            else if (this.node is ITree)
            {
                this.line = ((ITree)this.node).Line;
                this.charPositionInLine = ((ITree)this.node).CharPositionInLine;
                if (this.node is CommonTree)
                {
                    this.token = ((CommonTree)this.node).Token;
                }
            }
            else
            {
                int    type = adaptor.GetNodeType(this.node);
                string text = adaptor.GetNodeText(this.node);
                this.token = new CommonToken(type, text);
            }
        }
Example #5
0
        protected StringTemplate GetNodeST(ITreeAdaptor adaptor, object t)
        {
            string         text       = adaptor.GetNodeText(t);
            StringTemplate nodeST     = _nodeST.GetInstanceOf();
            string         uniqueName = "n" + GetNodeNumber(t);

            nodeST.SetAttribute("name", uniqueName);
            if (text != null)
            {
                text = text.Replace("\"", "\\\\\"");
            }
            nodeST.SetAttribute("text", text);
            return(nodeST);
        }
Example #6
0
        protected void ToDOTDefineEdges(object tree, ITreeAdaptor adaptor, StringTemplate treeST)
        {
            if ( tree == null )
            {
                return;
            }
            int n = adaptor.GetChildCount(tree);
            if ( n == 0 )
            {
                // must have already dumped as child from previous
                // invocation; do nothing
                return;
            }

            string parentName = "n" + GetNodeNumber(tree);

            // for each child, do a parent -> child edge using unique node names
            string parentText = adaptor.GetNodeText(tree);
            for (int i = 0; i < n; i++)
            {
                object child = adaptor.GetChild(tree, i);
                string childText = adaptor.GetNodeText(child);
                string childName = "n" + GetNodeNumber(child);
                StringTemplate edgeST = _edgeST.GetInstanceOf();
                edgeST.SetAttribute("parent", parentName);
                edgeST.SetAttribute("child", childName);
                edgeST.SetAttribute("parentText", parentText);
                edgeST.SetAttribute("childText", childText);
                treeST.SetAttribute("edges", edgeST);
                ToDOTDefineEdges(child, adaptor, treeST);
            }
        }
Example #7
0
 protected StringTemplate GetNodeST(ITreeAdaptor adaptor, object t)
 {
     string text = adaptor.GetNodeText(t);
     StringTemplate nodeST = _nodeST.GetInstanceOf();
     string uniqueName = "n" + GetNodeNumber(t);
     nodeST.SetAttribute("name", uniqueName);
     if (text != null)
         text = text.Replace("\"", "\\\\\"");
     nodeST.SetAttribute("text", text);
     return nodeST;
 }
Example #8
0
 public string GetNodeText(object t)
 {
     return(adaptor.GetNodeText(t));
 }
 public void Visit(object t, object parent, int childIndex, IDictionary labels)
 {
     list.Add(adaptor.GetNodeText(t)
              + "@" + ((parent != null) ? adaptor.GetNodeText(parent) : "nil")
              + "[" + childIndex + "]");
 }