50 lines
924 B
C#
50 lines
924 B
C#
|
namespace CanonSharp.Common.LexicalAnalyzer;
|
|||
|
|
|||
|
public class EmptyChar : IEquatable<EmptyChar>
|
|||
|
{
|
|||
|
public bool IsEmpty { get; }
|
|||
|
|
|||
|
public char Char { get; }
|
|||
|
|
|||
|
public static EmptyChar Empty => new();
|
|||
|
|
|||
|
private EmptyChar()
|
|||
|
{
|
|||
|
IsEmpty = true;
|
|||
|
Char = char.MaxValue;
|
|||
|
}
|
|||
|
|
|||
|
public EmptyChar(char c)
|
|||
|
{
|
|||
|
IsEmpty = false;
|
|||
|
Char = c;
|
|||
|
}
|
|||
|
|
|||
|
public bool Equals(EmptyChar? other)
|
|||
|
{
|
|||
|
if (other is null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
if (IsEmpty)
|
|||
|
{
|
|||
|
return other.IsEmpty;
|
|||
|
}
|
|||
|
|
|||
|
return Char == other.Char;
|
|||
|
}
|
|||
|
|
|||
|
public override bool Equals(object? obj) => obj is EmptyChar other && Equals(other);
|
|||
|
|
|||
|
public override int GetHashCode()
|
|||
|
{
|
|||
|
return IsEmpty.GetHashCode() ^ Char.GetHashCode();
|
|||
|
}
|
|||
|
|
|||
|
public override string ToString()
|
|||
|
{
|
|||
|
return IsEmpty ? "ε" : Char.ToString();
|
|||
|
}
|
|||
|
}
|