Example #1
0
        protected virtual void ExtractInformationFromTreeNodeStream(IIntStream input)
        {
            ITokenStreamInformation streamInformation = input as ITokenStreamInformation;

            if (streamInformation != null)
            {
                IToken lastToken     = streamInformation.LastToken;
                IToken lastRealToken = streamInformation.LastRealToken;
                if (lastRealToken != null)
                {
                    this._token = lastRealToken;
                    this._line  = lastRealToken.Line;
                    this._charPositionInLine  = lastRealToken.CharPositionInLine;
                    this._approximateLineInfo = lastRealToken.Equals(lastToken);
                }
            }
            else
            {
                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 Tree.ITree)
                {
                    this._line = ((Tree.ITree) this._node).Line;
                    this._charPositionInLine = ((Tree.ITree) this._node).CharPositionInLine;
                    if (this._node is CommonTree)
                    {
                        this._token = ((CommonTree)this._node).Token;
                    }
                }
                else
                {
                    int    type = adaptor.GetType(this._node);
                    string text = adaptor.GetText(this._node);
                    this._token = new CommonToken(type, text);
                }
            }
        }
Example #2
0
        protected virtual void ExtractInformationFromTreeNodeStream(ITreeNodeStream input)
        {
            this._node = input.LT(1);

            object positionNode = null;
            IPositionTrackingStream positionTrackingStream = input as IPositionTrackingStream;

            if (positionTrackingStream != null)
            {
                positionNode = positionTrackingStream.GetKnownPositionElement(false);
                if (positionNode == null)
                {
                    positionNode = positionTrackingStream.GetKnownPositionElement(true);
                    this._approximateLineInfo = positionNode != null;
                }
            }

            ITokenStreamInformation streamInformation = input as ITokenStreamInformation;

            if (streamInformation != null)
            {
                IToken lastToken     = streamInformation.LastToken;
                IToken lastRealToken = streamInformation.LastRealToken;
                if (lastRealToken != null)
                {
                    this._token = lastRealToken;
                    this._line  = lastRealToken.Line;
                    this._charPositionInLine  = lastRealToken.CharPositionInLine;
                    this._approximateLineInfo = lastRealToken.Equals(lastToken);
                }
            }
            else
            {
                ITreeAdaptor adaptor = input.TreeAdaptor;
                IToken       payload = adaptor.GetToken(positionNode ?? _node);
                if (payload != null)
                {
                    this._token = payload;
                    if (payload.Line <= 0)
                    {
                        // imaginary node; no line/pos info; scan backwards
                        int    i         = -1;
                        object priorNode = input.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;
                            try
                            {
                                priorNode = input.LT(i);
                            }
                            catch (NotSupportedException)
                            {
                                priorNode = null;
                            }
                        }
                    }
                    else
                    {
                        // node created from real token
                        this._line = payload.Line;
                        this._charPositionInLine = payload.CharPositionInLine;
                    }
                }
                else if (this._node is Tree.ITree)
                {
                    this._line = ((Tree.ITree) this._node).Line;
                    this._charPositionInLine = ((Tree.ITree) this._node).CharPositionInLine;
                    if (this._node is CommonTree)
                    {
                        this._token = ((CommonTree)this._node).Token;
                    }
                }
                else
                {
                    int    type = adaptor.GetType(this._node);
                    string text = adaptor.GetText(this._node);
                    this._token = new CommonToken(type, text);
                }
            }
        }
        protected virtual void ExtractInformationFromTreeNodeStream(IIntStream input)
        {
            ITokenStreamInformation tokenStreamInformation = input as ITokenStreamInformation;

            if (tokenStreamInformation != null)
            {
                IToken lastToken     = tokenStreamInformation.LastToken;
                IToken lastRealToken = tokenStreamInformation.LastRealToken;
                if (lastRealToken != null)
                {
                    this._token = lastRealToken;
                    this._line  = lastRealToken.Line;
                    this._charPositionInLine  = lastRealToken.CharPositionInLine;
                    this._approximateLineInfo = lastRealToken.Equals(lastToken);
                }
            }
            else
            {
                ITreeNodeStream treeNodeStream = (ITreeNodeStream)input;
                this._node = treeNodeStream.LT(1);
                ITreeAdaptor treeAdaptor = treeNodeStream.TreeAdaptor;
                IToken       token       = treeAdaptor.GetToken(this._node);
                if (token != null)
                {
                    this._token = token;
                    if (token.Line <= 0)
                    {
                        int    num = -1;
                        object obj = treeNodeStream.LT(num);
                        IToken token2;
                        while (true)
                        {
                            if (obj != null)
                            {
                                token2 = treeAdaptor.GetToken(obj);
                                if (token2 != null && token2.Line > 0)
                                {
                                    break;
                                }
                                num--;
                                obj = treeNodeStream.LT(num);
                                continue;
                            }
                            return;
                        }
                        this._line = token2.Line;
                        this._charPositionInLine  = token2.CharPositionInLine;
                        this._approximateLineInfo = true;
                    }
                    else
                    {
                        this._line = token.Line;
                        this._charPositionInLine = token.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 = treeAdaptor.GetType(this._node);
                    string text = treeAdaptor.GetText(this._node);
                    this._token = new CommonToken(type, text);
                }
            }
        }
Example #4
0
        protected virtual void ExtractInformationFromTreeNodeStream(ITreeNodeStream input)
        {
            this._node = input.LT(1);
            ITokenStreamInformation streamInformation = input as ITokenStreamInformation;

            if (streamInformation != null)
            {
                IToken lastToken     = streamInformation.LastToken;
                IToken lastRealToken = streamInformation.LastRealToken;
                if (lastRealToken == null)
                {
                    return;
                }
                this._token = lastRealToken;
                this._line  = lastRealToken.Line;
                this._charPositionInLine  = lastRealToken.CharPositionInLine;
                this._approximateLineInfo = lastRealToken.Equals((object)lastToken);
            }
            else
            {
                ITreeAdaptor treeAdaptor = input.TreeAdaptor;
                IToken       token1      = treeAdaptor.GetToken(this._node);
                if (token1 != null)
                {
                    this._token = token1;
                    if (token1.Line <= 0)
                    {
                        int    k = -1;
                        object t = input.LT(k);
                        while (t != null)
                        {
                            IToken token2 = treeAdaptor.GetToken(t);
                            if (token2 != null && token2.Line > 0)
                            {
                                this._line = token2.Line;
                                this._charPositionInLine  = token2.CharPositionInLine;
                                this._approximateLineInfo = true;
                                break;
                            }
                            --k;
                            try
                            {
                                t = input.LT(k);
                            }
                            catch (ArgumentException ex)
                            {
                                t = (object)null;
                            }
                        }
                    }
                    else
                    {
                        this._line = token1.Line;
                        this._charPositionInLine = token1.CharPositionInLine;
                    }
                }
                else if (this._node is ITree)
                {
                    this._line = ((ITree)this._node).Line;
                    this._charPositionInLine = ((ITree)this._node).CharPositionInLine;
                    if (!(this._node is CommonTree))
                    {
                        return;
                    }
                    this._token = ((CommonTree)this._node).Token;
                }
                else
                {
                    this._token = (IToken) new CommonToken(treeAdaptor.GetType(this._node), treeAdaptor.GetText(this._node));
                }
            }
        }