Skip to content
Permalink
Browse files

Update scalafmt to 2.4.2

  • Loading branch information
xuwei-k committed Feb 23, 2020
1 parent 9e751de commit 3f55bd2b41f2ad24fffab4d44c23984f9328d4ca
Showing with 293 additions and 271 deletions.
  1. +1 −1 .scalafmt.conf
  2. +55 −48 build.sbt
  3. +5 −5 examples/src/main/scala/org/parboiled2/examples/Calculator1.scala
  4. +5 −5 examples/src/main/scala/org/parboiled2/examples/Calculator2.scala
  5. +6 −6 examples/src/main/scala/org/parboiled2/examples/CsvParser.scala
  6. +19 −21 examples/src/main/scala/org/parboiled2/examples/JsonParser.scala
  7. +4 −3 parboiled-core/src/main/scala/org/parboiled2/CharPredicate.scala
  8. +9 −3 parboiled-core/src/main/scala/org/parboiled2/Parser.scala
  9. +2 −0 parboiled-core/src/main/scala/org/parboiled2/ParserInput.scala
  10. +1 −0 parboiled-core/src/main/scala/org/parboiled2/RuleDSLActions.scala
  11. +1 −0 parboiled-core/src/main/scala/org/parboiled2/RuleDSLBasics.scala
  12. +1 −0 parboiled-core/src/main/scala/org/parboiled2/RuleDSLCombinators.scala
  13. +2 −0 parboiled-core/src/main/scala/org/parboiled2/support/Lifter.scala
  14. +6 −7 parboiled-core/src/main/scala/org/parboiled2/support/OpTreeContext.scala
  15. +6 −0 parboiled-core/src/main/scala/org/parboiled2/support/RunResult.scala
  16. +3 −0 parboiled-core/src/main/scala/org/parboiled2/support/Unpack.scala
  17. +1 −3 parboiled-core/src/main/scala/org/parboiled2/util/Base64.scala
  18. +26 −28 parboiled-core/src/test/scala/org/parboiled2/ActionSpec.scala
  19. +24 −24 parboiled-core/src/test/scala/org/parboiled2/BasicSpec.scala
  20. +5 −5 parboiled-core/src/test/scala/org/parboiled2/CalculatorSpec.scala
  21. +7 −12 parboiled-core/src/test/scala/org/parboiled2/CharUtilsSpec.scala
  22. +29 −29 parboiled-core/src/test/scala/org/parboiled2/CombinatorSpec.scala
  23. +3 −3 parboiled-core/src/test/scala/org/parboiled2/CustomCharAndStringExpansionSpec.scala
  24. +2 −2 parboiled-core/src/test/scala/org/parboiled2/CutSpec.scala
  25. +13 −13 parboiled-core/src/test/scala/org/parboiled2/DSLTest.scala
  26. +1 −1 parboiled-core/src/test/scala/org/parboiled2/DefaultArgumentsSpec.scala
  27. +12 −12 parboiled-core/src/test/scala/org/parboiled2/ErrorReportingSpec.scala
  28. +4 −4 parboiled-core/src/test/scala/org/parboiled2/MetaRuleSpec.scala
  29. +5 −5 parboiled-core/src/test/scala/org/parboiled2/ReductionTypeSpec.scala
  30. +3 −3 parboiled-core/src/test/scala/org/parboiled2/RunningSpec.scala
  31. +1 −0 parboiled-core/src/test/scala/org/parboiled2/TestParserSpec.scala
  32. +2 −2 parboiled-core/src/test/scala/org/parboiled2/VarianceSpec.scala
  33. +2 −2 parboiled-core/src/test/scala/org/parboiled2/nestedpackage/AlienPackageParserSpec.scala
  34. +1 −0 parboiled-core/src/test/scala/org/parboiled2/util/Base64Spec.scala
  35. +10 −10 parboiled/src/main/scala/org/parboiled2/StringBuilding.scala
  36. +1 −1 parboiled/src/test/scala/org/parboiled2/Base64ParsingSpec.scala
  37. +15 −13 project/ActionOpsBoilerplate.scala
@@ -1,4 +1,4 @@
version = 2.3.2
version = 2.4.2

maxColumn = 120
assumeStandardLibraryStripMargin = true
103 build.sbt
@@ -1,6 +1,6 @@
import ReleaseTransformations._

import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
import sbtcrossproject.CrossPlugin.autoImport._

val commonSettings = Seq(
@@ -10,63 +10,66 @@ val commonSettings = Seq(
startYear := Some(2009),
licenses := Seq("Apache-2.0" -> new URL("http://www.apache.org/licenses/LICENSE-2.0.txt")),
unmanagedResources in Compile += baseDirectory.value.getParentFile.getParentFile / "LICENSE",
scmInfo := Some(ScmInfo(url("https://github.com/sirthias/parboiled2"), "scm:git:git@github.com:sirthias/parboiled2.git")),

scmInfo := Some(
ScmInfo(url("https://github.com/sirthias/parboiled2"), "scm:git:git@github.com:sirthias/parboiled2.git")
),
scalaVersion := "2.12.10",
crossScalaVersions := Seq("2.11.12", "2.12.10", "2.13.1"),

scalacOptions ++= Seq(
"-deprecation",
"-encoding", "UTF-8",
"-encoding",
"UTF-8",
"-feature",
"-language:_",
"-unchecked",
"-Xlint:_,-missing-interpolator",
"-Ywarn-dead-code",
"-Ywarn-dead-code"
//"-Ywarn-numeric-widen",
),
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) => Seq(
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Xfuture",
)
case Some((2, 12)) => Seq(
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-unused:imports,-patvars,-privates,-locals,-implicits,-explicits",
"-Ycache-macro-class-loader:last-modified",
"-Ybackend-parallelism", "8",
"-Xfatal-warnings",
"-Xfuture",
"-Xsource:2.13", // new warning: deprecate assignments in argument position
)
case Some((2, 13)) => Seq(
"-Ywarn-unused:imports,-patvars,-privates,-locals,-implicits,-explicits",
"-Ycache-macro-class-loader:last-modified",
"-Ybackend-parallelism", "8",
)
case Some((2, 11)) =>
Seq(
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Xfuture"
)
case Some((2, 12)) =>
Seq(
"-Yno-adapted-args",
"-Ywarn-inaccessible",
"-Ywarn-infer-any",
"-Ywarn-nullary-override",
"-Ywarn-nullary-unit",
"-Ywarn-unused:imports,-patvars,-privates,-locals,-implicits,-explicits",
"-Ycache-macro-class-loader:last-modified",
"-Ybackend-parallelism",
"8",
"-Xfatal-warnings",
"-Xfuture",
"-Xsource:2.13" // new warning: deprecate assignments in argument position
)
case Some((2, 13)) =>
Seq(
"-Ywarn-unused:imports,-patvars,-privates,-locals,-implicits,-explicits",
"-Ycache-macro-class-loader:last-modified",
"-Ybackend-parallelism",
"8"
)
case x => sys.error(s"unsupported scala version: $x")
}
},

scalacOptions in (Compile, console) ~= (_ filterNot (o o == "-Ywarn-unused-import" || o == "-Xfatal-warnings")),
scalacOptions in (Test, console) ~= (_ filterNot (o o == "-Ywarn-unused-import" || o == "-Xfatal-warnings")),
scalacOptions in (Compile, doc) += "-no-link-warnings",
sourcesInBase := false,

// file headers
headerLicense := Some(HeaderLicense.ALv2("2009-2019", "Mathias Doenitz")),

// reformat main and test sources on compile
scalafmtOnCompile := true,
scalafmtOnCompile := true
)

lazy val crossSettings = Seq(
@@ -136,10 +139,10 @@ val utestVersion = Def.setting(
}
)

val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.3" % "compile")
val utest = Def.setting("com.lihaoyi" %%% "utest" % utestVersion.value % Test)
val scalaCheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.14.3" % Test)
val `scala-reflect` = Def.setting("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")
val shapeless = Def.setting("com.chuusai" %%% "shapeless" % "2.3.3" % "compile")
val utest = Def.setting("com.lihaoyi" %%% "utest" % utestVersion.value % Test)
val scalaCheck = Def.setting("org.scalacheck" %%% "scalacheck" % "1.14.3" % Test)
val `scala-reflect` = Def.setting("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")

// since ScalaCheck native is not available from the original authors @lolgab made a release
// see https://github.com/rickynils/scalacheck/issues/396#issuecomment-467782592
@@ -152,15 +155,16 @@ val `spray-json` = "io.spray" %% "spray-json" % "1.3.5"

/////////////////////// PROJECTS /////////////////////////

lazy val root = project.in(file("."))
lazy val root = project
.in(file("."))
.aggregate(examples, jsonBenchmark)
.aggregate(parboiledJVM, parboiledJS)
.aggregate(parboiledCoreJVM, parboiledCoreJS)
.settings(commonSettings)
.settings(publishingSettings)
.settings(releaseSettings)
.settings(
publishArtifact := false,
publishArtifact := false
)

lazy val examples = project
@@ -181,7 +185,8 @@ lazy val jsonBenchmark = project
.settings(publishArtifact := false)
.settings(
libraryDependencies ++= Seq(`json4s-native`, `json4s-jackson`),
bench := (run in Compile).partialInput(" -i 10 -wi 10 -f1 -t1").evaluated)
bench := (run in Compile).partialInput(" -i 10 -wi 10 -f1 -t1").evaluated
)

lazy val scalaParser = project
.enablePlugins(AutomateHeaderPlugin)
@@ -191,9 +196,10 @@ lazy val scalaParser = project
.settings(libraryDependencies ++= Seq(shapeless.value, utest.value))
.settings(utestSettings)

lazy val parboiledJVM = parboiled.jvm
lazy val parboiledJS = parboiled.js
lazy val parboiledJVM = parboiled.jvm
lazy val parboiledJS = parboiled.js
lazy val parboiledNative = parboiled.native

lazy val parboiled = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.enablePlugins(AutomateHeaderPlugin, SbtOsgi)
@@ -224,7 +230,7 @@ lazy val parboiled = crossProject(JSPlatform, JVMPlatform, NativePlatform)
libraryDependencies ++= Seq(`scala-reflect`.value, shapeless.value, utest.value),
mappings in (Compile, packageBin) ~= (_.groupBy(_._2).toSeq.map(_._2.head)), // filter duplicate outputs
mappings in (Compile, packageDoc) ~= (_.groupBy(_._2).toSeq.map(_._2.head)), // filter duplicate outputs
pomPostProcess := { // we need to remove the dependency onto the parboiledCore module from the POM
pomPostProcess := { // we need to remove the dependency onto the parboiledCore module from the POM
import scala.xml.transform._
import scala.xml.{NodeSeq, Node => XNode}

@@ -237,9 +243,10 @@ lazy val parboiled = crossProject(JSPlatform, JVMPlatform, NativePlatform)

lazy val generateActionOps = taskKey[Seq[File]]("Generates the ActionOps boilerplate source file")

lazy val parboiledCoreJVM = parboiledCore.jvm
lazy val parboiledCoreJS = parboiledCore.js
lazy val parboiledCoreJVM = parboiledCore.jvm
lazy val parboiledCoreJS = parboiledCore.js
lazy val parboiledCoreNative = parboiledCore.native

lazy val parboiledCore = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("parboiled-core"))
@@ -49,7 +49,7 @@ object Calculator1 extends App {
* the parsing run with the help of the value stack.
*/
class Calculator1(val input: ParserInput) extends Parser {
def InputLine = rule { Expression ~ EOI }
def InputLine = rule(Expression ~ EOI)

def Expression: Rule1[Int] = rule {
Term ~ zeroOrMore(
@@ -65,11 +65,11 @@ class Calculator1(val input: ParserInput) extends Parser {
)
}

def Factor = rule { Number | Parens }
def Factor = rule(Number | Parens)

def Parens = rule { '(' ~ Expression ~ ')' }
def Parens = rule('(' ~ Expression ~ ')')

def Number = rule { capture(Digits) ~> (_.toInt) }
def Number = rule(capture(Digits) ~> (_.toInt))

def Digits = rule { oneOrMore(CharPredicate.Digit) }
def Digits = rule(oneOrMore(CharPredicate.Digit))
}
@@ -68,7 +68,7 @@ object Calculator2 extends App {
class Calculator2(val input: ParserInput) extends Parser {
import Calculator2._

def InputLine = rule { Expression ~ EOI }
def InputLine = rule(Expression ~ EOI)

def Expression: Rule1[Expr] = rule {
Term ~ zeroOrMore(
@@ -84,11 +84,11 @@ class Calculator2(val input: ParserInput) extends Parser {
)
}

def Factor = rule { Number | Parens }
def Factor = rule(Number | Parens)

def Parens = rule { '(' ~ Expression ~ ')' }
def Parens = rule('(' ~ Expression ~ ')')

def Number = rule { capture(Digits) ~> Value }
def Number = rule(capture(Digits) ~> Value)

def Digits = rule { oneOrMore(CharPredicate.Digit) }
def Digits = rule(oneOrMore(CharPredicate.Digit))
}
@@ -54,19 +54,19 @@ class CsvParser(val input: ParserInput, headerPresent: Boolean, fieldDelimiter:
.separatedBy(NL) ~ optional(NL) ~ EOI ~> CsvFile
}

def header = rule { record }
def header = rule(record)

def record = rule { oneOrMore(field).separatedBy(fieldDelimiter) ~> Record }
def record = rule(oneOrMore(field).separatedBy(fieldDelimiter) ~> Record)

def field = rule { `quoted-field` | `unquoted-field` }
def field = rule(`quoted-field` | `unquoted-field`)

def `quoted-field` = rule {
OWS ~ '"' ~ clearSB() ~ zeroOrMore((QTEXTDATA | "\"\"") ~ appendSB()) ~ '"' ~ OWS ~ push(sb.toString)
}

def `unquoted-field` = rule { capture(zeroOrMore(TEXTDATA)) }
def `unquoted-field` = rule(capture(zeroOrMore(TEXTDATA)))

def NL = rule { optional('\r') ~ '\n' }
def NL = rule(optional('\r') ~ '\n')

def OWS = rule { zeroOrMore(' ') }
def OWS = rule(zeroOrMore(' '))
}
@@ -29,13 +29,13 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
import JsonParser._

// the root rule
def Json = rule { WhiteSpace ~ Value ~ EOI }
def Json = rule(WhiteSpace ~ Value ~ EOI)

def JsonObject: Rule1[JsObject] = rule {
ws('{') ~ zeroOrMore(Pair).separatedBy(ws(',')) ~ ws('}') ~> ((fields: Seq[JsField]) => JsObject(fields: _*))
}

def Pair = rule { JsonStringUnwrapped ~ ws(':') ~ Value ~> ((_, _)) }
def Pair = rule(JsonStringUnwrapped ~ ws(':') ~ Value ~> ((_, _)))

def Value: Rule1[JsValue] = rule {
// as an optimization of the equivalent rule:
@@ -55,17 +55,17 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
}
}

def JsonString = rule { JsonStringUnwrapped ~> (JsString(_)) }
def JsonString = rule(JsonStringUnwrapped ~> (JsString(_)))

def JsonStringUnwrapped = rule { '"' ~ clearSB() ~ Characters ~ ws('"') ~ push(sb.toString) }
def JsonStringUnwrapped = rule('"' ~ clearSB() ~ Characters ~ ws('"') ~ push(sb.toString))

def JsonNumber = rule { capture(Integer ~ optional(Frac) ~ optional(Exp)) ~> (JsNumber(_)) ~ WhiteSpace }
def JsonNumber = rule(capture(Integer ~ optional(Frac) ~ optional(Exp)) ~> (JsNumber(_)) ~ WhiteSpace)

def JsonArray = rule { ws('[') ~ zeroOrMore(Value).separatedBy(ws(',')) ~ ws(']') ~> (JsArray(_: _*)) }
def JsonArray = rule(ws('[') ~ zeroOrMore(Value).separatedBy(ws(',')) ~ ws(']') ~> (JsArray(_: _*)))

def Characters = rule { zeroOrMore(NormalChar | '\\' ~ EscapedChar) }
def Characters = rule(zeroOrMore(NormalChar | '\\' ~ EscapedChar))

def NormalChar = rule { !QuoteBackslash ~ ANY ~ appendSB() }
def NormalChar = rule(!QuoteBackslash ~ ANY ~ appendSB())

def EscapedChar = rule(
QuoteSlashBackSlash ~ appendSB()
@@ -74,30 +74,28 @@ class JsonParser(val input: ParserInput) extends Parser with StringBuilding {
| 'n' ~ appendSB('\n')
| 'r' ~ appendSB('\r')
| 't' ~ appendSB('\t')
| Unicode ~> { code =>
sb.append(code.asInstanceOf[Char]); ()
}
| Unicode ~> { code => sb.append(code.asInstanceOf[Char]); () }
)

def Unicode = rule { 'u' ~ capture(HexDigit ~ HexDigit ~ HexDigit ~ HexDigit) ~> (java.lang.Integer.parseInt(_, 16)) }
def Unicode = rule('u' ~ capture(HexDigit ~ HexDigit ~ HexDigit ~ HexDigit) ~> (java.lang.Integer.parseInt(_, 16)))

def Integer = rule { optional('-') ~ (Digit19 ~ Digits | Digit) }
def Integer = rule(optional('-') ~ (Digit19 ~ Digits | Digit))

def Digits = rule { oneOrMore(Digit) }
def Digits = rule(oneOrMore(Digit))

def Frac = rule { "." ~ Digits }
def Frac = rule("." ~ Digits)

def Exp = rule { ignoreCase('e') ~ optional(anyOf("+-")) ~ Digits }
def Exp = rule(ignoreCase('e') ~ optional(anyOf("+-")) ~ Digits)

def JsonTrue = rule { "true" ~ WhiteSpace ~ push(JsTrue) }
def JsonTrue = rule("true" ~ WhiteSpace ~ push(JsTrue))

def JsonFalse = rule { "false" ~ WhiteSpace ~ push(JsFalse) }
def JsonFalse = rule("false" ~ WhiteSpace ~ push(JsFalse))

def JsonNull = rule { "null" ~ WhiteSpace ~ push(JsNull) }
def JsonNull = rule("null" ~ WhiteSpace ~ push(JsNull))

def WhiteSpace = rule { zeroOrMore(WhiteSpaceChar) }
def WhiteSpace = rule(zeroOrMore(WhiteSpaceChar))

def ws(c: Char) = rule { c ~ WhiteSpace }
def ws(c: Char) = rule(c ~ WhiteSpace)
}

object JsonParser {
@@ -90,8 +90,10 @@ sealed abstract class CharPredicate extends (Char => Boolean) {

protected def or(that: Char => Boolean): CharPredicate =
from(if (this == Empty) that else c => this(c) || that(c))

protected def and(that: Char => Boolean): CharPredicate =
if (this == Empty) Empty else from(c => this(c) && that(c))

protected def andNot(that: Char => Boolean): CharPredicate =
if (this == Empty) Empty else from(c => this(c) && !that(c))
}
@@ -118,9 +120,7 @@ object CharPredicate {
case x => General(x)
}

def apply(magnets: ApplyMagnet*): CharPredicate = magnets.foldLeft(Empty) { (a, m) =>
a ++ m.predicate
}
def apply(magnets: ApplyMagnet*): CharPredicate = magnets.foldLeft(Empty)((a, m) => a ++ m.predicate)

class ApplyMagnet(val predicate: CharPredicate)

@@ -129,6 +129,7 @@ object CharPredicate {
implicit def fromChar(c: Char): ApplyMagnet = fromChars(c :: Nil)
implicit def fromCharArray(array: Array[Char]): ApplyMagnet = fromChars(array.toIndexedSeq)
implicit def fromString(chars: String): ApplyMagnet = fromChars(chars)

implicit def fromChars(chars: Seq[Char]): ApplyMagnet =
chars match {
case _ if chars.size < 128 & !chars.exists(unmaskable) =>

0 comments on commit 3f55bd2

Please sign in to comment.
You can’t perform that action at this time.