Skip to content

Commit

Permalink
Merge pull request scala#305 from SethTisue/misc-cleanups
Browse files Browse the repository at this point in the history
misc cleanups, go (nearly) warning-free
  • Loading branch information
SethTisue committed Nov 3, 2020
2 parents 75dd089 + 19cca8f commit de78aff
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 25 deletions.
49 changes: 38 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
import sbtcrossproject.CrossPlugin.autoImport.crossProject
lazy val root = project.in(file("."))
.aggregate(parserCombinatorsJVM, parserCombinatorsJS, parserCombinatorsNative)
.settings(
publish / skip := true,
)

lazy val parserCombinators = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.withoutSuffixFor(JVMPlatform).in(file("."))
.settings(ScalaModulePlugin.scalaModuleSettings)
.jvmSettings(ScalaModulePlugin.scalaModuleOsgiSettings)
.in(file("."))
.settings(
ScalaModulePlugin.scalaModuleSettings,
name := "scala-parser-combinators",
scalaModuleMimaPreviousVersion := None,
scalaModuleMimaPreviousVersion := None, // until we publish 1.2.0

apiMappings ++= scalaInstance.value.libraryJars.collect {
case file if file.getName.startsWith("scala-library") && file.getName.endsWith(".jar") =>
file -> url(s"http://www.scala-lang.org/api/${scalaVersion.value}/")
}.toMap,

scalacOptions in (Compile, doc) ++= {
// go nearly warning-free, but only on 2.13, it's too hard across all versions
Compile / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq("-Werror",
// ideally we'd do something about this. `^?` is the responsible method
"-Wconf:site=scala.util.parsing.combinator.Parsers.*&cat=lint-multiarg-infix:i",
// not sure what resolving this would look like? didn't think about it too hard
"-Wconf:site=scala.util.parsing.combinator.lexical.StdLexical.*&cat=other-match-analysis:i",
)
case _ => Seq()
}),
Compile / doc / scalacOptions ++= (CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => Seq(
// it isn't able to link to [[java.lang.NoSuchMethodError]]
// scala-xml doesn't have this problem, I tried copying their apiMappings stuff
// and that didn't help, I'm mystified why :-/
"""-Wconf:msg=Could not find any member to link for*:i""",
)
case _ => Seq()
}),
Compile / doc / scalacOptions ++= {
if (isDotty.value)
Seq("-language:Scala2")
else
Expand All @@ -22,15 +44,15 @@ lazy val parserCombinators = crossProject(JVMPlatform, JSPlatform, NativePlatfor
"-doc-source-url",
s"https://github.com/scala/scala-parser-combinators/tree/v${version.value}€{FILE_PATH}.scala",
"-sourcepath",
(baseDirectory in LocalRootProject).value.absolutePath,
(LocalRootProject / baseDirectory).value.absolutePath,
"-doc-title",
"Scala Parser Combinators",
"-doc-version",
version.value
)
},
unmanagedSourceDirectories in Compile ++= {
(unmanagedSourceDirectories in Compile).value.map { dir =>
Compile / unmanagedSourceDirectories ++= {
(Compile / unmanagedSourceDirectories).value.map { dir =>
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 13)) => file(dir.getPath ++ "-2.13+")
case Some((0, _)) => file(dir.getPath ++ "-2.13+")
Expand All @@ -40,22 +62,27 @@ lazy val parserCombinators = crossProject(JVMPlatform, JSPlatform, NativePlatfor
}
)
.jvmSettings(
ScalaModulePlugin.scalaModuleOsgiSettings,
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}"),
libraryDependencies += "junit" % "junit" % "4.13.1" % Test,
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % Test
)
.jsSettings(
crossScalaVersions -= "0.27.0-RC1",
// Scala.js cannot run forked tests
fork in Test := false
Test / fork := false
)
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
.nativeSettings(
skip in compile := System.getProperty("java.version").startsWith("1.6") || !scalaVersion.value.startsWith("2.11"),
compile / skip := System.getProperty("java.version").startsWith("1.6") || !scalaVersion.value.startsWith("2.11"),
test := {},
libraryDependencies := {
if (!scalaVersion.value.startsWith("2.11"))
libraryDependencies.value.filterNot(_.organization == "org.scala-native")
else libraryDependencies.value
}
)

lazy val parserCombinatorsJVM = parserCombinators.jvm
lazy val parserCombinatorsJS = parserCombinators.js
lazy val parserCombinatorsNative = parserCombinators.native
16 changes: 8 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@ set -e
# - commit the changes and tag this new revision with an arbitrary suffix after a hash, e.g.,
# `v1.2.3#dotty-0.27` (the suffix is ignored, the version will be `1.2.3`)

# For normal tags that are cross-built, we release on JDK 8 for Scala 2.x
# We release on JDK 8 (for Scala 2.x and Dotty 0.x)
isReleaseJob() {
if [[ "$ADOPTOPENJDK" == "8" && "$TRAVIS_SCALA_VERSION" =~ ^2\.1[01234]\..*$ ]]; then
if [[ "$ADOPTOPENJDK" == "8" ]]; then
true
else
false
fi
}

if [[ "$SCALAJS_VERSION" != "" ]]; then
projectPrefix="parserCombinatorsJS"
projectPrefix="parserCombinatorsJS/"
elif [[ "$SCALANATIVE_VERSION" != "" ]]; then
projectPrefix="parserCombinatorsNative"
projectPrefix="parserCombinatorsNative/"
else
projectPrefix="parserCombinators"
projectPrefix="parserCombinatorsJVM/"
fi

verPat="[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9-]+)?"
Expand All @@ -45,12 +45,12 @@ if [[ "$TRAVIS_TAG" =~ $tagPat ]]; then
fi

# default is +publishSigned; we cross-build with travis jobs, not sbt's crossScalaVersions
export CI_RELEASE="$projectPrefix/publishSigned"
export CI_SNAPSHOT_RELEASE="$projectPrefix/publish"
export CI_RELEASE="${projectPrefix}publishSigned"
export CI_SNAPSHOT_RELEASE="${projectPrefix}publish"

# default is sonatypeBundleRelease, which closes and releases the staging repo
# see https://github.com/xerial/sbt-sonatype#commands
# for now, until we're confident in the new release scripts, just close the staging repo.
export CI_SONATYPE_RELEASE="; sonatypePrepare; sonatypeBundleUpload; sonatypeClose"

sbt clean $projectPrefix/test $projectPrefix/publishLocal $releaseTask
sbt clean ${projectPrefix}test ${projectPrefix}publishLocal $releaseTask
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package scala
package util.parsing.combinator

import scala.annotation.migration
import scala.language.implicitConversions

/** `JavaTokenParsers` differs from [[scala.util.parsing.combinator.RegexParsers]]
* by adding the following definitions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ trait PackratParsers extends Parsers {
*/
private[PackratParsers] val cache = mutable.HashMap.empty[(Parser[_], Position), MemoEntry[_]]

private[PackratParsers] def getFromCache[T](p: Parser[T]): Option[MemoEntry[T]] = {
cache.get((p, pos)).asInstanceOf[Option[MemoEntry[T]]]
private[PackratParsers] def getFromCache[T2](p: Parser[T2]): Option[MemoEntry[T2]] = {
cache.get((p, pos)).asInstanceOf[Option[MemoEntry[T2]]]
}

private[PackratParsers] def updateCacheAndGet[T](p: Parser[T], w: MemoEntry[T]): MemoEntry[T] = {
private[PackratParsers] def updateCacheAndGet[T2](p: Parser[T2], w: MemoEntry[T2]): MemoEntry[T2] = {
cache.put((p, pos),w)
w
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ trait Parsers {
= withFilter(p)

def withFilter(p: T => Boolean): Parser[T]
= Parser{ in => this(in) filterWithError(p, "Input doesn't match filter: "+_, in)}
= Parser{ in => this(in).filterWithError(p, "Input doesn't match filter: "+_, in)}

// no filter yet, dealing with zero is tricky!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package lexical
import token._
import input.CharArrayReader.EofCh
import scala.collection.mutable
import scala.language.implicitConversions

/** This component provides a standard lexical parser for a simple,
* [[http://scala-lang.org Scala]]-like language. It parses keywords and
Expand Down

0 comments on commit de78aff

Please sign in to comment.