Skip to content

Commit f41ff0e

Browse files
committed
Escape $ in docs for undefined variables
1 parent e117a39 commit f41ff0e

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

library/src/scala/Console.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ import scala.util.DynamicVariable
4545
* val prime = (2 to candidate - 1).forall(candidate % _ != 0)
4646
*
4747
* if (prime)
48-
* Console.println(s"${RESET}${GREEN}yes${RESET}")
48+
* Console.println(s"\${RESET}\${GREEN}yes\${RESET}")
4949
* else
50-
* Console.err.println(s"${RESET}${YELLOW_B}${RED}${UNDERLINED}NO!${RESET}")
50+
* Console.err.println(s"\${RESET}\${YELLOW_B}\${RED}\${UNDERLINED}NO!\${RESET}")
5151
* }
5252
*
5353
* def main(args: Array[String]): Unit = isPrime()
@@ -56,10 +56,10 @@ import scala.util.DynamicVariable
5656
* }}}
5757
*
5858
* <table style="border: 10px solid #000;width:100%">
59-
* <tr><td style="background-color:#000;color:#fff">$ scala PrimeTest</td></tr>
59+
* <tr><td style="background-color:#000;color:#fff">\$ scala PrimeTest</td></tr>
6060
* <tr><td style="background-color:#000;color:#fff">1234567891</td></tr>
6161
* <tr><td style="background-color:#000;color:#0f0">yes</td></tr>
62-
* <tr><td style="background-color:#000;color:#fff">$ scala PrimeTest</td></tr>
62+
* <tr><td style="background-color:#000;color:#fff">\$ scala PrimeTest</td></tr>
6363
* <tr><td style="background-color:#000;color:#fff">56474</td></tr>
6464
* <tr><td style="background-color:#000;color:#fff"><span style="background-color:#ff0;color:#f00;text-decoration:underline">NO!</span></td></tr>
6565
* </table>
@@ -76,7 +76,7 @@ import scala.util.DynamicVariable
7676
*
7777
* def isPrime(candidate: Int): Boolean = {
7878
*
79-
* val input = new StringReader(s"$candidate\n")
79+
* val input = new StringReader(s"\$candidate\n")
8080
* val outCapture = new ByteArrayOutputStream
8181
* val errCapture = new ByteArrayOutputStream
8282
*
@@ -97,15 +97,15 @@ import scala.util.DynamicVariable
9797
*
9898
* def main(args: Array[String]): Unit = {
9999
* val primes = (2 to 50) filter (isPrime)
100-
* println(s"First primes: $primes")
100+
* println(s"First primes: \$primes")
101101
* }
102102
*
103103
* }
104104
* }}}
105105
*
106106
*
107107
* <table style="border: 10px solid #000;width:100%">
108-
* <tr><td style="background-color:#000;color:#fff">$ scala FunctionalPrimeTest</td></tr>
108+
* <tr><td style="background-color:#000;color:#fff">\$ scala FunctionalPrimeTest</td></tr>
109109
* <tr><td style="background-color:#000;color:#fff">First primes: Vector(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)</td></tr>
110110
* </table>
111111
*

library/src/scala/Option.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ object Option {
9999
* bMaybe = Option(abc.get(2))
100100
* bMaybe match {
101101
* case Some(b) =>
102-
* println(s"Found $b")
102+
* println(s"Found \$b")
103103
* case None =>
104104
* println("Not found")
105105
* }

library/src/scala/StringContext.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import scala.annotation.tailrec
2121
* Here's an example:
2222
* {{{
2323
* val name = "James"
24-
* println(s"Hello, $name") // Hello, James
24+
* println(s"Hello, \$name") // Hello, James
2525
* }}}
2626
*
2727
* Any processed string literal is rewritten as an instantiation and
2828
* method call against this class. For example:
2929
* {{{
30-
* s"Hello, $name"
30+
* s"Hello, \$name"
3131
* }}}
3232
*
3333
* is rewritten to be:
@@ -45,7 +45,7 @@ import scala.annotation.tailrec
4545
* implicit class JsonHelper(private val sc: StringContext) extends AnyVal {
4646
* def json(args: Any*): JSONObject = ...
4747
* }
48-
* val x: JSONObject = json"{ a: $a }"
48+
* val x: JSONObject = json"{ a: \$a }"
4949
* }}}
5050
*
5151
* Here the `JsonHelper` extension class implicitly adds the `json` method to
@@ -77,14 +77,14 @@ case class StringContext(parts: String*) {
7777
* Here's an example of usage:
7878
* {{{
7979
* val name = "James"
80-
* println(s"Hello, $name") // Hello, James
80+
* println(s"Hello, \$name") // Hello, James
8181
* }}}
82-
* In this example, the expression $name is replaced with the `toString` of the
82+
* In this example, the expression \$name is replaced with the `toString` of the
8383
* variable `name`.
8484
* The `s` interpolator can take the `toString` of any arbitrary expression within
85-
* a `${}` block, for example:
85+
* a `\${}` block, for example:
8686
* {{{
87-
* println(s"1 + 1 = ${1 + 1}")
87+
* println(s"1 + 1 = \${1 + 1}")
8888
* }}}
8989
* will print the string `1 + 1 = 2`.
9090
*
@@ -149,7 +149,7 @@ case class StringContext(parts: String*) {
149149
* {{{
150150
* val height = 1.9d
151151
* val name = "James"
152-
* println(f"$name%s is $height%2.2f meters tall") // James is 1.90 meters tall
152+
* println(f"\$name%s is \$height%2.2f meters tall") // James is 1.90 meters tall
153153
* }}}
154154
*
155155
* @param `args` The arguments to be inserted into the resulting string.

library/src/scala/annotation/implicitAmbiguous.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package scala.annotation
1717
* multiple ambiguous values, annotate at least one of the implicit values
1818
* `@implicitAmbiguous`. Assuming the implicit value is a method with type
1919
* parameters `X1,..., XN`, the error message will be the result of replacing
20-
* all occurrences of `${Xi}` in the string `msg` with the string representation
20+
* all occurrences of `\${Xi}` in the string `msg` with the string representation
2121
* of the corresponding type argument `Ti`.
2222
*
2323
* If more than one `@implicitAmbiguous` annotation is collected, the compiler is
@@ -31,7 +31,7 @@ package scala.annotation
3131
*
3232
* implicit def neq[E, F] : E =!= F = null
3333
*
34-
* @annotation.implicitAmbiguous("Could not prove ${J} =!= ${J}")
34+
* @annotation.implicitAmbiguous("Could not prove \${J} =!= \${J}")
3535
* implicit def neqAmbig1[G, H, J] : J =!= J = null
3636
* implicit def neqAmbig2[I] : I =!= I = null
3737
*

library/src/scala/io/AnsiColor.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package io
2525
*
2626
* object ColorDemo extends App {
2727
*
28-
* println(s"${REVERSED}${BOLD}Hello 1979!${RESET}")
28+
* println(s"\${REVERSED}\${BOLD}Hello 1979!\${RESET}")
2929
* }
3030
* }}}
3131
*

library/src/scala/reflect/ClassTag.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import java.lang.{ Class => jClass }
3030
* For example:
3131
* {{{
3232
* scala> def mkArray[T : ClassTag](elems: T*) = Array[T](elems: _*)
33-
* mkArray: [T](elems: T*)(implicit evidence$1: scala.reflect.ClassTag[T])Array[T]
33+
* mkArray: [T](elems: T*)(implicit evidence\$1: scala.reflect.ClassTag[T])Array[T]
3434
*
3535
* scala> mkArray(42, 13)
3636
* res0: Array[Int] = Array(42, 13)

library/src/scala/util/Either.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ package util
3535
* }
3636
*
3737
* result match {
38-
* case Right(x) => s"You passed me the Int: $x, which I will increment. $x + 1 = ${x+1}"
39-
* case Left(x) => s"You passed me the String: $x"
38+
* case Right(x) => s"You passed me the Int: \$x, which I will increment. \$x + 1 = \${x+1}"
39+
* case Left(x) => s"You passed me the String: \$x"
4040
* }
4141
* }}}
4242
*
@@ -159,10 +159,10 @@ sealed abstract class Either[+A, +B] extends Product with Serializable {
159159
* val report = for (result <- interactWithDB(someQuery)) yield generateReport(result)
160160
* report match {
161161
* case Right(r) => send(r)
162-
* case Left(e) => log(s"report not generated, reason was $e")
162+
* case Left(e) => log(s"report not generated, reason was \$e")
163163
* }
164164
* // only report errors
165-
* for (e <- interactWithDB(someQuery).left) log(s"query failed, reason was $e")
165+
* for (e <- interactWithDB(someQuery).left) log(s"query failed, reason was \$e")
166166
* }}}
167167
*/
168168
def left = Either.LeftProjection(this)
@@ -178,8 +178,8 @@ sealed abstract class Either[+A, +B] extends Product with Serializable {
178178
* @example {{{
179179
* val result = util.Try("42".toInt).toEither
180180
* result.fold(
181-
* e => s"Operation failed with $e",
182-
* v => s"Operation produced value: $v"
181+
* e => s"Operation failed with \$e",
182+
* v => s"Operation produced value: \$v"
183183
* )
184184
* }}}
185185
*
@@ -452,7 +452,7 @@ object Either {
452452
* Either.cond(
453453
* userInput.forall(_.isDigit) && userInput.size == 10,
454454
* PhoneNumber(userInput),
455-
* s"The input ($userInput) does not look like a phone number"
455+
* s"The input (\$userInput) does not look like a phone number"
456456
* }}}
457457
*/
458458
def cond[A, B](test: Boolean, right: => B, left: => A): Either[A, B] =

library/src/scala/util/matching/Regex.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import java.util.regex.{ Pattern, Matcher }
5959
*
6060
* {{{
6161
* "2004-01-20" match {
62-
* case date(year, month, day) => s"$year was a good year for PLs."
62+
* case date(year, month, day) => s"\$year was a good year for PLs."
6363
* }
6464
* }}}
6565
*
@@ -78,7 +78,7 @@ import java.util.regex.{ Pattern, Matcher }
7878
*
7979
* {{{
8080
* "2004-01-20" match {
81-
* case date(year, _*) => s"$year was a good year for PLs."
81+
* case date(year, _*) => s"\$year was a good year for PLs."
8282
* }
8383
* }}}
8484
*
@@ -121,7 +121,7 @@ import java.util.regex.{ Pattern, Matcher }
121121
* val mi = date.findAllIn(dates)
122122
* while (mi.hasNext) {
123123
* val d = mi.next
124-
* if (mi.group(1).toInt < 1960) println(s"$d: An oldie but goodie.")
124+
* if (mi.group(1).toInt < 1960) println(s"\$d: An oldie but goodie.")
125125
* }
126126
* }}}
127127
*
@@ -165,8 +165,8 @@ import java.util.regex.{ Pattern, Matcher }
165165
* {{{
166166
* val redacted = date.replaceAllIn(dates, "XXXX-XX-XX")
167167
* val yearsOnly = date.replaceAllIn(dates, m => m.group(1))
168-
* val months = (0 to 11).map { i => val c = Calendar.getInstance; c.set(2014, i, 1); f"$c%tb" }
169-
* val reformatted = date.replaceAllIn(dates, _ match { case date(y,m,d) => f"${months(m.toInt - 1)} $d, $y" })
168+
* val months = (0 to 11).map { i => val c = Calendar.getInstance; c.set(2014, i, 1); f"\$c%tb" }
169+
* val reformatted = date.replaceAllIn(dates, _ match { case date(y,m,d) => f"\${months(m.toInt - 1)} \$d, \$y" })
170170
* }}}
171171
*
172172
* Pattern matching the `Match` against the `Regex` that created it does not reapply the `Regex`.
@@ -191,7 +191,7 @@ import java.util.regex.{ Pattern, Matcher }
191191
* @param groupNames A mapping from names to indices in capture groups
192192
*
193193
* @define replacementString
194-
* In the replacement String, a dollar sign (`$`) followed by a number will be
194+
* In the replacement String, a dollar sign (`\$`) followed by a number will be
195195
* interpreted as a reference to a group in the matched pattern, with numbers
196196
* 1 through 9 corresponding to the first nine groups, and 0 standing for the
197197
* whole match. Any other character is an error. The backslash (`\`) character
@@ -380,7 +380,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
380380
* {{{
381381
* val madhatter = "(h)(?=(at[^a]+))".r
382382
* val madhats = madhatter.findAllMatchIn(hathaway).map {
383-
* case madhatter(x,y) => s"$x$y"
383+
* case madhatter(x,y) => s"\$x\$y"
384384
* }.toList // List(hath, hatth, hattth, hatttt)
385385
* }}}
386386
*
@@ -494,7 +494,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
494494
* import scala.util.matching.Regex
495495
* val datePattern = new Regex("""(\d\d\d\d)-(\d\d)-(\d\d)""", "year", "month", "day")
496496
* val text = "From 2011-07-15 to 2011-07-17"
497-
* val repl = datePattern replaceAllIn (text, m => s"${m group "month"}/${m group "day"}")
497+
* val repl = datePattern replaceAllIn (text, m => s"\${m group "month"}/\${m group "day"}")
498498
* }}}
499499
*
500500
* $replacementString
@@ -517,7 +517,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
517517
* {{{
518518
* import scala.util.matching.Regex._
519519
*
520-
* val vars = Map("x" -> "a var", "y" -> """some $ and \ signs""")
520+
* val vars = Map("x" -> "a var", "y" -> """some \$ and \ signs""")
521521
* val text = "A text with variables %x, %y and %z."
522522
* val varPattern = """%(\w+)""".r
523523
* val mapper = (m: Match) => vars get (m group 1) map (quoteReplacement(_))
@@ -564,7 +564,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
564564
* the entire String matches in extractor patterns.
565565
*
566566
* Normally, matching on `date` behaves as though the pattern were
567-
* enclosed in anchors, `"^pattern$"`.
567+
* enclosed in anchors, `"^pattern\$"`.
568568
*
569569
* The unanchored `Regex` behaves as though those anchors were removed.
570570
*
@@ -578,7 +578,7 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends
578578
* val date(year, month, day) = "Date 2011-07-15" // OK
579579
*
580580
* val copyright: String = "Date of this document: 2011-07-15" match {
581-
* case date(year, month, day) => s"Copyright $year" // OK
581+
* case date(year, month, day) => s"Copyright \$year" // OK
582582
* case _ => "No copyright"
583583
* }
584584
* }}}
@@ -766,7 +766,7 @@ object Regex {
766766
*
767767
* val date = """(\d\d\d\d)-(\d\d)-(\d\d)""".r
768768
* val text = "The doc spree happened on 2011-07-15."
769-
* val day = date replaceAllIn(text, _ match { case Groups(_, month, day) => s"$month/$day" })
769+
* val day = date replaceAllIn(text, _ match { case Groups(_, month, day) => s"\$month/\$day" })
770770
* }}}
771771
*/
772772
object Groups {
@@ -904,21 +904,21 @@ object Regex {
904904
*
905905
* All regex metacharacters in the input match themselves literally in the output.
906906
*
907-
* @example {{{List("US$", "CAN$").map(Regex.quote).mkString("|").r}}}
907+
* @example {{{List("US\$", "CAN\$").map(Regex.quote).mkString("|").r}}}
908908
*/
909909
def quote(text: String): String = Pattern quote text
910910

911911
/** Quotes replacement strings to be used in replacement methods.
912912
*
913913
* Replacement methods give special meaning to backslashes (`\`) and
914-
* dollar signs (`$`) in replacement strings, so they are not treated
914+
* dollar signs (`\$`) in replacement strings, so they are not treated
915915
* as literals. This method escapes these characters so the resulting
916916
* string can be used as a literal replacement representing the input
917917
* string.
918918
*
919919
* @param text The string one wishes to use as literal replacement.
920920
* @return A string that can be used to replace matches with `text`.
921-
* @example {{{"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")}}}
921+
* @example {{{"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US\$")}}}
922922
*/
923923
def quoteReplacement(text: String): String = Matcher quoteReplacement text
924924
}

0 commit comments

Comments
 (0)