Skip to content

Commit c1ffc4b

Browse files
authored
Fix some minor issues before 0.3.5 (#305)
1 parent af1bc74 commit c1ffc4b

3 files changed

Lines changed: 13 additions & 15 deletions

File tree

core/shared/src/main/scala/cats/parse/Caret.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ package cats.parse
2323

2424
import cats.Order
2525

26-
/** This is a pointer to a zero based row, column, and total offset.
26+
/** This is a pointer to a zero based line, column, and total offset.
2727
*/
28-
case class Caret(row: Int, col: Int, offset: Int)
28+
case class Caret(line: Int, col: Int, offset: Int)
2929

3030
object Caret {
3131
val Start: Caret = Caret(0, 0, 0)
3232

3333
implicit val caretOrder: Order[Caret] =
3434
new Order[Caret] {
3535
def compare(left: Caret, right: Caret): Int = {
36-
val c0 = Integer.compare(left.row, right.row)
36+
val c0 = Integer.compare(left.line, right.line)
3737
if (c0 != 0) c0
3838
else {
3939
val c1 = Integer.compare(left.col, right.col)

core/shared/src/main/scala/cats/parse/LocationMap.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class LocationMap(val input: String) {
6969
*/
7070
def toLineCol(offset: Int): Option[(Int, Int)] =
7171
if (isValidOffset(offset)) {
72-
val Caret(_, row, col) = toCaretUnsafeImpl(offset)
73-
Some((row, col))
72+
val Caret(_, line, col) = toCaretUnsafeImpl(offset)
73+
Some((line, col))
7474
} else None
7575

7676
// This does not do bounds checking because we
@@ -94,20 +94,18 @@ class LocationMap(val input: String) {
9494
// the key, or a.length if all elements in the array are less than the specified key.
9595
//
9696
// so insertion pos = ~(idx + 1)
97-
val row = ~(idx + 1)
98-
// so we are pointing into a row
99-
val rowStart = firstPos(row)
100-
val col = offset - rowStart
101-
Caret(offset, row, col)
97+
val line = ~(idx + 1)
98+
// so we are pointing into a line
99+
val lineStart = firstPos(line)
100+
val col = offset - lineStart
101+
Caret(offset, line, col)
102102
} else {
103103
// idx is exactly the right value because offset is beginning of a line
104104
Caret(offset, idx, 0)
105105
}
106106
}
107107

108-
/** Convert an offset to a Caret.
109-
* @throws IllegalArgumentException
110-
* if offset is longer than input
108+
/** Convert an offset to a Caret. throws IllegalArgumentException if offset is longer than input
111109
*/
112110
def toCaretUnsafe(offset: Int): Caret =
113111
if (isValidOffset(offset)) toCaretUnsafeImpl(offset)
@@ -123,7 +121,7 @@ class LocationMap(val input: String) {
123121
if (i >= 0 && i < lines.length) Some(lines(i))
124122
else None
125123

126-
/** Return the offset for a given row/col. if we return Some(input.length) this means EOF if we
124+
/** Return the offset for a given line/col. if we return Some(input.length) this means EOF if we
127125
* return Some(i) for 0 <= i < input.length it is a valid item else offset < 0 or offset >
128126
* input.length we return None
129127
*/

core/shared/src/test/scala/cats/parse/ParserTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object ParserGen {
7272

7373
implicit val cogenCaret: Cogen[Caret] =
7474
Cogen { caret: Caret =>
75-
(caret.offset.toLong << 32) | (caret.col.toLong << 16) | (caret.row.toLong)
75+
(caret.offset.toLong << 32) | (caret.col.toLong << 16) | (caret.line.toLong)
7676
}
7777

7878
def arbGen[A: Arbitrary: Cogen]: GenT[Gen] =

0 commit comments

Comments
 (0)