using System;
namespace AspClassic.Parser;
///
/// A parse tree for a simple name (e.g. 'foo').
///
public sealed class SimpleName : Name
{
private readonly string _Name;
private readonly TypeCharacter _TypeCharacter;
private readonly bool _Escaped;
///
/// The name, if any.
///
public string Name => _Name;
///
/// The type character.
///
public TypeCharacter TypeCharacter => _TypeCharacter;
///
/// Whether the name is escaped.
///
public bool Escaped => _Escaped;
public override bool IsBad => Name == null;
///
/// Creates a bad simple name.
///
/// The location of the parse tree.
/// A bad simple name.
public static SimpleName GetBadSimpleName(Span span)
{
return new SimpleName(span);
}
///
/// Constructs a new simple name parse tree.
///
/// The name, if any.
/// The type character.
/// Whether the name is escaped.
/// The location of the parse tree.
public SimpleName(string name, TypeCharacter typeCharacter, bool escaped, Span span)
: base(TreeType.SimpleName, span)
{
if (typeCharacter != 0 && escaped)
{
throw new ArgumentException("Escaped named cannot have type characters.");
}
if (typeCharacter != 0 && typeCharacter != TypeCharacter.DecimalSymbol && typeCharacter != TypeCharacter.DoubleSymbol && typeCharacter != TypeCharacter.IntegerSymbol && typeCharacter != TypeCharacter.LongSymbol && typeCharacter != TypeCharacter.SingleSymbol && typeCharacter != TypeCharacter.StringSymbol)
{
throw new ArgumentOutOfRangeException("typeCharacter");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
_Name = name;
_TypeCharacter = typeCharacter;
_Escaped = escaped;
}
private SimpleName(Span span)
: base(TreeType.SimpleName, span)
{
}
}