Skip to content

Commit 98737a2

Browse files
committed
Add support for Scala.js, with cross-compilation.
Scala versions were upgraded to 2.11.7 and 2.12.0-M3. 2.12 is only used when running the build on JDK8 or later. JavaTokenParsers.identifier was rewritten not to use a regexp, but rather primitive parsers and Character.isJavaIdentifier{Start,Part}. The regexp-based implementation relies on Java-specific character ranges. JavaTokenParsers.stringLiteral was slightly adapted with an expansion of `\p{Cntrl}` into `[\x00-\x1F\x7F]`. The former character range is Java-specific. We also removed an invalid (and useless) `+` at the end of the regexp. The test t4929.scala is JVM-only.
1 parent fd09708 commit 98737a2

40 files changed

+63
-28
lines changed

Diff for: .travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ script: admin/build.sh
1919
jdk:
2020
- openjdk6
2121
- openjdk7
22+
- oraclejdk8
2223

2324
notifications:
2425
email:

Diff for: build.sbt

+48-23
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11

2-
scalaModuleSettings
3-
4-
name := "scala-parser-combinators"
5-
6-
version := "1.1.0-SNAPSHOT"
7-
8-
scalaVersion := crossScalaVersions.value.head
9-
10-
crossScalaVersions := Seq("2.11.6", "2.12.0-M1")
11-
12-
// important!! must come here (why?)
13-
scalaModuleOsgiSettings
14-
15-
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}")
16-
17-
// needed to fix classloader issues (see scala-xml#20)
18-
fork in Test := true
19-
20-
libraryDependencies += "junit" % "junit" % "4.11" % "test"
21-
22-
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
23-
24-
mimaPreviousVersion := None
2+
crossScalaVersions in ThisBuild := {
3+
val javaVersion = System.getProperty("java.version")
4+
val isJDK6Or7 =
5+
javaVersion.startsWith("1.6.") || javaVersion.startsWith("1.7.")
6+
if (isJDK6Or7)
7+
Seq("2.11.7")
8+
else
9+
Seq("2.11.7", "2.12.0-M3")
10+
}
11+
12+
lazy val `scala-parser-combinators` = crossProject.in(file(".")).
13+
settings(scalaModuleSettings: _*).
14+
jvmSettings(
15+
name := "scala-parser-combinators-jvm"
16+
).
17+
jsSettings(
18+
name := "scala-parser-combinators-js"
19+
).
20+
settings(
21+
moduleName := "scala-parser-combinators",
22+
version := "1.1.0-SNAPSHOT",
23+
scalaVersion := crossScalaVersions.value.head
24+
).
25+
jvmSettings(
26+
// important!! must come here (why?)
27+
scalaModuleOsgiSettings: _*
28+
).
29+
jvmSettings(
30+
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}"),
31+
32+
// needed to fix classloader issues (see scala-xml#20)
33+
fork in Test := true
34+
).
35+
jsSettings(
36+
// Scala.js cannot run forked tests
37+
fork in Test := false
38+
).
39+
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)).
40+
jvmSettings(
41+
libraryDependencies += "junit" % "junit" % "4.11" % "test",
42+
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
43+
).
44+
settings(
45+
mimaPreviousVersion := None
46+
)
47+
48+
lazy val `scala-parser-combinatorsJVM` = `scala-parser-combinators`.jvm
49+
lazy val `scala-parser-combinatorsJS` = `scala-parser-combinators`.js

Diff for: project/plugins.sbt

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
addSbtPlugin("org.scala-lang.modules" % "scala-module-plugin" % "1.0.3")
2+
3+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.6")

Diff for: src/main/scala/scala/util/parsing/combinator/JavaTokenParsers.scala renamed to shared/src/main/scala/scala/util/parsing/combinator/JavaTokenParsers.scala

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ trait JavaTokenParsers extends RegexParsers {
2626
* <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8">The Java Language Spec</a>.
2727
* Generally, this means a letter, followed by zero or more letters or numbers.
2828
*/
29-
def ident: Parser[String] =
30-
"""\p{javaJavaIdentifierStart}\p{javaJavaIdentifierPart}*""".r
29+
def ident: Parser[String] = (
30+
"" ~> // handle whitespace
31+
rep1(acceptIf(Character.isJavaIdentifierStart)("identifier expected but `" + _ + "' found"),
32+
elem("identifier part", Character.isJavaIdentifierPart(_: Char))) ^^ (_.mkString)
33+
)
34+
3135
/** An integer, without sign or with a negative sign. */
3236
def wholeNumber: Parser[String] =
3337
"""-?\d+""".r
@@ -49,7 +53,7 @@ trait JavaTokenParsers extends RegexParsers {
4953
*/
5054
@migration("`stringLiteral` allows escaping single and double quotes, but not forward slashes any longer.", "2.10.0")
5155
def stringLiteral: Parser[String] =
52-
("\""+"""([^"\p{Cntrl}\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*+"""+"\"").r
56+
("\""+"""([^"\x00-\x1F\x7F\\]|\\[\\'"bfnrt]|\\u[a-fA-F0-9]{4})*"""+"\"").r
5357
/** A number following the rules of `decimalNumber`, with the following
5458
* optional additions:
5559
*

Diff for: src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala renamed to shared/src/test/scala/scala/util/parsing/combinator/JavaTokenParsersTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class JavaTokenParsersTest {
9797
case Failure(message, next) =>
9898
assertEquals(next.pos.line, 1)
9999
assertEquals(next.pos.column, 1)
100-
assert(message.endsWith(s"regex `\\p{javaJavaIdentifierStart}\\p{javaJavaIdentifierPart}*' expected but `-' found"))
100+
assert(message.endsWith(s"identifier expected but `-' found"))
101101
case _ => sys.error(parseResult.toString)
102102
}
103103

Diff for: src/test/scala/scala/util/parsing/combinator/JsonTest.scala renamed to shared/src/test/scala/scala/util/parsing/combinator/JsonTest.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ class JsonTest {
120120
assertEquals("{\"name\" : {\"name1\" : \"va1ue1\", \"name2\" : \"va1ue2\"}}",
121121
JSONObject(Map("name" -> JSONObject(TreeMap("name1" -> "va1ue1", "name2" -> "va1ue2")))).toString())
122122

123-
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())
123+
val expected =
124+
if (1.0.toString == "1") "[4, 1, 3, 2, 6, 5, 8, 7]"
125+
else "[4.0, 1.0, 3.0, 2.0, 6.0, 5.0, 8.0, 7.0]"
126+
assertEquals(expected, JSONArray(List[Double](4,1,3,2,6,5,8,7)).toString())
124127
}
125128

126129
// A test method that escapes all characters in strings

0 commit comments

Comments
 (0)