Skip to content

Commit 151ef0d

Browse files
authored
Merge pull request #83 from gourlaysama/backports1
[backport] Scala.js support for 1.0.x
2 parents 6582a95 + ad63597 commit 151ef0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+89
-36
lines changed

build.sbt

+43-20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import com.typesafe.tools.mima.plugin.{MimaPlugin, MimaKeys}
2-
3-
scalaModuleSettings
4-
5-
name := "scala-parser-combinators"
6-
7-
version := "1.0.5-SNAPSHOT"
1+
scalaVersion in ThisBuild := crossScalaVersions.value.head
82

93
crossScalaVersions in ThisBuild := {
104
val javaVersion = System.getProperty("java.version")
@@ -16,16 +10,45 @@ crossScalaVersions in ThisBuild := {
1610
Seq("2.11.7", "2.12.0-M3")
1711
}
1812

19-
// important!! must come here (why?)
20-
scalaModuleOsgiSettings
21-
22-
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}")
23-
24-
// needed to fix classloader issues (see scala-xml#20)
25-
fork in Test := true
26-
27-
libraryDependencies += "junit" % "junit" % "4.11" % "test"
28-
29-
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
30-
31-
mimaPreviousVersion := Some("1.0.2")
13+
lazy val `scala-parser-combinators` = crossProject.in(file(".")).
14+
settings(scalaModuleSettings: _*).
15+
settings(
16+
name := "scala-parser-combinators-root"
17+
).
18+
jvmSettings(
19+
// Mima uses the name of the jvm project in the artifactId
20+
// when resolving previous versions (so no "-jvm" project)
21+
name := "scala-parser-combinators"
22+
).
23+
jsSettings(
24+
name := "scala-parser-combinators-js"
25+
).
26+
settings(
27+
moduleName := "scala-parser-combinators",
28+
version := "1.0.5-SNAPSHOT"
29+
).
30+
jvmSettings(
31+
// important!! must come here (why?)
32+
scalaModuleOsgiSettings: _*
33+
).
34+
jvmSettings(
35+
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}"),
36+
37+
// needed to fix classloader issues (see scala-xml#20)
38+
fork in Test := true
39+
).
40+
jsSettings(
41+
// Scala.js cannot run forked tests
42+
fork in Test := false
43+
).
44+
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)).
45+
jvmSettings(
46+
libraryDependencies += "junit" % "junit" % "4.11" % "test",
47+
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"
48+
).
49+
jvmSettings(
50+
mimaPreviousVersion := Some("1.0.4")
51+
)
52+
53+
lazy val `scala-parser-combinatorsJVM` = `scala-parser-combinators`.jvm
54+
lazy val `scala-parser-combinatorsJS` = `scala-parser-combinators`.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package scala.util.parsing.input
2+
3+
import java.lang.CharSequence
4+
import java.util.{AbstractMap, Collections}
5+
6+
private[input] trait PositionCache {
7+
private[input] lazy val indexCache: java.util.Map[CharSequence,Array[Int]] = new AbstractMap[CharSequence, Array[Int]] {
8+
9+
override def entrySet() = Collections.emptySet()
10+
11+
// the /dev/null of Maps
12+
override def put(ch: CharSequence, a: Array[Int]) = null
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scala.util.parsing.input
2+
3+
import java.lang.{CharSequence, ThreadLocal}
4+
import java.util.WeakHashMap
5+
6+
/**
7+
* @author Tomáš Janoušek
8+
*/
9+
private[input] trait PositionCache {
10+
private lazy val indexCacheTL =
11+
// not DynamicVariable as that would share the map from parent to child :-(
12+
new ThreadLocal[java.util.Map[CharSequence, Array[Int]]] {
13+
override def initialValue = new WeakHashMap[CharSequence, Array[Int]]
14+
}
15+
16+
private[input] def indexCache = indexCacheTL.get
17+
}

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.4")
2+
3+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.6")

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
*

src/main/scala/scala/util/parsing/input/OffsetPosition.scala renamed to shared/src/main/scala/scala/util/parsing/input/OffsetPosition.scala

+1-11
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,5 @@ case class OffsetPosition(source: CharSequence, offset: Int) extends Position {
9191
}
9292

9393
/** An object holding the index cache.
94-
*
95-
* @author Tomáš Janoušek
9694
*/
97-
object OffsetPosition extends scala.runtime.AbstractFunction2[CharSequence,Int,OffsetPosition] {
98-
private lazy val indexCacheTL =
99-
// not DynamicVariable as that would share the map from parent to child :-(
100-
new ThreadLocal[java.util.Map[CharSequence, Array[Int]]] {
101-
override def initialValue = new WeakHashMap[CharSequence, Array[Int]]
102-
}
103-
104-
private def indexCache = indexCacheTL.get
105-
}
95+
object OffsetPosition extends scala.runtime.AbstractFunction2[CharSequence,Int,OffsetPosition] with PositionCache

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

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)