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

Do not lose full type signatures after parsing #24

Merged
merged 6 commits into from
Dec 18, 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
30 changes: 7 additions & 23 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import scala.xml.transform.{RewriteRule, RuleTransformer}

scalaVersion in ThisBuild := "2.11.8"

// TODO The parser combinators lib needs to support multiple Scala/ScalaJS versions to enable this
crossScalaVersions in ThisBuild := Seq("2.11.8", "2.12.1")

val commonSettings = Def.settings(
Expand All @@ -23,7 +22,7 @@ val commonSettings = Def.settings(
"-Xfuture",
"-Xlint",
"-Xfatal-warnings",
"-Ywarn-dead-code",
//"-Ywarn-dead-code",
"-language:implicitConversions",
"-language:higherKinds",
"-language:existentials"
Expand Down Expand Up @@ -119,7 +118,7 @@ lazy val docSettings = Seq(
addMappingsToSiteDir(mappings in (ScalaUnidoc, packageDoc), docsMappingsAPIDir),
ghpagesNoJekyll := false,
git.remoteRepo := "https://github.com/alonsodomin/cron4s.git",
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM, typesJVM),
unidocProjectFilter in (ScalaUnidoc, unidoc) := inProjects(coreJVM),
scalacOptions in (ScalaUnidoc, unidoc) ++= Seq(
"-Xfatal-warnings",
"-doc-source-url", scmInfo.value.get.browseUrl + "/tree/master€{FILE_PATH}.scala",
Expand Down Expand Up @@ -169,8 +168,8 @@ lazy val cron4sJS = (project in file(".js")).
settings(commonJsSettings: _*).
settings(publishSettings).
enablePlugins(ScalaJSPlugin).
aggregate(typesJS, testkitJS, coreJS, testsJS).
dependsOn(typesJS, testkitJS, coreJS, testsJS)
aggregate(coreJS, testkitJS, testsJS).
dependsOn(coreJS, testkitJS, testsJS)

lazy val cron4sJVM = (project in file(".jvm")).
settings(
Expand All @@ -179,8 +178,8 @@ lazy val cron4sJVM = (project in file(".jvm")).
).
settings(commonSettings: _*).
settings(publishSettings).
aggregate(typesJVM, testkitJVM, coreJVM, testsJVM).
dependsOn(typesJVM, testkitJVM, coreJVM, testsJVM)
aggregate(coreJVM, testkitJVM, testsJVM).
dependsOn(coreJVM, testkitJVM, testsJVM)

lazy val docs = project.
enablePlugins(MicrositesPlugin).
Expand All @@ -202,8 +201,7 @@ lazy val core = (crossProject in file("core")).
settings(publishSettings: _*).
settings(Dependencies.core: _*).
jvmSettings(Dependencies.coreJVM: _*).
jvmSettings(mimaSettings("core"): _*).
dependsOn(types)
jvmSettings(mimaSettings("core"): _*)

lazy val coreJS = core.js
lazy val coreJVM = core.jvm
Expand All @@ -223,20 +221,6 @@ lazy val testkit = (crossProject.crossType(CrossType.Pure) in file("testkit")).
lazy val testkitJS = testkit.js
lazy val testkitJVM = testkit.jvm

lazy val types = (crossProject.crossType(CrossType.Pure) in file("types")).
settings(
name := "types",
moduleName := "cron4s-types"
).
settings(commonSettings: _*).
settings(commonJsSettings: _*).
settings(publishSettings: _*).
settings(Dependencies.types: _*).
jvmSettings(mimaSettings("types"): _*)

lazy val typesJS = types.js
lazy val typesJVM = types.jvm

lazy val tests = (crossProject in file("tests")).
settings(
name := "tests",
Expand Down
8 changes: 4 additions & 4 deletions core/js/src/main/scala/cron4s/spi/js/package.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cron4s.spi

import cron4s.CronField
import cron4s.expr.{CronExpr, Expr}
import cron4s.expr.CronExpr
import cron4s.types.IsFieldExpr

import scala.scalajs.js.Date
Expand Down Expand Up @@ -64,9 +64,9 @@ package object js {
}
}

implicit class JSCronExpr(expr: CronExpr) extends ExtendedCronExpr[Date](expr)
implicit class JSExpr[E[_ <: CronField] <: Expr[_], F <: CronField]
implicit class JSCronExpr(expr: CronExpr) extends CronDateTimeOps[Date](expr)
implicit class JSExpr[E[_ <: CronField], F <: CronField]
(expr: E[F])
(implicit ev: IsFieldExpr[E, F])
extends ExtendedExpr[E, F, Date](expr)
extends ExprDateTimeOps[E, F, Date](expr, JsAdapter, ev)
}
6 changes: 3 additions & 3 deletions core/jvm/src/main/scala/cron4s/spi/javatime/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ package object javatime {

}

implicit class Java8CronExpr[DT <: Temporal](expr: CronExpr) extends ExtendedCronExpr[DT](expr)
implicit class Java8Expr[E[_ <: CronField] <: Expr[_], F <: CronField, DT <: Temporal]
implicit class Java8CronExpr[DT <: Temporal](expr: CronExpr) extends CronDateTimeOps[DT](expr)
implicit class Java8Expr[E[_ <: CronField], F <: CronField, DT <: Temporal]
(expr: E[F])
(implicit ev: IsFieldExpr[E, F])
extends ExtendedExpr[E, F, DT](expr)
extends ExprDateTimeOps[E, F, DT](expr, DateTimeAdapter[DT], ev)
}
9 changes: 4 additions & 5 deletions core/jvm/src/main/scala/cron4s/spi/joda/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cron4s.spi
import cron4s.CronField
import cron4s.expr._
import cron4s.types.IsFieldExpr

import org.joda.time.{DateTime, DateTimeFieldType}

import scalaz.Equal
Expand All @@ -14,7 +13,7 @@ import scalaz.Equal
package object joda {
import CronField._

implicit val dateTimeInstance = Equal.equalA[DateTime]
implicit val dateTimeInstance: Equal[DateTime] = Equal.equalA[DateTime]

implicit object JodaTimeAdapter extends DateTimeAdapter[DateTime] {

Expand Down Expand Up @@ -44,9 +43,9 @@ package object joda {
}
}

implicit class JodaCronExpr(expr: CronExpr) extends ExtendedCronExpr[DateTime](expr)
implicit class JodaExpr[E[_ <: CronField] <: Expr[_], F <: CronField]
implicit class JodaCronExpr(expr: CronExpr) extends CronDateTimeOps[DateTime](expr)
implicit class JodaExpr[E[_ <: CronField], F <: CronField]
(expr: E[F])
(implicit ev: IsFieldExpr[E, F])
extends ExtendedExpr[E, F, DateTime](expr)
extends ExprDateTimeOps[E, F, DateTime](expr, JodaTimeAdapter, ev)
}
6 changes: 3 additions & 3 deletions core/shared/src/main/scala/cron4s/CronUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sealed abstract class CronUnit[+F <: CronField] extends Serializable {
*
* @return the range of valid values
*/
def range: IndexedSeq[Int]
def range: Vector[Int]

}

Expand All @@ -43,7 +43,7 @@ private[cron4s] trait CronUnits {
val field: F, val min: Int, val max: Int
) extends CronUnit[F] {

val range: IndexedSeq[Int] = min to max
val range: Vector[Int] = (min to max).toVector

}

Expand All @@ -69,7 +69,7 @@ private[cron4s] trait CronUnitInstances extends CronUnits {

private[this] def hasCronField[F <: CronField](unit: CronUnit[F]): HasCronField[CronUnit, F] =
new HasCronField[CronUnit, F] {
override def range(fL: CronUnit[F]): IndexedSeq[Int] = unit.range
override def range(fL: CronUnit[F]): Vector[Int] = unit.range
}

implicit val secondsInstance = hasCronField(Seconds)
Expand Down
37 changes: 20 additions & 17 deletions core/shared/src/main/scala/cron4s/expr/CronExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ import shapeless._
* @author Antonio Alonso Dominguez
*/
final case class CronExpr(
seconds: SecondExpr,
minutes: MinutesExpr,
hours: HoursExpr,
daysOfMonth: DaysOfMonthExpr,
months: MonthsExpr,
daysOfWeek: DaysOfWeekExpr
seconds: FieldExprAST[CronField.Second],
minutes: FieldExprAST[CronField.Minute],
hours: FieldExprAST[CronField.Hour],
daysOfMonth: FieldExprAST[CronField.DayOfMonth],
months: FieldExprAST[CronField.Month],
daysOfWeek: FieldExprAST[CronField.DayOfWeek]
) {

private[cron4s] lazy val repr: CronExprRepr = Generic[CronExpr].to(this)
private[cron4s] lazy val ast: CronExprAST = Generic[CronExpr].to(this)

/**
* Time part of the CRON expression
*/
lazy val timePart: TimePartExpr = new TimePartExpr(repr.take(3))
lazy val timePart: TimePartExpr = TimePartExpr(seconds, minutes, hours)

/**
* Date part of the CRON expression
*/
lazy val datePart: DatePartExpr = new DatePartExpr(repr.drop(3))
lazy val datePart: DatePartExpr = DatePartExpr(daysOfMonth, months, daysOfWeek)

/**
* Generic field accessor. Given a CronField, this method can be used
Expand All @@ -37,15 +38,17 @@ final case class CronExpr(
* @tparam F CronField type
* @return field-based expression for given field
*/
def field[F <: CronField](implicit unit: CronUnit[F]): Expr[F] = unit.field match {
case CronField.Second => seconds.asInstanceOf[Expr[F]]
case CronField.Minute => minutes.asInstanceOf[Expr[F]]
case CronField.Hour => hours.asInstanceOf[Expr[F]]
case CronField.DayOfMonth => daysOfMonth.asInstanceOf[Expr[F]]
case CronField.Month => months.asInstanceOf[Expr[F]]
case CronField.DayOfWeek => daysOfWeek.asInstanceOf[Expr[F]]
def field[F <: CronField](implicit unit: CronUnit[F]): FieldExprAST[F] = unit.field match {
case CronField.Second => seconds.asInstanceOf[FieldExprAST[F]]
case CronField.Minute => minutes.asInstanceOf[FieldExprAST[F]]
case CronField.Hour => hours.asInstanceOf[FieldExprAST[F]]
case CronField.DayOfMonth => daysOfMonth.asInstanceOf[FieldExprAST[F]]
case CronField.Month => months.asInstanceOf[FieldExprAST[F]]
case CronField.DayOfWeek => daysOfWeek.asInstanceOf[FieldExprAST[F]]
}

override def toString = s"$seconds $minutes $hours $daysOfMonth $months $daysOfWeek"
def ranges: List[Vector[Int]] = ast.map(cron4s.generic.range).toList

override def toString = ast.map(cron4s.generic.show).toList.mkString(" ")

}
Loading