Skip to content

Commit

Permalink
Merge pull request circe#251 from scala-steward/update/scalafmt-core-…
Browse files Browse the repository at this point in the history
…2.5.1

Update scalafmt-core to 2.5.1
  • Loading branch information
larsrh committed May 14, 2020
2 parents ae1ed5e + 634f8c0 commit 4c55f25
Show file tree
Hide file tree
Showing 18 changed files with 307 additions and 364 deletions.
6 changes: 3 additions & 3 deletions .scalafmt.conf
@@ -1,10 +1,10 @@
version=2.4.2
version=2.5.1
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses = true
danglingParentheses.preset = true
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers]
docstrings = JavaDoc
align = none
align.preset = none
9 changes: 4 additions & 5 deletions ast/src/main/scala/jawn/ast/JawnFacade.scala
Expand Up @@ -10,11 +10,10 @@ object JawnFacade extends Facade.NoIndexFacade[JValue] {
final def jtrue: JValue = JTrue

final def jnum(s: CharSequence, decIndex: Int, expIndex: Int): JValue =
if (decIndex == -1 && expIndex == -1) {
if (decIndex == -1 && expIndex == -1)
DeferLong(s.toString)
} else {
else
DeferNum(s.toString)
}

final def jstring(s: CharSequence): JValue =
JString(s.toString)
Expand Down Expand Up @@ -42,9 +41,9 @@ object JawnFacade extends Facade.NoIndexFacade[JValue] {
private[this] var key: String = null
private[this] val vs = mutable.TreeMap.empty[String, JValue]
def add(s: CharSequence): Unit =
if (key == null) {
if (key == null)
key = s.toString
} else {
else {
vs(key.toString) = JString(s.toString); key = null
}
def add(v: JValue): Unit = { vs(key) = v; key = null }
Expand Down
5 changes: 2 additions & 3 deletions ast/src/test/scala/jawn/AstTest.scala
Expand Up @@ -64,13 +64,12 @@ class AstTest extends Properties("AstTest") {
}

property(".getBigDecimal") = forAll { (n: BigDecimal) =>
if (Try(BigDecimal(n.toString)) == Success(n)) {
if (Try(BigDecimal(n.toString)) == Success(n))
Claim(
JNum(n.toString).getBigDecimal == Some(n) &&
JParser.parseUnsafe(n.toString).getBigDecimal == Some(n)
)
} else {
else
Claim(true)
}
}
}
5 changes: 2 additions & 3 deletions ast/src/test/scala/jawn/ParseCheck.scala
Expand Up @@ -70,9 +70,8 @@ class AstCheck extends Properties("AstCheck") {
val offsets = percs.map(n => (json.length * n).toInt)
val pairs = offsets.zip(offsets.drop(1))
pairs.map { case (i, j) => json.substring(i, j) }
} else {
} else
json :: Nil
}

def parseSegments(p: AsyncParser[JValue], segments: List[String]): collection.Seq[JValue] =
segments.foldLeft(List.empty[JValue]) { (rs, s) =>
Expand Down Expand Up @@ -132,7 +131,7 @@ class AstCheck extends Properties("AstCheck") {
val M = 1000000
val q = "\""

val s0 = ("x" * (40 * M))
val s0 = "x" * (40 * M)
val e0 = q + s0 + q
val p0: Prop = TestUtil.withTemp(e0)(t => Claim(JParser.parseFromFile(t).filter(_ == JString(s0)).isSuccess))

Expand Down
9 changes: 4 additions & 5 deletions build.sbt
Expand Up @@ -75,11 +75,10 @@ lazy val jawnSettings = Seq(
pomIncludeRepository := Function.const(false),
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value) {
if (isSnapshot.value)
Some("Snapshots".at(nexus + "content/repositories/snapshots"))
} else {
else
Some("Releases".at(nexus + "service/local/staging/deploy/maven2"))
}
},
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
Expand Down Expand Up @@ -115,9 +114,9 @@ lazy val parser = project
.settings(jawnSettings: _*)
.settings(
Test / unmanagedSourceDirectories ++= (
if (isDotty.value) {
if (isDotty.value)
List(baseDirectory.value / "src" / "test" / "dotty")
} else Nil
else Nil
)
)
.disablePlugins(JmhPlugin)
Expand Down
61 changes: 26 additions & 35 deletions parser/src/main/scala/jawn/AsyncParser.scala
Expand Up @@ -173,8 +173,8 @@ final class AsyncParser[J] protected[jawn] (

// we rely on exceptions to tell us when we run out of data
try {
while (true) {
if (state < 0) {
while (true)
if (state < 0)
(at(offset): @switch) match {
case '\n' =>
newline(offset)
Expand All @@ -187,82 +187,74 @@ final class AsyncParser[J] protected[jawn] (
if (state == ASYNC_PRESTART) {
offset += 1
state = ASYNC_START
} else if (state == ASYNC_END) {
} else if (state == ASYNC_END)
die(offset, "expected eof")
} else if (state == ASYNC_POSTVAL) {
else if (state == ASYNC_POSTVAL)
die(offset, "expected , or ]")
} else {
else
state = 0
}

case ',' =>
if (state == ASYNC_POSTVAL) {
offset += 1
state = ASYNC_PREVAL
} else if (state == ASYNC_END) {
} else if (state == ASYNC_END)
die(offset, "expected eof")
} else {
else
die(offset, "expected json value")
}

case ']' =>
if (state == ASYNC_POSTVAL || state == ASYNC_START) {
if (state == ASYNC_POSTVAL || state == ASYNC_START)
if (streamMode > 0) {
offset += 1
state = ASYNC_END
} else {
} else
die(offset, "expected json value or eof")
}
} else if (state == ASYNC_END) {
else if (state == ASYNC_END)
die(offset, "expected eof")
} else {
else
die(offset, "expected json value")
}

case c =>
if (state == ASYNC_END) {
if (state == ASYNC_END)
die(offset, "expected eof")
} else if (state == ASYNC_POSTVAL) {
else if (state == ASYNC_POSTVAL)
die(offset, "expected ] or ,")
} else {
else {
if (state == ASYNC_PRESTART && streamMode > 0) streamMode = -1
state = 0
}
}

} else {
else {
// jump straight back into rparse
offset = reset(offset)
val (value, j) = if (state <= 0) {
parse(offset)
} else {
rparse(state, curr, context, stack)
}
if (streamMode > 0) {
val (value, j) =
if (state <= 0)
parse(offset)
else
rparse(state, curr, context, stack)
if (streamMode > 0)
state = ASYNC_POSTVAL
} else if (streamMode == 0) {
else if (streamMode == 0)
state = ASYNC_PREVAL
} else {
else
state = ASYNC_END
}
curr = j
offset = j
context = null
stack = Nil
results += value
}
}
Right(results)
} catch {
case e: AsyncException =>
if (done) {
if (done)
// if we are done, make sure we ended at a good stopping point
if (state == ASYNC_PREVAL || state == ASYNC_END) Right(results)
else Left(ParseException("exhausted input", -1, -1, -1))
} else {
else
// we ran out of data, so return what we have so far
Right(results)
}

case e: ParseException =>
// we hit a parser error, so return that error and results so far
Expand All @@ -280,9 +272,8 @@ final class AsyncParser[J] protected[jawn] (
pos -= diff
System.arraycopy(data, diff, data, 0, len)
i - diff
} else {
} else
i
}

/**
* We use this to keep track of the last recoverable place we've
Expand Down
25 changes: 12 additions & 13 deletions parser/src/main/scala/jawn/ByteBasedParser.scala
Expand Up @@ -58,17 +58,17 @@ trait ByteBasedParser[J] extends Parser[J] {

var c: Int = byte(j) & 0xff
while (c != 34) { // "
if (c == 92) { // \
if (c == 92) // \
(byte(j + 1): @switch) match {
case 98 => { sb.append('\b'); j += 2 }
case 102 => { sb.append('\f'); j += 2 }
case 110 => { sb.append('\n'); j += 2 }
case 114 => { sb.append('\r'); j += 2 }
case 116 => { sb.append('\t'); j += 2 }
case 98 => sb.append('\b'); j += 2
case 102 => sb.append('\f'); j += 2
case 110 => sb.append('\n'); j += 2
case 114 => sb.append('\r'); j += 2
case 116 => sb.append('\t'); j += 2

case 34 => { sb.append('"'); j += 2 }
case 47 => { sb.append('/'); j += 2 }
case 92 => { sb.append('\\'); j += 2 }
case 34 => sb.append('"'); j += 2
case 47 => sb.append('/'); j += 2
case 92 => sb.append('\\'); j += 2

// if there's a problem then descape will explode
case 117 =>
Expand All @@ -78,9 +78,9 @@ trait ByteBasedParser[J] extends Parser[J] {

case c => die(j, s"invalid escape sequence (\\${c.toChar})", 1)
}
} else if (c < 32) {
else if (c < 32)
die(j, s"control char ($c) in string", 1)
} else if (c < 128) {
else if (c < 128) {
// 1-byte UTF-8 sequence
sb.append(c.toChar)
j += 1
Expand All @@ -96,9 +96,8 @@ trait ByteBasedParser[J] extends Parser[J] {
// 4-byte UTF-8 sequence
sb.append(at(j, j + 4))
j += 4
} else {
} else
die(j, "invalid UTF-8 encoding")
}
c = byte(j) & 0xff
}
ctxt.add(sb.toString, i)
Expand Down
21 changes: 9 additions & 12 deletions parser/src/main/scala/jawn/ChannelParser.scala
Expand Up @@ -18,9 +18,8 @@ object ChannelParser {
fis.read(bytes)
fis.close()
new StringParser[J](new String(bytes, "UTF-8"))
} else {
} else
new ChannelParser[J](new FileInputStream(f).getChannel, bufferSize)
}

def fromChannel[J](ch: ReadableByteChannel, bufferSize: Int = DefaultBufferSize): ChannelParser[J] =
new ChannelParser[J](ch, bufferSize)
Expand All @@ -33,15 +32,14 @@ object ChannelParser {
* or too large to have a valid power of two.
*/
def computeBufferSize(x: Int): Int =
if (x < 0) {
if (x < 0)
throw new IllegalArgumentException(s"negative bufferSize ($x)")
} else if (x > 0x40000000) {
else if (x > 0x40000000)
throw new IllegalArgumentException(s"bufferSize too large ($x)")
} else if (bitCount(x) == 1) {
else if (bitCount(x) == 1)
x
} else {
else
highestOneBit(x) << 1
}
}

/**
Expand Down Expand Up @@ -110,9 +108,8 @@ final class ChannelParser[J](ch: ReadableByteChannel, bufferSize: Int) extends S
nnext = ch.read(ByteBuffer.wrap(next))
pos -= Bufsize
i - Bufsize
} else {
} else
i
}

final protected[this] def checkpoint(state: Int, i: Int, context: FContext[J], stack: List[FContext[J]]): Unit =
()
Expand Down Expand Up @@ -152,11 +149,11 @@ final class ChannelParser[J](ch: ReadableByteChannel, bufferSize: Int) extends S
if (k > Allsize) {
grow()
at(i, k)
} else if (k <= Bufsize) {
} else if (k <= Bufsize)
new String(curr, i, len, utf8)
} else if (i >= Bufsize) {
else if (i >= Bufsize)
new String(next, i - Bufsize, len, utf8)
} else {
else {
val arr = new Array[Byte](len)
val mid = Bufsize - i
System.arraycopy(curr, i, arr, 0, mid)
Expand Down
25 changes: 12 additions & 13 deletions parser/src/main/scala/jawn/CharBasedParser.scala
Expand Up @@ -44,19 +44,19 @@ trait CharBasedParser[J] extends Parser[J] {

var c = at(j)
while (c != '"') {
if (c < ' ') {
if (c < ' ')
die(j, s"control char (${c.toInt}) in string", 1)
} else if (c == '\\') {
else if (c == '\\')
(at(j + 1): @switch) match {
case 'b' => { sb.append('\b'); j += 2 }
case 'f' => { sb.append('\f'); j += 2 }
case 'n' => { sb.append('\n'); j += 2 }
case 'r' => { sb.append('\r'); j += 2 }
case 't' => { sb.append('\t'); j += 2 }
case 'b' => sb.append('\b'); j += 2
case 'f' => sb.append('\f'); j += 2
case 'n' => sb.append('\n'); j += 2
case 'r' => sb.append('\r'); j += 2
case 't' => sb.append('\t'); j += 2

case '"' => { sb.append('"'); j += 2 }
case '/' => { sb.append('/'); j += 2 }
case '\\' => { sb.append('\\'); j += 2 }
case '"' => sb.append('"'); j += 2
case '/' => sb.append('/'); j += 2
case '\\' => sb.append('\\'); j += 2

// if there's a problem then descape will explode
case 'u' =>
Expand All @@ -66,7 +66,7 @@ trait CharBasedParser[J] extends Parser[J] {

case c => die(j, s"illegal escape sequence (\\$c)", 1)
}
} else {
else {
// this case is for "normal" code points that are just one Char.
//
// we don't have to worry about surrogate pairs, since those
Expand Down Expand Up @@ -95,8 +95,7 @@ trait CharBasedParser[J] extends Parser[J] {
if (k != -1) {
ctxt.add(at(i + 1, k - 1), i)
k
} else {
} else
parseStringComplex(i, ctxt)
}
}
}

0 comments on commit 4c55f25

Please sign in to comment.