diff options
20 files changed, 165 insertions, 71 deletions
diff --git a/project/Build.scala b/project/Build.scala index 5b09e053f0..9f73563f8e 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -44,7 +44,7 @@ object ScalaBuild extends Build with Layers { </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> + <connection>scm:git:git://github.com/scala/scala.git</connection> </scm> <issueManagement> <system>jira</system> @@ -92,7 +92,7 @@ object ScalaBuild extends Build with Layers { </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> + <connection>scm:git:git://github.com/scala/scala.git</connection> </scm> <issueManagement> <system>jira</system> diff --git a/src/build/maven/continuations-plugin-pom.xml b/src/build/maven/continuations-plugin-pom.xml index aca519b87e..9abb0a36f0 100644 --- a/src/build/maven/continuations-plugin-pom.xml +++ b/src/build/maven/continuations-plugin-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> diff --git a/src/build/maven/jline-pom.xml b/src/build/maven/jline-pom.xml index 4752deb5e0..0d6e801551 100644 --- a/src/build/maven/jline-pom.xml +++ b/src/build/maven/jline-pom.xml @@ -28,13 +28,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> diff --git a/src/build/maven/scala-actors-pom.xml b/src/build/maven/scala-actors-pom.xml index 12bae2a23d..e8c6649721 100644 --- a/src/build/maven/scala-actors-pom.xml +++ b/src/build/maven/scala-actors-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> <dependency> diff --git a/src/build/maven/scala-compiler-pom.xml b/src/build/maven/scala-compiler-pom.xml index f9bcb6719d..82d0ed7c91 100644 --- a/src/build/maven/scala-compiler-pom.xml +++ b/src/build/maven/scala-compiler-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> diff --git a/src/build/maven/scala-dbc-pom.xml b/src/build/maven/scala-dbc-pom.xml index 23092d10ad..aa3d050c1e 100644 --- a/src/build/maven/scala-dbc-pom.xml +++ b/src/build/maven/scala-dbc-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> <dependency> diff --git a/src/build/maven/scala-dotnet-library-pom.xml b/src/build/maven/scala-dotnet-library-pom.xml index 339460924a..007e8be173 100644 --- a/src/build/maven/scala-dotnet-library-pom.xml +++ b/src/build/maven/scala-dotnet-library-pom.xml @@ -24,13 +24,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <distributionManagement> <repository> diff --git a/src/build/maven/scala-library-pom.xml b/src/build/maven/scala-library-pom.xml index 8e0abd4937..673c3dfada 100644 --- a/src/build/maven/scala-library-pom.xml +++ b/src/build/maven/scala-library-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <distributionManagement> <repository> diff --git a/src/build/maven/scala-partest-pom.xml b/src/build/maven/scala-partest-pom.xml index f18ca46c50..ac05f242d5 100644 --- a/src/build/maven/scala-partest-pom.xml +++ b/src/build/maven/scala-partest-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> diff --git a/src/build/maven/scala-swing-pom.xml b/src/build/maven/scala-swing-pom.xml index a03bc07ab0..3df5db5b21 100644 --- a/src/build/maven/scala-swing-pom.xml +++ b/src/build/maven/scala-swing-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> <dependency> diff --git a/src/build/maven/scalap-pom.xml b/src/build/maven/scalap-pom.xml index d7f867d4a1..50c08e899c 100644 --- a/src/build/maven/scalap-pom.xml +++ b/src/build/maven/scalap-pom.xml @@ -23,13 +23,12 @@ </license> </licenses> <scm> - <connection>scm:svn:http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk</connection> - <url>https://lampsvn.epfl.ch/trac/scala/browser/scala/trunk</url> + <connection>scm:git:git://github.com/scala/scala.git</connection> + <url>https://github.com/scala/scala.git</url> </scm> <issueManagement> - <system>trac</system> - <url>http://lampsvn.epfl.ch/trac/scala - </url> + <system>JIRA</system> + <url>https://issues.scala-lang.org/</url> </issueManagement> <dependencies> diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index 4c77cb7082..8e326c202a 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -739,7 +739,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with clasz.cunit.warning(sym.pos, """|compiler bug: created invalid generic signature for %s in %s |signature: %s - |if this is reproducible, please report bug at http://lampsvn.epfl.ch/trac/scala + |if this is reproducible, please report bug at https://issues.scala-lang.org/ """.trim.stripMargin.format(sym, sym.owner.skipPackageObject.fullName, sig)) return } @@ -753,7 +753,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with |original type: %s |normalized type: %s |erasure type: %s - |if this is reproducible, please report bug at http://lampsvn.epfl.ch/trac/scala + |if this is reproducible, please report bug at https://issues.scala-lang.org/ """.trim.stripMargin.format(sym, sym.owner.skipPackageObject.fullName, sig, memberTpe, normalizedTpe, bytecodeTpe)) return } diff --git a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala index 3896304a7f..bbc36e01c9 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala @@ -261,7 +261,7 @@ trait PatMatVirtualiser extends ast.TreeDSL { self: Analyzer => case Bound(subpatBinder, typed@Typed(expr, tpt)) if typed.tpe ne null => Some((subpatBinder, typed.tpe)) case Bind(_, typed@Typed(expr, tpt)) if typed.tpe ne null => Some((patBinder, typed.tpe)) case Typed(expr, tpt) if tree.tpe ne null => Some((patBinder, tree.tpe)) - case _ => None + case _ => None } } diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 505d7c85a1..95a1eafae2 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2144,13 +2144,13 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { case Annotated(Ident(nme.synthSwitch), selector) => (selector, false) case s => (s, true) } - val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode, WildcardType)) - val selectorTp = packCaptured(selector1.tpe.widen) - val casesTyped = typedCases(cases, selectorTp, resTp) + val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode, WildcardType)) + val selectorTp = packCaptured(selector1.tpe.widen) + val casesTyped = typedCases(cases, selectorTp, resTp) val caseTypes = casesTyped map (c => packedType(c, context.owner).deconst) val (ownType0, needAdapt) = if (isFullyDefined(resTp)) (resTp, false) else weakLub(caseTypes) val ownType = ownType0.skolemizeExistential(context.owner, context.tree) - val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, ownType)) + val casesAdapted = if (!needAdapt) casesTyped else casesTyped map (adaptCase(_, mode, ownType)) // val (owntype0, needAdapt) = ptOrLub(casesTyped map (x => repackExistential(x.tpe))) // val owntype = elimAnonymousClass(owntype0) (selector1, selectorTp, casesAdapted, ownType, doTranslation) diff --git a/src/library/scala/collection/immutable/StringLike.scala b/src/library/scala/collection/immutable/StringLike.scala index f9697565de..fc4e7bf0a8 100644 --- a/src/library/scala/collection/immutable/StringLike.scala +++ b/src/library/scala/collection/immutable/StringLike.scala @@ -207,9 +207,20 @@ self => /** You can follow a string with `.r`, turning it into a `Regex`. E.g. * - * """A\w*""".r is the regular expression for identifiers starting with `A`. + * `"""A\w*""".r` is the regular expression for identifiers starting with `A`. */ - def r: Regex = new Regex(toString) + def r: Regex = r() + + /** You can follow a string with `.r(g1, ... , gn)`, turning it into a `Regex`, + * with group names g1 through gn. + * + * `"""(\d\d)-(\d\d)-(\d\d\d\d)""".r("month", "day", "year")` matches dates + * and provides its subcomponents through groups named "month", "day" and + * "year". + * + * @param groupNames The names of the groups in the pattern, in the order they appear. + */ + def r(groupNames: String*): Regex = new Regex(toString, groupNames: _*) def toBoolean: Boolean = parseBoolean(toString) def toByte: Byte = java.lang.Byte.parseByte(toString) diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala index ca97515e23..3f21cc9724 100644 --- a/src/library/scala/util/matching/Regex.scala +++ b/src/library/scala/util/matching/Regex.scala @@ -133,6 +133,15 @@ import java.util.regex.{ Pattern, Matcher } * * @param regex A string representing a regular expression * @param groupNames A mapping from names to indices in capture groups + * + * @define replacementString + * In the replacement String, a dollar sign (`$`) followed by a number will be + * interpreted as a reference to a group in the matched pattern, with numbers + * 1 through 9 corresponding to the first nine groups, and 0 standing for the + * whole match. Any other character is an error. The backslash (`\`) character + * will be interpreted as an escape character, and can be used to escape the + * dollar sign. One can use [[scala.util.matching.Regex]]'s `quoteReplacement` + * to automatically escape these characters. */ @SerialVersionUID(-2094783597747625537L) class Regex(regex: String, groupNames: String*) extends Serializable { @@ -180,7 +189,7 @@ class Regex(regex: String, groupNames: String*) extends Serializable { None } - /** Return all matches of this regexp in given character sequence as a [[scala.util.mathcing.Regex.MatchIterator]], + /** Return all matches of this regexp in given character sequence as a [[scala.util.matching.Regex.MatchIterator]], * which is a special [[scala.collection.Iterator]] that returns the * matched strings, but can also be converted into a normal iterator * that returns objects of type [[scala.util.matching.Regex.Match]] @@ -193,6 +202,25 @@ class Regex(regex: String, groupNames: String*) extends Serializable { */ def findAllIn(source: java.lang.CharSequence) = new Regex.MatchIterator(source, this, groupNames) + + /** Return all matches of this regexp in given character sequence as a + * [[scala.collection.Iterator]] of [[scala.util.matching.Regex.Match]. + * + * @param source The text to match against. + * @return A [[scala.collection.Iterator]] of [[scala.util.matching.Regex.Match]] for all matches. + * @example {{{for (words <- """\w+""".r findAllMatchIn "A simple example.") yield words.start}}} + */ + def findAllMatchIn(source: java.lang.CharSequence): Iterator[Match] = { + val matchIterator = findAllIn(source) + new Iterator[Match] { + def hasNext = matchIterator.hasNext + def next: Match = { + matchIterator.next; + new Match(matchIterator.source, matchIterator.matcher, matchIterator.groupNames).force + } + } + } + /** Return optionally first matching string of this regexp in given character sequence, * or None if it does not exist. * @@ -258,6 +286,8 @@ class Regex(regex: String, groupNames: String*) extends Serializable { /** Replaces all matches by a string. * + * $replacementString + * * @param target The string to match * @param replacement The string that will replace each match * @return The resulting string @@ -280,6 +310,8 @@ class Regex(regex: String, groupNames: String*) extends Serializable { * val repl = datePattern replaceAllIn (text, m => m.group("month")+"/"+m.group("day")) * }}} * + * $replacementString + * * @param target The string to match. * @param replacer The function which maps a match to another string. * @return The target string after replacements. @@ -298,13 +330,15 @@ class Regex(regex: String, groupNames: String*) extends Serializable { * {{{ * import scala.util.matching.Regex._ * - * val map = Map("x" -> "a var", "y" -> "another var") + * val map = Map("x" -> "a var", "y" -> """some $ and \ signs""") * val text = "A text with variables %x, %y and %z." * val varPattern = """%(\w+)""".r - * val mapper = (m: Match) => map get (m group 1) + * val mapper = (m: Match) => map get (m group 1) map (quoteReplacement(_)) * val repl = varPattern replaceSomeIn (text, mapper) * }}} * + * $replacementString + * * @param target The string to match. * @param replacer The function which optionally maps a match to another string. * @return The target string after replacements. @@ -319,6 +353,8 @@ class Regex(regex: String, groupNames: String*) extends Serializable { /** Replaces the first match by a string. * + * $replacementString + * * @param target The string to match * @param replacement The string that will replace the match * @return The resulting string @@ -505,7 +541,7 @@ object Regex { class MatchIterator(val source: java.lang.CharSequence, val regex: Regex, val groupNames: Seq[String]) extends AbstractIterator[String] with Iterator[String] with MatchData { self => - protected val matcher = regex.pattern.matcher(source) + protected[Regex] val matcher = regex.pattern.matcher(source) private var nextSeen = false /** Is there another match? */ @@ -569,4 +605,18 @@ object Regex { def replace(rs: String) = matcher.appendReplacement(sb, rs) } + + /** Quotes replacement strings to be used in replacement methods. + * + * Replacement methods give special meaning to backslashes (`\`) and + * dollar signs (`$`) in replacement strings, so they are not treated + * as literals. This method escapes these characters so the resulting + * string can be used as a literal replacement representing the input + * string. + * + * @param text The string one wishes to use as literal replacement. + * @return A string that can be used to replace matches with `text`. + * @example {{{"CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")}}} + */ + def quoteReplacement(text: String): String = Matcher quoteReplacement text } diff --git a/test/files/run/si4750.check b/test/files/run/si4750.check new file mode 100644 index 0000000000..bf55f70df3 --- /dev/null +++ b/test/files/run/si4750.check @@ -0,0 +1 @@ +US$ 5.80 diff --git a/test/files/run/si4750.scala b/test/files/run/si4750.scala new file mode 100644 index 0000000000..96d2c4fec7 --- /dev/null +++ b/test/files/run/si4750.scala @@ -0,0 +1,7 @@ +import scala.util.matching.Regex + +object Test extends App { + val input = "CURRENCY 5.80" + println("CURRENCY".r.replaceAllIn(input, Regex quoteReplacement "US$")) +} + diff --git a/test/files/scalacheck/t2460.scala b/test/files/scalacheck/t2460.scala new file mode 100644 index 0000000000..196b43789f --- /dev/null +++ b/test/files/scalacheck/t2460.scala @@ -0,0 +1,32 @@ +import org.scalacheck.Prop.forAll +import org.scalacheck.Properties +import org.scalacheck.ConsoleReporter.testStatsEx +import org.scalacheck.{Test => SCTest} +import org.scalacheck.Gen + +object Test extends Properties("Regex : Ticket 2460") { + + val vowel = Gen.oneOf("a", "z") + + val numberOfMatch = forAll(vowel) { + (s: String) => "\\s*([a-z])\\s*".r("data").findAllMatchIn((1 to 20).map(_ => s).mkString).size == 20 + } + + val numberOfGroup = forAll(vowel) { + (s: String) => "\\s*([a-z])\\s*([a-z])\\s*".r("data").findAllMatchIn((1 to 20).map(_ => s).mkString).next.groupCount == 2 + } + + val nameOfGroup = forAll(vowel) { + (s: String) => "([a-z])".r("data").findAllMatchIn(s).next.group("data") == s + } + + val tests = List( + ("numberOfMatch", numberOfMatch), + ("numberOfGroup", numberOfGroup), + ("nameOfGroup", nameOfGroup) + ) + + /*tests foreach { + case (name, p) => testStatsEx(name, SCTest.check(p)) + }*/ +} diff --git a/test/scaladoc/scala/html/HtmlFactoryTest.scala b/test/scaladoc/scala/html/HtmlFactoryTest.scala index 7550faa536..28c7a4b94f 100644 --- a/test/scaladoc/scala/html/HtmlFactoryTest.scala +++ b/test/scaladoc/scala/html/HtmlFactoryTest.scala @@ -442,8 +442,9 @@ object Test extends Properties("HtmlFactory") { property("Use cases should override their original members") = checkText("SI_5054_q1.scala")( - (None,"""def test(): Int""", true), - (None,"""def test(implicit lost: Int): Int""", false) + (None,"""def test(): Int""", true) + //Disabled because the full signature is now displayed + //(None,"""def test(implicit lost: Int): Int""", false) ) property("Use cases should keep their flags - final should not be lost") = @@ -599,8 +600,9 @@ object Test extends Properties("HtmlFactory") { T StartT the type of the first argument EndT arg1 Start1 The T term comment End1 arg2 Start2 The string comment End2 - returns StartRet The return comment EndRet - Definition Classes InheritDocDerived → InheritDocBase + returns StartRet The return comment EndRet""", true), + (Some("InheritDocDerived"), + """Definition Classes InheritDocDerived → InheritDocBase Example: StartExample function[Int](3, "something") EndExample Version StartVer 0.0.2 EndVer Since StartSince 0.0.1 EndSince @@ -624,8 +626,9 @@ object Test extends Properties("HtmlFactory") { T StartT the type of the first argument EndT arg1 Start1 The T term comment End1 arg2 Start2 The string comment End2 - returns StartRet The return comment EndRet - Example: StartExample function[Int](3,"something") EndExample + returns StartRet The return comment EndRet""", true), + (Some("UseCaseInheritDoc"), + """Example: StartExample function[Int](3,"something") EndExample Version StartVer 0.0.2 EndVer Since StartSince 0.0.1 EndSince Exceptions thrown |