Skip to content

Commit f63a944

Browse files
committed
Scalafmt-core: 2.4.2 -> 2.5.1
1 parent d43826a commit f63a944

23 files changed

+268
-228
lines changed

build.sbt

+5-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,11 @@ val scalac211Options: Seq[String] = {
202202
val scalacOptionExclusionsForConsole: Seq[String] = Seq("-Ywarn-unused:imports", "-Xfatal-warnings")
203203

204204
val scalacOptionSettings: Seq[Setting[_]] = {
205-
def baseScalaCOptions(scalaVersion: String) = CrossVersion.partialVersion(scalaVersion) match {
206-
case Some((2, 11)) => scalac211Options
207-
case _ => scalac212Options
208-
}
205+
def baseScalaCOptions(scalaVersion: String) =
206+
CrossVersion.partialVersion(scalaVersion) match {
207+
case Some((2, 11)) => scalac211Options
208+
case _ => scalac212Options
209+
}
209210

210211
Seq(
211212
scalacOptions ++= baseScalaCOptions(scalaVersion.value),

parser/src/main/scala/Parser.scala

+39-33
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ object Parser {
9090
/**
9191
* Character range like `a-z`.
9292
*/
93-
def matchCharRange[_: P]: P[Range[Char]] = P(
94-
(singleLitCharClassChar ~ "-" ~ singleLitCharClassChar).map {
95-
case (l, h) => Range(l, h)
96-
}
97-
)
93+
def matchCharRange[_: P]: P[Range[Char]] =
94+
P(
95+
(singleLitCharClassChar ~ "-" ~ singleLitCharClassChar).map {
96+
case (l, h) => Range(l, h)
97+
}
98+
)
9899

99100
/**
100101
* Matches repeat counts like `{3}` or `{1,4}`.
@@ -103,7 +104,9 @@ object Parser {
103104
P(
104105
"{" ~/ (
105106
(posInt ~ "," ~/ posInt.? ~/ "}" ~/ (P("?").map(_ => Greediness.NonGreedy) | Pass(
106-
Greediness.Greedy))).map { case (l, h, g) => Quantifier.Range(l, h, g) } |
107+
Greediness.Greedy))).map {
108+
case (l, h, g) => Quantifier.Range(l, h, g)
109+
} |
107110
(posInt.map(Quantifier.Exact(_)) ~ "}")
108111
)
109112
).opaque("repeat count such as '{3}', '{1,4}', `{1, 4}?`, '{3,}', or `{3,}?")
@@ -163,28 +166,30 @@ object Parser {
163166
("[" ~ charClassTerm ~ "]")
164167
)
165168

166-
def base[_: P]: P[RegexC[Unit]] = P(
167-
standardMatchChar.map(lit(_).void) |
168-
("\\" ~/ (("u" ~ unicodeCodePoint | specialChar).map(lit(_).void) | shorthandClass.map(
169-
matching(_).void))) |
170-
wildcard.map(_.void) |
171-
charClass.map(matching(_).void) |
172-
// TODO distinguish between capturing and not?
173-
("(?:" ~ regex ~ ")") |
174-
("(" ~ regex ~ ")")
175-
)
176-
177-
def factor[_: P]: P[RegexC[Unit]] = P {
178-
base.flatMap { r =>
179-
P("*?").map(_ => r.star(Greediness.NonGreedy).void) |
180-
P("*").map(_ => r.star(Greediness.Greedy).void) |
181-
P("+").map(_ => r.oneOrMore(Greediness.Greedy).void) |
182-
P("??").map(_ => r.optional(Greediness.NonGreedy).void) |
183-
P("?").map(_ => r.optional(Greediness.Greedy).void) |
184-
quantifier.map(q => r.quantifyFold(q, ())((_, _) => ())) |
185-
Pass(r)
169+
def base[_: P]: P[RegexC[Unit]] =
170+
P(
171+
standardMatchChar.map(lit(_).void) |
172+
("\\" ~/ (("u" ~ unicodeCodePoint | specialChar).map(lit(_).void) | shorthandClass.map(
173+
matching(_).void))) |
174+
wildcard.map(_.void) |
175+
charClass.map(matching(_).void) |
176+
// TODO distinguish between capturing and not?
177+
("(?:" ~ regex ~ ")") |
178+
("(" ~ regex ~ ")")
179+
)
180+
181+
def factor[_: P]: P[RegexC[Unit]] =
182+
P {
183+
base.flatMap { r =>
184+
P("*?").map(_ => r.star(Greediness.NonGreedy).void) |
185+
P("*").map(_ => r.star(Greediness.Greedy).void) |
186+
P("+").map(_ => r.oneOrMore(Greediness.Greedy).void) |
187+
P("??").map(_ => r.optional(Greediness.NonGreedy).void) |
188+
P("?").map(_ => r.optional(Greediness.Greedy).void) |
189+
quantifier.map(q => r.quantifyFold(q, ())((_, _) => ())) |
190+
Pass(r)
191+
}
186192
}
187-
}
188193

189194
// TODO can probably do better than toList call. Do we care?
190195
def term[_: P]: P[RegexC[Unit]] = P(factor.rep(0).map(_.toList.sequence_))
@@ -193,12 +198,13 @@ object Parser {
193198
* A parser for a regular expression. You probably want to use [[regexExpr]] instead, as this
194199
* parser will succeed even if there are trailing characters after a valid regular expression.
195200
*/
196-
def regex[_: P]: P[RegexC[Unit]] = P(
197-
term.flatMap { r1 =>
198-
("|" ~/ regex).map(r2 => r1 | r2) |
199-
Pass(r1)
200-
}
201-
)
201+
def regex[_: P]: P[RegexC[Unit]] =
202+
P(
203+
term.flatMap { r1 =>
204+
("|" ~/ regex).map(r2 => r1 | r2) |
205+
Pass(r1)
206+
}
207+
)
202208

203209
/**
204210
* A parser for strings that are complete regular expressions, up until the end of the string.

regex-gen/src/main/scala/CharRegexGen.scala

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ object CharRegexGen {
2626
def genAsciiRegex[Out: Arbitrary: Cogen]: Gen[RegexC[Out]] =
2727
RegexGen.genRegex[Char, Out](RegexGen.Config.fromDiscreteDiet(CharacterClasses.ascii))
2828

29-
def genStandardCharRegex[Out: Arbitrary: Cogen]: Gen[RegexC[Out]] = Gen.frequency(
30-
5 -> genAsciiRegex[Out],
31-
4 -> genAlphaNumRegex[Out],
32-
1 -> genSupportedCharRegex[Out]
33-
)
29+
def genStandardCharRegex[Out: Arbitrary: Cogen]: Gen[RegexC[Out]] =
30+
Gen.frequency(
31+
5 -> genAsciiRegex[Out],
32+
4 -> genAlphaNumRegex[Out],
33+
1 -> genSupportedCharRegex[Out]
34+
)
3435

3536
val genSupportedChars: Gen[Char] = dietMatchingGen(supportedCharacters)
3637

regex-gen/src/main/scala/DietGen.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ object DietGen {
1515
Gen.nonEmptyListOf(genA).map(_.foldMap(Diet.one(_)))
1616
}
1717

18-
def weightedDietMatchingGen[A](diet: Diet[A], weight: Range[A] => Int)(
19-
implicit chooseA: Choose[A]): Gen[A] =
18+
def weightedDietMatchingGen[A](diet: Diet[A], weight: Range[A] => Int)(implicit
19+
chooseA: Choose[A]): Gen[A] =
2020
genWeightedDietRange(diet, weight).flatMap(range => Gen.choose(range.start, range.end))
2121

2222
def dietMatchingGen[A: Choose](diet: Diet[A]): Gen[A] = weightedDietMatchingGen[A](diet, _ => 1)

regex-gen/src/main/scala/QuantifierGen.scala

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ object QuantifierGen {
2626
1 -> genRange
2727
)
2828

29-
def genCount(q: Quantifier): Gen[Int] = q match {
30-
case Quantifier.Exact(n) => Gen.const(n)
31-
case Quantifier.Range(min, max, _) =>
32-
Gen.sized(maxSize => Gen.choose(min, max.getOrElse(maxSize)))
33-
case Quantifier.Optional(_) => Gen.choose(0, 1)
34-
}
29+
def genCount(q: Quantifier): Gen[Int] =
30+
q match {
31+
case Quantifier.Exact(n) => Gen.const(n)
32+
case Quantifier.Range(min, max, _) =>
33+
Gen.sized(maxSize => Gen.choose(min, max.getOrElse(maxSize)))
34+
case Quantifier.Optional(_) => Gen.choose(0, 1)
35+
}
3536
}

regex-gen/src/main/scala/RegexAndCandidate.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ object RegexAndCandidate {
5252
Gen.oneOf(probablyNotMatching, genRegexAndMatch[In, Out](cfg, matchToGen))
5353
}
5454

55-
implicit def arbRegexAndCandidate[In, Out](
56-
implicit arbRegex: Arbitrary[RegexM[In, Out]],
55+
implicit def arbRegexAndCandidate[In, Out](implicit
56+
arbRegex: Arbitrary[RegexM[In, Out]],
5757
candidateGen: RegexCandidates[In, Match[In]]): Arbitrary[RegexAndCandidate[In, Out]] =
5858
Arbitrary(
5959
for {

regex-gen/src/main/scala/RegexEq.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import org.scalacheck.rng.Seed
1515
object RegexEq {
1616
private val genSeed: Gen[Seed] = Gen.choose(Long.MinValue, Long.MaxValue).map(Seed(_))
1717

18-
def genRegexEq[In, M](candidateCount: Int)(
19-
implicit rc: RegexCandidates[In, M]): Gen[Eq ~> λ[a => Eq[Regex[In, M, a]]]] =
18+
def genRegexEq[In, M](candidateCount: Int)(implicit
19+
rc: RegexCandidates[In, M]): Gen[Eq ~> λ[a => Eq[Regex[In, M, a]]]] =
2020
Gen.parameterized { params =>
2121
genSeed.map { seed =>
2222
new (Eq ~> λ[a => Eq[Regex[In, M, a]]]) {

regex-gen/src/main/scala/RegexGen.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ object RegexGen {
217217
cogenOut: Cogen[Out])
218218

219219
object GenRegexWithEv {
220-
def fromRegexGen[In, M, Out](regex: Gen[Regex[In, M, Out]])(
221-
implicit arbOut: Arbitrary[Out],
220+
def fromRegexGen[In, M, Out](regex: Gen[Regex[In, M, Out]])(implicit
221+
arbOut: Arbitrary[Out],
222222
cogenOut: Cogen[Out]): GenRegexWithEv[In, M, Out] =
223223
GenRegexWithEv(regex, arbOut.arbitrary, cogenOut)
224224
}
@@ -240,13 +240,12 @@ object RegexGen {
240240
def distributeSumNel(entryCount: Int, extra: Int): Gen[NonEmptyList[Int]] =
241241
if (entryCount < 1)
242242
Gen.fail
243-
else {
243+
else
244244
Gen.listOfN(extra, Gen.choose(0, entryCount - 1)).map { indices =>
245245
val sizes = Array.fill(entryCount)(1)
246246
indices.foreach(i => sizes(i) += 1)
247247
NonEmptyList.fromListUnsafe(sizes.toList)
248248
}
249-
}
250249

251250
// Scalacheck includes an implicit converstion A => Gen[A], and it can cause hard-to-spot bugs
252251
implicit private[irrec] def ambGenConversion1[A](a: A): Gen[A] =

regex-gen/src/main/scala/RegexMatchGen.scala

+11-10
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ import cats.collections.{Diet, Discrete, Range}
1111
import cats.implicits._
1212

1313
object RegexMatchGen {
14-
def dietMatchToGen[A](available: Diet[A], dietToGen: Diet[A] => Gen[A])(
15-
implicit orderA: Order[A],
16-
discreteA: Discrete[A]): Match[A] => Gen[A] = _ match {
17-
case Match.Literal(expected) => Gen.const(expected)
18-
case Match.Wildcard() => dietToGen(available)
19-
case Match.MatchSet.Allow(allowed) => dietToGen(allowed)
20-
case Match.MatchSet.Forbid(forbidden) => dietToGen(available -- forbidden)
21-
}
14+
def dietMatchToGen[A](available: Diet[A], dietToGen: Diet[A] => Gen[A])(implicit
15+
orderA: Order[A],
16+
discreteA: Discrete[A]): Match[A] => Gen[A] =
17+
_ match {
18+
case Match.Literal(expected) => Gen.const(expected)
19+
case Match.Wildcard() => dietToGen(available)
20+
case Match.MatchSet.Allow(allowed) => dietToGen(allowed)
21+
case Match.MatchSet.Forbid(forbidden) => dietToGen(available -- forbidden)
22+
}
2223

2324
val byteMatchingGen: Match[Byte] => Gen[Byte] =
2425
dietMatchToGen(Diet.fromRange(Range(Byte.MinValue, Byte.MaxValue)), dietMatchingGen(_))
@@ -60,7 +61,7 @@ object RegexMatchGen {
6061
available: Diet[In]): RegexM[In, Out] => Gen[Stream[In]] =
6162
regexMatchingStreamGen[In](dietMatchToGen(available, dietMatchingGen(_))).apply
6263

63-
def genRegexMatch[In, M, Out](r: Regex[In, M, Out])(
64-
implicit rc: RegexCandidates[In, M]): Gen[Stream[In]] =
64+
def genRegexMatch[In, M, Out](r: Regex[In, M, Out])(implicit
65+
rc: RegexCandidates[In, M]): Gen[Stream[In]] =
6566
rc.genMatchingStream(r)
6667
}

regex-gen/src/main/scala/TypeWith.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ sealed abstract class TypeWith[Ev[_]] {
1313
object TypeWith {
1414
type Aux[Ev[_], A] = TypeWith[Ev] { type T = A }
1515

16-
def apply[Ev[_], A](implicit ev: Ev[A]): TypeWith[Ev] = new TypeWith[Ev] {
17-
type T = A
18-
def evidence = ev
19-
}
16+
def apply[Ev[_], A](implicit ev: Ev[A]): TypeWith[Ev] =
17+
new TypeWith[Ev] {
18+
type T = A
19+
def evidence = ev
20+
}
2021
}

regex/src/main/scala/Cont.scala

+15-12
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,23 @@ package regex
44
sealed abstract class Cont[+A] extends Product with Serializable {
55
import Cont._
66

7-
def empty: A = this match {
8-
case Single(a) => a
9-
case Choice(whenEmpty, _) => whenEmpty
10-
}
7+
def empty: A =
8+
this match {
9+
case Single(a) => a
10+
case Choice(whenEmpty, _) => whenEmpty
11+
}
1112

12-
def nonEmpty: A = this match {
13-
case Single(a) => a
14-
case Choice(_, whenNonEmpty) => whenNonEmpty
15-
}
13+
def nonEmpty: A =
14+
this match {
15+
case Single(a) => a
16+
case Choice(_, whenNonEmpty) => whenNonEmpty
17+
}
1618

17-
def map[B](f: A => B): Cont[B] = this match {
18-
case Single(value) => Single(f(value))
19-
case Choice(whenEmpty, whenNonEmpty) => Choice(f(whenEmpty), f(whenNonEmpty))
20-
}
19+
def map[B](f: A => B): Cont[B] =
20+
this match {
21+
case Single(value) => Single(f(value))
22+
case Choice(whenEmpty, whenNonEmpty) => Choice(f(whenEmpty), f(whenNonEmpty))
23+
}
2124
}
2225

2326
object Cont {

regex/src/main/scala/Match.scala

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import cats.implicits._
77
sealed abstract class Match[A] extends Product with Serializable {
88
import Match._
99

10-
def matches(a: A)(implicit orderA: Order[A]): Boolean = this match {
11-
case Literal(expected) => a === expected
12-
case MatchSet.Allow(allowed) => allowed.contains(a)
13-
case MatchSet.Forbid(forbidden) => !forbidden.contains(a)
14-
case Wildcard() => true
15-
}
10+
def matches(a: A)(implicit orderA: Order[A]): Boolean =
11+
this match {
12+
case Literal(expected) => a === expected
13+
case MatchSet.Allow(allowed) => allowed.contains(a)
14+
case MatchSet.Forbid(forbidden) => !forbidden.contains(a)
15+
case Wildcard() => true
16+
}
1617
}
1718

1819
object Match {
@@ -38,10 +39,11 @@ object Match {
3839
case (Forbid(x), Forbid(y)) => Forbid(x | y)
3940
}
4041

41-
def negate: MatchSet[A] = this match {
42-
case Allow(x) => Forbid(x)
43-
case Forbid(x) => Allow(x)
44-
}
42+
def negate: MatchSet[A] =
43+
this match {
44+
case Allow(x) => Forbid(x)
45+
case Forbid(x) => Allow(x)
46+
}
4547
}
4648

4749
object MatchSet {

regex/src/main/scala/ParseState.scala

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ final case class ParseState[In, A](queue: StateQueue[Thread[In, A]]) extends Any
2121
}
2222
}
2323

24-
private def addThread(t: Thread[In, A]): ParseState[In, A] = t match {
25-
case Thread.Accept(_) => ParseState(queue.insertWithoutId(t))
26-
case Thread.Cont(id, _) => ParseState(queue.insertUnique(id.asInt, t))
27-
}
24+
private def addThread(t: Thread[In, A]): ParseState[In, A] =
25+
t match {
26+
case Thread.Accept(_) => ParseState(queue.insertWithoutId(t))
27+
case Thread.Cont(id, _) => ParseState(queue.insertUnique(id.asInt, t))
28+
}
2829

2930
def results: List[A] = threads.flatMap(_.result)
3031

@@ -46,8 +47,8 @@ final case class ParseState[In, A](queue: StateQueue[Thread[In, A]]) extends Any
4647
object ParseState {
4748
def empty[In, A]: ParseState[In, A] = ParseState(StateQueue.empty)
4849

49-
def fromThreads[F[_], In, A](threads: F[Thread[In, A]])(
50-
implicit foldableF: Foldable[F]): ParseState[In, A] =
50+
def fromThreads[F[_], In, A](threads: F[Thread[In, A]])(implicit
51+
foldableF: Foldable[F]): ParseState[In, A] =
5152
threads.foldLeft(empty[In, A])(_.addThread(_))
5253

5354
implicit private val indexedSeqFoldable: Foldable[IndexedSeq] =

regex/src/main/scala/Quantifier.scala

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import ceedubs.irrec.regex.Greediness._
55
sealed abstract class Quantifier extends Product with Serializable {
66
import Quantifier._
77

8-
def pprint: String = this match {
9-
case Exact(n) => s"{$n}"
10-
case Range(min, max, g) => s"{$min,${max.getOrElse("")}}${pprintGreediness(g)}"
11-
case Optional(g) => s"?${pprintGreediness(g)}"
12-
}
8+
def pprint: String =
9+
this match {
10+
case Exact(n) => s"{$n}"
11+
case Range(min, max, g) => s"{$min,${max.getOrElse("")}}${pprintGreediness(g)}"
12+
case Optional(g) => s"?${pprintGreediness(g)}"
13+
}
1314
}
1415

1516
object Quantifier {
@@ -18,8 +19,9 @@ object Quantifier {
1819
extends Quantifier
1920
final case class Optional(greediness: Greediness) extends Quantifier
2021

21-
def pprintGreediness(greediness: Greediness): String = greediness match {
22-
case Greedy => ""
23-
case NonGreedy => "?"
24-
}
22+
def pprintGreediness(greediness: Greediness): String =
23+
greediness match {
24+
case Greedy => ""
25+
case NonGreedy => "?"
26+
}
2527
}

0 commit comments

Comments
 (0)