Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        protected internal void SerializeNode(StringBuilder buf, object t)
        {
            int    ID   = adaptor.GetUniqueID(t);
            string text = adaptor.GetNodeText(t);
            int    type = adaptor.GetNodeType(t);

            buf.Append("\t");
            buf.Append(ID);
            buf.Append("\t");
            buf.Append(type);
            IToken token = adaptor.GetToken(t);
            int    line  = -1;
            int    pos   = -1;

            if (token != null)
            {
                line = token.Line;
                pos  = token.CharPositionInLine;
            }
            buf.Append("\t");
            buf.Append(line);
            buf.Append("\t");
            buf.Append(pos);
            int tokenIndex = adaptor.GetTokenStartIndex(t);

            buf.Append("\t");
            buf.Append(tokenIndex);
            SerializeText(buf, text);
        }
Exemplo n.º 3
0
 public virtual IToken GetToken(object t)
 {
     return(adaptor.GetToken(t));
 }
Exemplo n.º 4
0
 public IToken GetToken(object treeNode)
 {
     return(adaptor.GetToken(treeNode));
 }