using Microsoft.VisualBasic.CompilerServices; namespace AspClassic.Parser; /// /// Stores source code line and column information. /// public struct Location { private readonly int _Index; private readonly int _Line; private readonly int _Column; /// /// The index in the stream (0-based). /// public int Index => _Index; /// /// The physical line number (1-based). /// public int Line => _Line; /// /// The physical column number (1-based). /// public int Column => _Column; /// /// Whether the location is a valid location. /// public bool IsValid => Line != 0 && Column != 0; /// /// Constructs a new Location for a particular source location. /// /// The index in the stream (0-based). /// The physical line number (1-based). /// The physical column number (1-based). public Location(int index, int line, int column) { this = default(Location); _Index = index; _Line = line; _Column = column; } /// /// Compares two specified Location values to see if they are equal. /// /// One location to compare. /// The other location to compare. /// True if the locations are the same, False otherwise. public static bool operator ==(Location left, Location right) { return left.Index == right.Index; } /// /// Compares two specified Location values to see if they are not equal. /// /// One location to compare. /// The other location to compare. /// True if the locations are not the same, False otherwise. public static bool operator !=(Location left, Location right) { return left.Index != right.Index; } /// /// Compares two specified Location values to see if one is before the other. /// /// One location to compare. /// The other location to compare. /// True if the first location is before the other location, False otherwise. public static bool operator <(Location left, Location right) { return left.Index < right.Index; } /// /// Compares two specified Location values to see if one is after the other. /// /// One location to compare. /// The other location to compare. /// True if the first location is after the other location, False otherwise. public static bool operator >(Location left, Location right) { return left.Index > right.Index; } /// /// Compares two specified Location values to see if one is before or the same as the other. /// /// One location to compare. /// The other location to compare. /// True if the first location is before or the same as the other location, False otherwise. public static bool operator <=(Location left, Location right) { return left.Index <= right.Index; } /// /// Compares two specified Location values to see if one is after or the same as the other. /// /// One location to compare. /// The other location to compare. /// True if the first location is after or the same as the other location, False otherwise. public static bool operator >=(Location left, Location right) { return left.Index >= right.Index; } /// /// Compares two specified Location values. /// /// One location to compare. /// The other location to compare. /// 0 if the locations are equal, -1 if the left one is less than the right one, 1 otherwise. public static int Compare(Location left, Location right) { if (left == right) { return 0; } if (left < right) { return -1; } return 1; } public override string ToString() { return "(" + Conversions.ToString(Column) + "," + Conversions.ToString(Line) + ")"; } public override bool Equals(object obj) { if (obj is Location) { return this == (Location)obj; } return false; } public override int GetHashCode() { return checked((int)(Index & 0xFFFFFFFFu)); } }