|
using System;
namespace CodeDomExpParser
{
/// <summary>
/// Represents a token that is parsed out by the <see cref="Tokenizer"/>.
/// </summary>
public sealed class Token
{
private string _Text;
private object _ParsedObject;
private TokenType _Type;
private TokenPriority _Priority;
/// <summary>
/// The text that makes up the token.
/// </summary>
public string Text
{
get { return _Text; }
//set { _Text = value; }
}
/// <summary>
/// If the token can be parsed into a type like an integer, this property holds that value.
/// </summary>
public object ParsedObject
{
get { return _ParsedObject; }
//set { _ParsedObject = value; }
}
/// <summary>
/// Token type
/// </summary>
public TokenType Type
{
get { return _Type; }
//set { _Type = value; }
}
/// <summary>
/// Token priority
/// </summary>
public TokenPriority Priority
{
get { return _Priority; }
//set { _Priority = value; }
}
/// <summary>
/// Constructor for tokens that are not parsed.
/// </summary>
/// <param name="text"></param>
/// <param name="type"></param>
/// <param name="priority"></param>
public Token(string text, TokenType type, TokenPriority priority)
{
_Text = text;
_Type = type;
_Priority = priority;
_ParsedObject = text;
}
/// <summary>
/// Constructor for tokens that are parsed.
/// </summary>
/// <param name="parsedObj"></param>
/// <param name="type"></param>
/// <param name="priority"></param>
public Token(object parsedObj, TokenType type, TokenPriority priority)
{
_ParsedObject = parsedObj;
_Text = ParsedObject.ToString();
_Type = type;
_Priority = priority;
}
/// <summary>
/// The null token represents a state where the <see cref="Tokenizer"/> encountered an error
/// or has not begun parsing yet.
/// </summary>
public readonly static Token NullToken = new Token("", TokenType.NotAToken, TokenPriority.None);
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.