using System; namespace Confuser.Core.Project { /// /// The type of pattern tokens /// public enum TokenType { /// /// An identifier, could be functions/operators. /// Identifier, /// /// A string literal. /// Literal, /// /// A left parenthesis. /// LParens, /// /// A right parenthesis. /// RParens, /// /// A comma. /// Comma } /// /// Represent a token in pattern /// public struct PatternToken { /// /// The position of this token in the pattern, or null if position not available. /// public readonly int? Position; /// /// The type of this token. /// public readonly TokenType Type; /// /// The value of this token, applicable to identifiers and literals. /// public readonly string Value; /// /// Initializes a new instance of the struct. /// /// The position of token. /// The type of token. public PatternToken(int pos, TokenType type) { Position = pos; Type = type; Value = null; } /// /// Initializes a new instance of the struct. /// /// The position of token. /// The type of token. /// The value of token. public PatternToken(int pos, TokenType type, string value) { Position = pos; Type = type; Value = value; } /// /// Initializes a new instance of the struct. /// /// The type of token. public PatternToken(TokenType type) { Position = null; Type = type; Value = null; } /// /// Initializes a new instance of the struct. /// /// The type of token. /// The value of token. public PatternToken(TokenType type, string value) { Position = null; Type = type; Value = value; } /// public override string ToString() { if (Position != null) { if (Value != null) return string.Format("[{0}] {1} @ {2}", Type, Value, Position); return string.Format("[{0}] @ {1}", Type, Position); } if (Value != null) return string.Format("[{0}] {1}", Type, Value); return string.Format("[{0}]", Type); } } }