token.cs

来自「csharp-solution,C#高效编程源码」· CS 代码 · 共 54 行

CS
54
字号

namespace CSharp
{
    /// <summary>
    /// Token provides a common abstract base class for 
    /// the concrete token implementation classes. It is 
    /// intended to be used in conjunction with a specific 
    /// token interface. For example, to implement string 
    /// literal tokens you would do this:
    /// <code>
    /// interface IStringLiteralToken : IToken {}
    /// class StringLiteralToken : Token, IStringLiteralToken
    /// { 
    /// ...
    /// }
    /// </code>
    /// </summary>
    
    internal abstract class Token : IToken
    {
        /// <param name="begin">begin</param>
        /// <param name="end">end</param>
        /// <remarks>
        /// It would be useful to check if
        /// (<paramref name="begin">begin</paramref> ==
        /// <paramref name="end">end</paramref>)
        /// and throw an exception if so.
        /// </remarks>

        protected Token(Position begin, Position end)
        {
            this.begin = begin;
            this.end = end;
        }
    
        public override string ToString()
        {
            return Position.MakeString(begin, end);
        }

        /// <remarks>
        /// Note that Accept is added to the internal
        /// implementation hierarchy and not to the 
        /// public interface hierarchy. That is, Accept
        /// is method of Token but not of IToken.
        /// </remarks>
        
        internal abstract void Accept(ITokenVisitor visitor);
                
        private readonly Position begin, end;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?