-
Notifications
You must be signed in to change notification settings - Fork 352
/
pos.scala
36 lines (25 loc) · 831 Bytes
/
pos.scala
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
// Copyright (c) 2013-2018 Rob Norris and Contributors
// This software is licensed under the MIT License (MIT).
// For more information see LICENSE or https://opensource.org/licenses/MIT
package doobie.util
import cats.instances.int._
import cats.instances.string._
import cats.syntax.show._
/** Module for source positions. */
object pos {
/** A source position. */
final case class Pos(path: String, line: Int) {
def file: String =
path.lastIndexOf(java.io.File.separatorChar.toString) match {
case -1 => path
case n => path.substring(n + 1)
}
override def toString =
show"$file:$line"
}
object Pos {
/** A `Pos` can be forged on demand. */
implicit def sourcePos(implicit ef: sourcecode.File, el: sourcecode.Line): Pos =
Pos(ef.value, el.value)
}
}