@@ -2,8 +2,8 @@ SourceCode [
2121```
2222
2323This might not be something you want to use for "business logic", but is very
24- helpful for things like [ debugging] ( #debug-prints ) , [ logging] ( #logging ) or
25- providing automatic diagnostics for [ DSLs] ( #embedding-domain-specific-languages ) .
24+ helpful for things like [ debugging] ( #debug-prints ) , [ logging] ( #logging ) or
25+ providing automatic diagnostics for [ DSLs] ( #embedding-domain-specific-languages ) .
2626This information is also available via an ` implicit ` , letting you write functions
27- that automatically pull it in.
27+ that automatically pull it in.
2828
2929Using SourceCode on code dealing with lots of anonymous functions or anonymous
3030classes can easily turn what you see in your debug printouts from this:
@@ -35,10 +35,10 @@ To this:
3535
3636![ After] ( docs/After.png )
3737
38- By capturing source information you can use to give your objects and function
39- meaningful names that tell you where they were defined, automatically without
40- needing you to manually assign a string-ID to every anonymous function or
41- anonymous class you define all over your code bas.
38+ By capturing source information you can use to give your objects and function
39+ meaningful names that tell you where they were defined, automatically without
40+ needing you to manually assign a string-ID to every anonymous function or
41+ anonymous class you define all over your code bas.
4242
4343If you like using Sourcecode, you might also enjoy this book by the author which
4444teaches you Scala in a similarly simple and straightforward way:
@@ -74,14 +74,14 @@ The kinds of compilation-time data that `sourcecode` provides are:
7474- ` sourcecode.Enclosing ` : the name of the nearest enclosing definition: ` val ` ,
7575 ` class ` , whatever, prefixed by the names of all enclosing ` class ` s, ` trait ` s,
7676 ` object ` s or ` package ` s, ` def ` s, ` val ` s, ` var ` s or ` lazy val ` s`
77- - ` sourcecode.Text[T] ` : when you want to take a value of type ` T ` , but also
78- want to get the "source text" of that particular value. Note that if
79- you have multiple statements in a ` {} ` block, ` sourcecode.Text ` will only
77+ - ` sourcecode.Text[T] ` : when you want to take a value of type ` T ` , but also
78+ want to get the "source text" of that particular value. Note that if
79+ you have multiple statements in a ` {} ` block, ` sourcecode.Text ` will only
8080 capture the source code for the last expression that gets returned. This
8181 implicit is slightly experimental; be sure to report any bugs you find!
82- - ` sourcecode.Args ` : the arguments that where provided to the nearest enclosing
82+ - ` sourcecode.Args ` : the arguments that where provided to the nearest enclosing
8383 method
84- - ` sourcecode.Name.Machine ` , ` sourcecode.FullName.Machine ` and
84+ - ` sourcecode.Name.Machine ` , ` sourcecode.FullName.Machine ` and
8585 ` sourcecode.Enclosing.Machine ` which are similar to ` sourcecode.Name ` ,
8686 ` sourcecode.FullName ` and ` sourcecode.Enclosing ` except they do not filter
8787 out synthetic method names; e.g. if you want to see the ` <init> ` names or
@@ -110,7 +110,7 @@ can't be used.
110110Examples
111111========
112112
113- Here are a few examples of ` sourcecode ` 's core functions being used in a
113+ Here are a few examples of ` sourcecode ` 's core functions being used in a
114114variety of contexts. Hopefully they will give you an idea of how the various
115115implicits behave:
116116
@@ -170,8 +170,8 @@ object Implicits {
170170}
171171```
172172
173- Note that in "normal" usage you would not directly call ` implicitly ` to summon
174- up ` sourcecode ` values; rather, you would add implicit parameters of these
173+ Note that in "normal" usage you would not directly call ` implicitly ` to summon
174+ up ` sourcecode ` values; rather, you would add implicit parameters of these
175175types to your functions. That would make these values automatically available
176176to your functions without needing to manually keep passing them in. Apart from
177177summoning them via implicits, you can also use the ` apply ` method on each type
@@ -233,7 +233,7 @@ object Implicits {
233233}
234234```
235235
236- By default, the various implicits all ignore any synthetic ` <init> ` ,
236+ By default, the various implicits all ignore any synthetic ` <init> ` ,
237237` <local Foo> ` or ` $anonfun ` methods that might be present:
238238
239239``` scala
@@ -284,10 +284,10 @@ object Synthetic {
284284```
285285
286286Hopefully this has given you a reasonable feel for * what** sourcecode does. You
287- may still be wondering * why* we would want any of this: what could we possibly
288- use these things for? Why would we want to write code that depends on our
287+ may still be wondering * why* we would want any of this: what could we possibly
288+ use these things for? Why would we want to write code that depends on our
289289package paths or variable names? The section below will provide use cases that
290- you will hopefully be able to relate to.
290+ you will hopefully be able to relate to.
291291
292292Use Cases
293293=========
@@ -318,7 +318,7 @@ This can be handy for letting you see where the log lines are coming from,
318318without tediously tagging every log statement with a unique prefix.
319319Furthermore, this happens at compile time, and is thus orders of magnitude
320320faster than getting this information by generating stack traces, and works
321- on Scala.js where stack-inspection does not. Lastly, if you want additional
321+ on Scala.js where stack-inspection does not. Lastly, if you want additional
322322information such as method names, class names, or packages to be provided to
323323your logging function, you can easily do so by asking for the ` sourcecode.Name `
324324or ` sourcecode.FullName ` or ` sourcecode.Pkg ` implicits.
@@ -362,7 +362,7 @@ named enums (or even an enum of the same name in a different package!) are
362362given unique names. In that case, you can use ` sourcecode.FullName ` or
363363` sourcecode.Enclosing ` to capture the full path e.g.
364364` "com.mypkg.MyEnum.firstItem" ` and ` "com.mypkg.MyEnum.secondItem" ` :
365-
365+
366366``` scala
367367package sourcecode
368368
@@ -383,7 +383,7 @@ object EnumFull {
383383 }
384384}
385385```
386- You can also use ` sourcecode.Name ` in an constructor, in which case it'll be
386+ You can also use ` sourcecode.Name ` in an constructor, in which case it'll be
387387picked up during inheritance:
388388
389389``` scala
@@ -425,7 +425,7 @@ class Foo(arg: Int){
425425new Foo (123 ).bar(" lol" ) // sourcecode.DebugRun.main Foo#bar [arg -> param]: (123,lol)
426426```
427427
428- You can easily vary the amount of verbosity, e.g. by swapping the
428+ You can easily vary the amount of verbosity, e.g. by swapping the
429429` sourcecode.Enclosing ` for a ` sourcecode.Name ` if you think it's too verbose:
430430
431431``` scala
@@ -460,11 +460,11 @@ new Foo(123).bar("lol") // [param]: lol
460460
461461Thus you can easily configure how much information your ` debug ` helper method
462462needs, at its definition, without having to hunt all over your codebase for the
463- various ` debug ` call-sites you left lying around and manually tweaking the
463+ various ` debug ` call-sites you left lying around and manually tweaking the
464464verbosity of each one. Furthermore, if you want additional information like
465465` sourcecode.Line ` or ` sourcecode.File ` , that's all just one implicit away.
466466
467- The [ PPrint] ( http://www.lihaoyi.com/upickle-pprint/pprint )
467+ The [ PPrint] ( http://www.lihaoyi.com/upickle-pprint/pprint )
468468library provides a ` pprint.log ` method that does exactly this: prints out the
469469value provided (in this case pretty-printing it with colors and nice formatting
470470& indentation) together with the enclosing context and line number, so you
@@ -473,8 +473,8 @@ can easily distinguish your individual prints later:
473473``` scala
474474scala> class Foo {
475475 | def bar (grid : Seq [Seq [Int ]]) = {
476- | // automatically capture and print out source context
477- | pprint.log(grid, tag= " grid" )
476+ | // automatically capture and print out source context
477+ | pprint.log(grid, tag= " grid" )
478478 | }
479479 | }
480480defined class Foo
@@ -488,7 +488,7 @@ List(
488488)
489489```
490490
491- ` pprint.log ` is itself defined as
491+ ` pprint.log ` is itself defined as
492492
493493``` scala
494494def log [T : PPrint ](value : T , tag : String = " " )
@@ -499,10 +499,10 @@ def log[T: PPrint](value: T, tag: String = "")
499499
500500Using ` sourcecode.Enclosing ` and ` sourcecode.Line ` to provide the context to
501501be printed. You can, or course, define your own ` log ` method in the same way,
502- customizing it to print or not-print exactly what you want to see via the
502+ customizing it to print or not-print exactly what you want to see via the
503503implicits that ` sourcecode ` provides!
504504
505- ` sourcecode.Args ` can be used to access all parameters that where provided
505+ ` sourcecode.Args ` can be used to access all parameters that where provided
506506to a method:
507507
508508``` scala
@@ -521,7 +521,7 @@ Embedding Domain-Specific Languages
521521-----------------------------------
522522
523523The Scala programming is a popular choice to embed domain-specific languages:
524- that means that you start with some external language, e.g. this
524+ that means that you start with some external language, e.g. this
525525[ MathProg] example
526526
527527``` scala
@@ -542,7 +542,7 @@ var y{K} >= 0;
542542```
543543
544544The linked slides has more detail about what exactly this language does (it
545- describes mathematical optimization problems). For a variety of reasons, you
545+ describes mathematical optimization problems). For a variety of reasons, you
546546may prefer to write this as part of a Scala program instead: for example you
547547may want Scala's IDE support, or its ability to define functions that help
548548reduce boilerplate, or maybe you like the way the compiler provides type errors
@@ -574,8 +574,8 @@ when printing error messages, or the results of the computation, you want to
574574see which ` val ` s are involved! Thus you end up duplicating the names over and
575575over and over.
576576
577- With sourcecode, you can easily define ` param ` ` set ` and ` xvar ` as taking
578- implicit ` sourcecode.Name ` s, thus eliminating all the boilerplate involved in
577+ With sourcecode, you can easily define ` param ` ` set ` and ` xvar ` as taking
578+ implicit ` sourcecode.Name ` s, thus eliminating all the boilerplate involved in
579579duplicating names:
580580
581581``` scala
@@ -609,8 +609,8 @@ C.parse("X") // Failure((A | B):1:1 ..."X")
609609```
610610
611611As you can see, the names of the rules ` A ` and ` B ` are embedded in the error
612- messages for parse failures. This makes debugging parsers far easier, while
613- saving you the effort of duplicating the name of the parser in possibly
612+ messages for parse failures. This makes debugging parsers far easier, while
613+ saving you the effort of duplicating the name of the parser in possibly
614614hundreds of rules in a large parser. In this case, it is the ` P(...) ` function
615615which takes an implicit ` sourcecode.Name ` that does this work:
616616
@@ -625,6 +625,11 @@ in its `.toString` method.
625625Version History
626626===============
627627
628+ 0.2.5
629+ -----
630+
631+ - Support Scala 3.0.0-RC2
632+
6286330.2.2
629634-----
630635
@@ -659,41 +664,41 @@ Version History
6596640.1.3
660665-----
661666
662- - Add scala 2.12.x support, thanks to
667+ - Add scala 2.12.x support, thanks to
663668 [ Lars Hupel] ( https://github.com/larsrh )
664669
6656700.1.2
666671-----
667672
668673- Add ` sourcecode.Args ` implicit, which can be used to capture debugging information
669- about the nearest enclosing function call for logging/debugging, thanks to
674+ about the nearest enclosing function call for logging/debugging, thanks to
670675 [ Benjamin Hagemeister] ( https://github.com/benhag )
671676
672- - Attempted fix for [ #17 ] ( https://github.com/lihaoyi/sourcecode/issues/17 ) and
677+ - Attempted fix for [ #17 ] ( https://github.com/lihaoyi/sourcecode/issues/17 ) and
673678 [ #13 ] ( https://github.com/lihaoyi/sourcecode/issues/13 ) , thanks to
674- [ Simeon H.K. Fitch] ( https://github.com/metasim )
679+ [ Simeon H.K. Fitch] ( https://github.com/metasim )
675680
6766810.1.1
677682-----
678683
679- - Ignore ` <local foo> ` and ` <init> ` symbols when determining ` sourcecode.Name ` ,
684+ - Ignore ` <local foo> ` and ` <init> ` symbols when determining ` sourcecode.Name ` ,
680685 ` sourcecode.FullName ` or ` sourcecode.Enclosing ` . If you want these, use the
681686 ` sourcecode.Name.Machine ` /` sourcecode.FullName.Machine ` /` sourcecode.Enclosing.Machine `
682687 implicits instead.
683-
688+
684689- Add ` sourcecode.Text ` implicit to capture source code of an expression
685690
686691- Add implicit conversions to ` sourcecode.* ` , so you can pass in a ` String `
687- to manually satisfy and implicit wanting a ` sourcecode.Name ` or
688- ` sourcecode.FullName ` or ` sourcecode.File ` , an ` Int ` to satisfy an implicit
689- asking for ` sourcecode.Line `
692+ to manually satisfy and implicit wanting a ` sourcecode.Name ` or
693+ ` sourcecode.FullName ` or ` sourcecode.File ` , an ` Int ` to satisfy an implicit
694+ asking for ` sourcecode.Line `
690695
691696- ` sourcecode.Enclosing ` has been simplified to take a single ` String ` rather
692697 than the previous ` Vector[Chunk] ` .
693-
694- - Added the ` sourcecode.Pkg ` implicit, which provides the current
695- enclosing package without any of the ` class ` s/` object ` s/` def ` s/etc.. Can be
696- subtracted from ` sourcecode.Enclosing ` if you * only* want the
698+
699+ - Added the ` sourcecode.Pkg ` implicit, which provides the current
700+ enclosing package without any of the ` class ` s/` object ` s/` def ` s/etc.. Can be
701+ subtracted from ` sourcecode.Enclosing ` if you * only* want the
697702 ` class ` s/` object ` s/` def ` s/etc.
698703
6997040.1.0
0 commit comments