https://github.com/tpolecat/sourcepos
Micro-library that provides source file name and line number.
https://github.com/tpolecat/sourcepos
Last synced: over 1 year ago
JSON representation
Micro-library that provides source file name and line number.
- Host: GitHub
- URL: https://github.com/tpolecat/sourcepos
- Owner: tpolecat
- License: mit
- Created: 2021-01-04T21:03:10.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2022-11-21T19:32:12.000Z (over 3 years ago)
- Last Synced: 2025-03-20T15:58:13.710Z (over 1 year ago)
- Language: Scala
- Size: 26.4 KB
- Stars: 33
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SourcePos
This is a Scala micro-library that provides:
- a `SourcePos` class that specifies a source file and line number, and
- an implicit macro that forges a `SourcePos` at the call site if none is available.
SourcePos is compiled for Scala **2.12**, **2.13**, and **3.0** (see release notes for exact versions).
```scala
libraryDependencies += "org.tpolecat" %% "sourcepos" %
```
#### Example
If you want to know where a method call originated, demand an implicit `SourcePos`. It has fields for both `file` and `line`, and a `toString` that prints them as `:`, which most editors will hyperlink for you.
```scala
import org.tpolecat.sourcepos._
object Example {
def method(n: Int)(implicit sp: SourcePos): String =
s"You called me with $n from $sp"
def main(args: Array[String]): Unit =
println(method(42))
}
```
Running this program on my computer yields:
```
You called me with 42 from /Users/rnorris/Scala/SourcePos/src/test/scala/Example.scala:9
```