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

53 lines
1.6 KiB
C#

using System;
namespace AspClassic.Parser;
/// <summary>
/// An integer literal.
/// </summary>
public sealed class IntegerLiteralToken : Token
{
private readonly int _Literal;
private readonly TypeCharacter _TypeCharacter;
private readonly IntegerBase _IntegerBase;
/// <summary>
/// The value of the literal.
/// </summary>
public int Literal => _Literal;
/// <summary>
/// The type character of the literal.
/// </summary>
public TypeCharacter TypeCharacter => _TypeCharacter;
/// <summary>
/// The integer base of the literal.
/// </summary>
public IntegerBase IntegerBase => _IntegerBase;
/// <summary>
/// Constructs a new integer literal.
/// </summary>
/// <param name="literal">The literal value.</param>
/// <param name="integerBase">The integer base of the literal.</param>
/// <param name="typeCharacter">The type character of the literal.</param>
/// <param name="span">The location of the literal.</param>
public IntegerLiteralToken(int literal, IntegerBase integerBase, TypeCharacter typeCharacter, Span span)
: base(TokenType.IntegerLiteral, span)
{
if (integerBase < IntegerBase.Decimal || integerBase > IntegerBase.Hexadecimal)
{
throw new ArgumentOutOfRangeException("integerBase");
}
if (typeCharacter != 0 && typeCharacter != TypeCharacter.IntegerSymbol && typeCharacter != TypeCharacter.IntegerChar && typeCharacter != TypeCharacter.ShortChar && typeCharacter != TypeCharacter.LongSymbol && typeCharacter != TypeCharacter.LongChar)
{
throw new ArgumentOutOfRangeException("typeCharacter");
}
_Literal = literal;
_IntegerBase = integerBase;
_TypeCharacter = typeCharacter;
}
}