aspclassic-core/AspClassic.Parser/Token.cs
Jelle Luteijn 484dbfc9d9 progress
2022-05-15 11:19:49 +02:00

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;
}
}