using System; namespace Sprache { /// /// Represents a position in the input. /// public class Position : IEquatable { /// /// Initializes a new instance of the class. /// /// The position. /// The line number. /// The column. public Position(int pos, int line, int column) { Pos = pos; Line = line; Column = column; } /// /// Creates an new instance from a given object. /// /// The current input. /// A new instance. public static Position FromInput(IInput input) { return new Position(input.Position, input.Line, input.Column); } /// /// Gets the current positon. /// public int Pos { get; private set; } /// /// Gets the current line number. /// public int Line { get; private set; } /// /// Gets the current column. /// public int Column { get; private set; } /// /// Determines whether the specified is equal to the current . /// /// /// true if the specified is equal to the current ; otherwise, false. /// /// The object to compare with the current object. public override bool Equals(object obj) { return Equals(obj as Position); } /// /// Indicates whether the current is equal to another object of the same type. /// /// /// true if the current object is equal to the parameter; otherwise, false. /// /// An object to compare with this object. public bool Equals(Position other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Pos == other.Pos && Line == other.Line && Column == other.Column; } /// /// Indicates whether the left is equal to the right . /// /// The left . /// The right . /// true if both objects are equal. public static bool operator ==(Position left, Position right) { return Equals(left, right); } /// /// Indicates whether the left is not equal to the right . /// /// The left . /// The right . /// true if the objects are not equal. public static bool operator !=(Position left, Position right) { return !Equals(left, right); } /// /// Serves as a hash function for a particular type. /// /// /// A hash code for the current . /// public override int GetHashCode() { var h = 31; h = h * 13 + Pos; h = h * 13 + Line; h = h * 13 + Column; return h; } /// /// Returns a string that represents the current object. /// /// /// A string that represents the current object. /// public override string ToString() { return string.Format("Line {0}, Column {1}", Line, Column); } } }