Skip to content

Add support for Scala.js, with cross-compilation. #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ script: admin/build.sh
jdk:
- openjdk6
- openjdk7
- oraclejdk8

notifications:
email:
Expand Down
71 changes: 48 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,24 +1,49 @@

scalaModuleSettings

name := "scala-parser-combinators"

version := "1.1.0-SNAPSHOT"

scalaVersion := crossScalaVersions.value.head

crossScalaVersions := Seq("2.11.6", "2.12.0-M1")

// important!! must come here (why?)
scalaModuleOsgiSettings

OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}")

// needed to fix classloader issues (see scala-xml#20)
fork in Test := true

libraryDependencies += "junit" % "junit" % "4.11" % "test"

libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"

mimaPreviousVersion := None
crossScalaVersions in ThisBuild := {
val javaVersion = System.getProperty("java.version")
val isJDK6Or7 =
javaVersion.startsWith("1.6.") || javaVersion.startsWith("1.7.")
if (isJDK6Or7)
Seq("2.11.7")
else
Seq("2.11.7", "2.12.0-M3")
}

lazy val `scala-parser-combinators` = crossProject.in(file(".")).
settings(scalaModuleSettings: _*).
jvmSettings(
name := "scala-parser-combinators-jvm"
).
jsSettings(
name := "scala-parser-combinators-js"
).
settings(
moduleName := "scala-parser-combinators",
version := "1.1.0-SNAPSHOT",
scalaVersion := crossScalaVersions.value.head
).
jvmSettings(
// important!! must come here (why?)
scalaModuleOsgiSettings: _*
).
jvmSettings(
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}"),

// needed to fix classloader issues (see scala-xml#20)
fork in Test := true
).
jsSettings(
// Scala.js cannot run forked tests
fork in Test := false
).
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)).
jvmSettings(
libraryDependencies += "junit" % "junit" % "4.11" % "test",
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
).
settings(
mimaPreviousVersion := None
)

lazy val `scala-parser-combinatorsJVM` = `scala-parser-combinators`.jvm
lazy val `scala-parser-combinatorsJS` = `scala-parser-combinators`.js
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
addSbtPlugin("org.scala-lang.modules" % "scala-module-plugin" % "1.0.3")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.6")
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ trait JavaTokenParsers extends RegexParsers {
* <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8">The Java Language Spec</a>.
* Generally, this means a letter, followed by zero or more letters or numbers.
*/
def ident: Parser[String] =
"""\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}*""".r
def ident: Parser[String] = (
"" ~> // handle whitespace
rep1(acceptIf(Character.isJavaIdentifierStart)("identifier expected but `" + _ + "' found"),
elem("identifier part", Character.isJavaIdentifierPart(_: Char))) ^^ (_.mkString)
)

/** An integer, without sign or with a negative sign. */
def wholeNumber: Parser[String] =
"""-?\d+""".r
Expand All @@ -49,7 +53,7 @@ trait JavaTokenParsers extends RegexParsers {
*/
@migration("`stringLiteral` allows escaping single and double quotes, but not forward slashes any longer.", "2.10.0")
def stringLiteral: Parser[String] =
("\""+"""([^"\p{Cntrl}\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*+"""+"\"").r
("\""+"""([^"\x00-\x1F\x7F\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*"""+"\"").r
/** A number following the rules of `decimalNumber`, with the following
* optional additions:
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class JavaTokenParsersTest {
case Failure(message, next) =>
assertEquals(next.pos.line, 1)
assertEquals(next.pos.column, 1)
assert(message.endsWith(s"regex `\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*' expected but `-' found"))
assert(message.endsWith(s"identifier expected but `-' found"))
case _ => sys.error(parseResult.toString)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class JsonTest {
assertEquals("{\"name\" : {\"name1\" : \"va1ue1\", \"name2\" : \"va1ue2\"}}",
JSONObject(Map("name" -> JSONObject(TreeMap("name1" -> "va1ue1", "name2" -> "va1ue2")))).toString())

assertEquals("[4.0, 1.0, 3.0, 2.0, 6.0, 5.0, 8.0, 7.0]", JSONArray(List[Double](4,1,3,2,6,5,8,7)).toString())
val expected =
if (1.0.toString == "1") "[4, 1, 3, 2, 6, 5, 8, 7]"
else "[4.0, 1.0, 3.0, 2.0, 6.0, 5.0, 8.0, 7.0]"
assertEquals(expected, JSONArray(List[Double](4,1,3,2,6,5,8,7)).toString())
}

// A test method that escapes all characters in strings
Expand Down