Skip to content

Micro-library that provides source file name and line number.

License

Notifications You must be signed in to change notification settings

tpolecat/SourcePos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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).

libraryDependencies += "org.tpolecat" %% "sourcepos" % <version>

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 <file>:<line>, which most editors will hyperlink for you.

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

About

Micro-library that provides source file name and line number.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages