Skip to content

Commit fd97e66

Browse files
committed
0.2.5
1 parent 75394fc commit fd97e66

File tree

2 files changed

+57
-52
lines changed

2 files changed

+57
-52
lines changed

README.md

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ SourceCode [![Build Status](https://travis-ci.org/lihaoyi/sourcecode.svg?branch=
22
==========
33

44
```scala
5-
"com.lihaoyi" %% "sourcecode" % "0.2.3" // Scala-JVM
6-
"com.lihaoyi" %%% "sourcecode" % "0.2.3" // Scala.js / Scala Native
5+
"com.lihaoyi" %% "sourcecode" % "0.2.5" // Scala-JVM
6+
"com.lihaoyi" %%% "sourcecode" % "0.2.5" // Scala.js / Scala Native
77
```
88

99
`sourcecode` is a small Scala library for that provides common "source code"
@@ -21,10 +21,10 @@ assert(line == 16)
2121
```
2222

2323
This 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).
2626
This information is also available via an `implicit`, letting you write functions
27-
that automatically pull it in.
27+
that automatically pull it in.
2828

2929
Using SourceCode on code dealing with lots of anonymous functions or anonymous
3030
classes 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

4343
If you like using Sourcecode, you might also enjoy this book by the author which
4444
teaches 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.
110110
Examples
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
114114
variety of contexts. Hopefully they will give you an idea of how the various
115115
implicits 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
175175
types to your functions. That would make these values automatically available
176176
to your functions without needing to manually keep passing them in. Apart from
177177
summoning 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

286286
Hopefully 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
289289
package 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

292292
Use Cases
293293
=========
@@ -318,7 +318,7 @@ This can be handy for letting you see where the log lines are coming from,
318318
without tediously tagging every log statement with a unique prefix.
319319
Furthermore, this happens at compile time, and is thus orders of magnitude
320320
faster 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
322322
information such as method names, class names, or packages to be provided to
323323
your logging function, you can easily do so by asking for the `sourcecode.Name`
324324
or `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
362362
given 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
367367
package 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
387387
picked up during inheritance:
388388

389389
```scala
@@ -425,7 +425,7 @@ class Foo(arg: Int){
425425
new 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

461461
Thus you can easily configure how much information your `debug` helper method
462462
needs, 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
464464
verbosity 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)
468468
library provides a `pprint.log` method that does exactly this: prints out the
469469
value 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
474474
scala> 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
| }
480480
defined 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
494494
def log[T: PPrint](value: T, tag: String = "")
@@ -499,10 +499,10 @@ def log[T: PPrint](value: T, tag: String = "")
499499

500500
Using `sourcecode.Enclosing` and `sourcecode.Line` to provide the context to
501501
be 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
503503
implicits 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
506506
to a method:
507507

508508
```scala
@@ -521,7 +521,7 @@ Embedding Domain-Specific Languages
521521
-----------------------------------
522522

523523
The 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

544544
The 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
546546
may prefer to write this as part of a Scala program instead: for example you
547547
may want Scala's IDE support, or its ability to define functions that help
548548
reduce 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
574574
see which `val`s are involved! Thus you end up duplicating the names over and
575575
over 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
579579
duplicating names:
580580

581581
```scala
@@ -609,8 +609,8 @@ C.parse("X") // Failure((A | B):1:1 ..."X")
609609
```
610610

611611
As 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
614614
hundreds of rules in a large parser. In this case, it is the `P(...)` function
615615
which takes an implicit `sourcecode.Name` that does this work:
616616

@@ -625,6 +625,11 @@ in its `.toString` method.
625625
Version History
626626
===============
627627

628+
0.2.5
629+
-----
630+
631+
- Support Scala 3.0.0-RC2
632+
628633
0.2.2
629634
-----
630635

@@ -659,41 +664,41 @@ Version History
659664
0.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

665670
0.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

676681
0.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

699704
0.1.0

build.sc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion
44

55
val dottyVersions = sys.props.get("dottyVersion").toList
66

7-
val scalaVersions = "2.11.12" :: "2.12.13" :: "2.13.4" :: "3.0.0-RC1" :: dottyVersions
7+
val scalaVersions = "2.11.12" :: "2.12.13" :: "2.13.4" :: "3.0.0-RC2" :: dottyVersions
88
val scala2Versions = scalaVersions.filter(_.startsWith("2."))
99

1010
val scalaJSVersions = for {

0 commit comments

Comments
 (0)