Skip to content
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

Build for scala3, scala-native and scala-js #26

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.*
project/project
project/target
target
.idea
.bsp
2 changes: 2 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-Dfile.encoding=UTF-8
-J-Xmx2g
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
1.12.4: https:/xitrum-framework/scaposer/pull/26

* Support Scala 3, scala.js and scala-native
* Remove support for Scala 2.11
* Update scala-parser-combinators to 2.3.0

1.11.1: https:/xitrum-framework/scaposer/pull/22

* Support Scala 12.3
* Support Scala 2.13
* Update scala-parser-combinators from 1.1.1 to 1.1.2

1.11.0:
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ i18n2 will overwrite those in i18n1.
Use with SBT
------------

Supported Scala versions: 2.11-2.13
Supported Scala versions: 2.13-3

build.sbt example:

::

libraryDependencies += "tv.cntt" %% "scaposer" % "1.11.1"
libraryDependencies += "tv.cntt" %% "scaposer" % "1.12.4"

Scaposer is used in `Xitrum web framework <https:/xitrum-framework/xitrum>`_.
76 changes: 64 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,17 +1,69 @@
organization := "tv.cntt"
name := "scaposer"
version := "1.11.1-SNAPSHOT"
lazy val `scaposer` = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.settings(
name := "scaposer",

scalaVersion := "2.13.0"
crossScalaVersions := Seq("2.13.0", "2.12.8", "2.11.12")
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"),
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),

scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked")
javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
libraryDependencies += "org.scala-lang.modules" %%% "scala-parser-combinators" % "2.3.0",

// Scala 2.11+ core does not include scala.util.parsing.combinator
libraryDependencies += "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2"
libraryDependencies += "org.specs2" %%% "specs2-core" % "4.20.3" % Test,
)

libraryDependencies += "org.specs2" %% "specs2-core" % "4.6.0" % "test"
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / crossScalaVersions := Seq(scalaVersion.value, "2.12.18", "3.3.1")

//https:/scala/scala-parser-combinators/issues/197
fork in Test := true
ThisBuild / organization := "io.github.olegych"
ThisBuild / organizationName := "OlegYch"
ThisBuild / organizationHomepage := Some(url("https:/OlegYch"))

ThisBuild / scmInfo := Some(
ScmInfo(
url("https:/OlegYch/scaposer"),
"scm:[email protected]:OlegYch/scaposer.git"
)
)
ThisBuild / developers := List(
Developer(
id = "ngocdaothanh",
name = "Ngoc Dao",
email = "[email protected]",
url = url("https:/ngocdaothanh")
),
Developer(
id = "OlegYch",
name = "Aleh Aleshka",
email = "[email protected]",
url = url("https:/OlegYch")
),
)

ThisBuild / description := "GNU Gettext .po file loader for Scala"
ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/license/mit/"))
ThisBuild / homepage := Some(url("https:/OlegYch/scaposer"))

// Remove all additional repository other than Maven Central from POM
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishMavenStyle := true
ThisBuild / publishTo := sonatypePublishToBundle.value
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"
ThisBuild / sonatypeProfileName := "OlegYch"
ThisBuild / releaseCrossBuild := true

import ReleaseTransformations._
ThisBuild / versionScheme := Some("early-semver")
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
runClean,
runTest,
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("+publishSigned"),
releaseStepCommand("sonatypeBundleRelease"),
setNextVersion,
commitNextVersion,
pushChanges
)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.18
sbt.version=1.9.7
10 changes: 8 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
// Run sbt eclipse to create Eclipse project file
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.14.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.16")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0")
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ case class I18n(ctxSingularToStrs: Map[(String, String), Seq[String]]) {
} else {
pluralFormso.map { expr =>
PluralIndexExpressionParser(expr) match {
case PluralIndexExpressionParser.Success(result, _) => x: Long => result(x).toInt
case PluralIndexExpressionParser.Success(result, _) => (x: Long) => result(x).toInt
case failure: PluralIndexExpressionParser.NoSuccess => fallbackPluralFormEvaluator _
}
}.getOrElse(fallbackPluralFormEvaluator _)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private class Parser extends JavaTokenParsers {
* `b`, `f`, `n`, `r` or `t`.
* - `\` followed by `u` followed by four hexadecimal digits
*/
private val reStringLiteral: Parser[String] =
private val reStringLiteral: this.Parser[String] =
("\""+"""((\\\")|\p{Space}|\\u[a-fA-F0-9]{4}|[^"\p{Cntrl}\\]|\\[\\/bfnrt])*"""+"\"").r

// Scala regex is single line by default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import scala.util.parsing.combinator.RegexParsers

object PluralIndexExpressionParser extends RegexParsers {
private def wholeExpr = nplurals ~ assign ~ integerConst ~ endExpr ~ plural ~ assign ~ subexpr ~ endExpr ^^ {
case _ ~ _ ~ maxIndex ~ _ ~ _ ~ _ ~ f ~ _ => x: Long => Math.min(f(Math.max(x, 0L)), maxIndex)
case _ ~ _ ~ maxIndex ~ _ ~ _ ~ _ ~ f ~ _ => (x: Long) => Math.min(f(Math.max(x, 0L)), maxIndex)
}

def apply(input: String): ParseResult[Long => Long] = parseAll(wholeExpr, input)

final private val assign = "="
final private val equals = "=="
final private val equals_ = "=="
final private val notEquals = "!="
final private val greater = ">"
final private val less = "<"
Expand All @@ -36,13 +36,13 @@ object PluralIndexExpressionParser extends RegexParsers {
final private val endExpr = ";"

private def number = """\d+""".r ^^ { str =>
x: Long => str.toLong
(x: Long) => str.toLong
}

private def integerConst = """\d+""".r ^^ (_.toInt)

private def n = "n" ^^ { _ =>
x: Long => x.toLong
(x: Long) => x.toLong
}

private def subexpr = ternary | logicToNumber | expr
Expand All @@ -51,44 +51,44 @@ object PluralIndexExpressionParser extends RegexParsers {

private def term: Parser[Long => Long] = value ~ rep(multuply ~ value | divide ~ value | mod ~ value) ^^ {
case number ~ list => list.foldLeft(number) {
case (x, `multuply` ~ y) => t: Long => x(t) * y(t)
case (x, `divide` ~ y) => t: Long => x(t) / y(t)
case (x, `mod` ~ y) => t: Long => x(t) % y(t)
case (x, `multuply` ~ y) => (t: Long) => x(t) * y(t)
case (x, `divide` ~ y) => (t: Long) => x(t) / y(t)
case (x, `mod` ~ y) => (t: Long) => x(t) % y(t)
}
}

private def expr: Parser[Long => Long] = term ~ rep(plus ~ term | minus ~ term) ^^ {
case number ~ list => list.foldLeft(number) {
case (x, `plus` ~ y) => t: Long => x(t) + y(t)
case (x, `minus` ~ y) => t: Long => x(t) - y(t)
case (x, `plus` ~ y) => (t: Long) => x(t) + y(t)
case (x, `minus` ~ y) => (t: Long) => x(t) - y(t)
}
}

private def compare = expr ~ (greaterOrEquals| lessOrEquals | notEquals | equals | greater | less) ~ expr ^^ {
case a ~ `greaterOrEquals` ~ b => x: Long => a(x) >= b(x)
case a ~ `lessOrEquals` ~ b => x: Long => a(x) <= b(x)
case a ~ `notEquals` ~ b => x: Long => a(x) != b(x)
case a ~ `equals` ~ b => x: Long => a(x) == b(x)
case a ~ `greater` ~ b => x: Long => a(x) > b(x)
case a ~ `less` ~ b => x: Long => a(x) < b(x)
private def compare = expr ~ (greaterOrEquals| lessOrEquals | notEquals | equals_ | greater | less) ~ expr ^^ {
case a ~ `greaterOrEquals` ~ b => (x: Long) => a(x) >= b(x)
case a ~ `lessOrEquals` ~ b => (x: Long) => a(x) <= b(x)
case a ~ `notEquals` ~ b => (x: Long) => a(x) != b(x)
case a ~ `equals_` ~ b => (x: Long) => a(x) == b(x)
case a ~ `greater` ~ b => (x: Long) => a(x) > b(x)
case a ~ `less` ~ b => (x: Long) => a(x) < b(x)
}

private def logic: Parser[Long => Boolean] = (openBrace ~> (logic) <~ closeBrace) | (compare ~ rep(logicalAnd ~ logic | logicalOr ~ logic) ^^ {
case compare ~ list => list.foldLeft(compare) {
case (x, `logicalAnd` ~ y) => t: Long => x(t) && y(t)
case (x, `logicalOr` ~ y) => t: Long => x(t) || y(t)
case (x, `logicalAnd` ~ y) => (t: Long) => x(t) && y(t)
case (x, `logicalOr` ~ y) => (t: Long) => x(t) || y(t)
}
})

private def logicToNumber: Parser[Long => Long] = logic ^^ { x =>
t: Long => if (x(t)) 1 else 0
(t: Long) => if (x(t)) 1 else 0
}

private def negLogic = negation ~ openBrace ~ logic ~ closeBrace ^^ {
case _ ~ _ ~ x ~ _ => t: Long => !x(t)
case _ ~ _ ~ x ~ _ => (t: Long) => !x(t)
}

private def ternary: Parser[Long => Long] = (logic | negLogic) ~ "?" ~ subexpr ~ ":" ~ subexpr ^^ {
case logic ~ _ ~ yes ~ _ ~ no => x: Long => if (logic(x)) yes(x) else no(x)
case logic ~ _ ~ yes ~ _ ~ no => (x: Long) => if (logic(x)) yes(x) else no(x)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ParserSpec extends Specification {

private def getPluralIndexEvaluator(expr: String) = {
PluralIndexExpressionParser(expr.replace(" ", "")).map { f =>
n: Long => f(n).toInt
(n: Long) => f(n).toInt
}.get
}
}
1 change: 1 addition & 0 deletions version.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ThisBuild / version := "1.12.5-SNAPSHOT"