package sterling.lang.compiler;

import java.util.Objects;

public class Position {

    private final String source;
    private final int line;
    private final int column;

    public Position(String source, int line, int column) {
        this.source = source;
        this.line = line + 1;
        this.column = column + 1;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (o instanceof Position) {
            Position other = (Position) o;
            return Objects.equals(source, other.source)
                && line == other.line
                && column == other.column;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return Objects.hash(source, line, column);
    }

    @Override
    public String toString() {
        return "'" + source + "' (" + line + ", " + column + ")";
    }
}
