-
Notifications
You must be signed in to change notification settings - Fork 1
/
Position.cs
59 lines (50 loc) · 1.51 KB
/
Position.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace Lexepars
{
using System;
/// <summary>
/// Represents a position in the input text.
/// </summary>
public struct Position : IEquatable<Position>
{
/// <summary>
/// Line number.
/// </summary>
public int Line { get; }
/// <summary>
/// Column number.
/// </summary>
public int Column { get; }
/// <summary>
/// Creates a new instance of <see cref="Position"/>.
/// </summary>
/// <param name="line"></param>
/// <param name="column"></param>
public Position(int line, int column)
{
Line = line;
Column = column;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{
switch (obj)
{
case Position p:
return this == p;
default:
return false;
}
}
/// <inheritdoc/>
public bool Equals(Position other) => this == other;
/// <inheritdoc/>
public override int GetHashCode() => Line ^ Column;
public static bool operator ==(Position a, Position b) => a.Column == b.Column && a.Line == b.Line;
public static bool operator !=(Position a, Position b) => !(a == b);
/// <summary>
/// Return the line and column numbers.
/// </summary>
/// <returns></returns>
public override string ToString() => $"({Line}, {Column})";
}
}