41 lines
905 B
C#
41 lines
905 B
C#
#define DEBUG
|
|
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace AspClassic.Parser;
|
|
|
|
/// <summary>
|
|
/// The base class for all tokens. Contains line and column information as well as token type.
|
|
/// </summary>
|
|
public abstract class Token
|
|
{
|
|
private readonly TokenType _Type;
|
|
|
|
private readonly Span _Span;
|
|
|
|
/// <summary>
|
|
/// The type of the token.
|
|
/// </summary>
|
|
public TokenType Type => _Type;
|
|
|
|
/// <summary>
|
|
/// The span of the token in the source text.
|
|
/// </summary>
|
|
public Span Span => _Span;
|
|
|
|
protected Token(TokenType type, Span span)
|
|
{
|
|
Debug.Assert(Enum.IsDefined(typeof(TokenType), type));
|
|
_Type = type;
|
|
_Span = span;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the unreserved keyword type of an identifier.
|
|
/// </summary>
|
|
/// <returns>The unreserved keyword type of an identifier, the token's type otherwise.</returns>
|
|
public virtual TokenType AsUnreservedKeyword()
|
|
{
|
|
return Type;
|
|
}
|
|
}
|