using System;
using System.Collections.Generic;
namespace AspClassic.Parser;
///
/// A punctuation token.
///
public sealed class PunctuatorToken : Token
{
private static Dictionary PunctuatorTable;
private static void AddPunctuator(Dictionary table, string punctuator, TokenType type)
{
table.Add(punctuator, type);
table.Add(Scanner.MakeFullWidth(punctuator), type);
}
internal static TokenType TokenTypeFromString(string s)
{
if (PunctuatorTable == null)
{
Dictionary Table = new Dictionary(StringComparer.InvariantCulture);
AddPunctuator(Table, "(", TokenType.LeftParenthesis);
AddPunctuator(Table, ")", TokenType.RightParenthesis);
AddPunctuator(Table, "{", TokenType.LeftCurlyBrace);
AddPunctuator(Table, "}", TokenType.RightCurlyBrace);
AddPunctuator(Table, "!", TokenType.Exclamation);
AddPunctuator(Table, "#", TokenType.Pound);
AddPunctuator(Table, ",", TokenType.Comma);
AddPunctuator(Table, ".", TokenType.Period);
AddPunctuator(Table, ":", TokenType.Colon);
AddPunctuator(Table, ":=", TokenType.ColonEquals);
AddPunctuator(Table, "&", TokenType.Ampersand);
AddPunctuator(Table, "&=", TokenType.AmpersandEquals);
AddPunctuator(Table, "*", TokenType.Star);
AddPunctuator(Table, "*=", TokenType.StarEquals);
AddPunctuator(Table, "+", TokenType.Plus);
AddPunctuator(Table, "+=", TokenType.PlusEquals);
AddPunctuator(Table, "-", TokenType.Minus);
AddPunctuator(Table, "-=", TokenType.MinusEquals);
AddPunctuator(Table, "/", TokenType.ForwardSlash);
AddPunctuator(Table, "/=", TokenType.ForwardSlashEquals);
AddPunctuator(Table, "\\", TokenType.BackwardSlash);
AddPunctuator(Table, "\\=", TokenType.BackwardSlashEquals);
AddPunctuator(Table, "^", TokenType.Caret);
AddPunctuator(Table, "^=", TokenType.CaretEquals);
AddPunctuator(Table, "<", TokenType.LessThan);
AddPunctuator(Table, "<=", TokenType.LessThanEquals);
AddPunctuator(Table, "=<", TokenType.LessThanEquals);
AddPunctuator(Table, "=", TokenType.Equals);
AddPunctuator(Table, "<>", TokenType.NotEquals);
AddPunctuator(Table, ">", TokenType.GreaterThan);
AddPunctuator(Table, ">=", TokenType.GreaterThanEquals);
AddPunctuator(Table, "=>", TokenType.GreaterThanEquals);
AddPunctuator(Table, "<<", TokenType.LessThanLessThan);
AddPunctuator(Table, "<<=", TokenType.LessThanLessThanEquals);
AddPunctuator(Table, ">>", TokenType.GreaterThanGreaterThan);
AddPunctuator(Table, ">>=", TokenType.GreaterThanGreaterThanEquals);
PunctuatorTable = Table;
}
if (!PunctuatorTable.ContainsKey(s))
{
return TokenType.None;
}
return PunctuatorTable[s];
}
///
/// Constructs a new punctuator token.
///
/// The punctuator token type.
/// The location of the punctuator.
public PunctuatorToken(TokenType type, Span span)
: base(type, span)
{
if (type < TokenType.LeftParenthesis || type > TokenType.GreaterThanGreaterThanEquals)
{
throw new ArgumentOutOfRangeException("type");
}
}
}