Skip to content

Instantly share code, notes, and snippets.

@MasseGuillaume
Created May 2, 2016 20:40
Show Gist options
  • Save MasseGuillaume/e139b5a88ccf66de896951ee397d8291 to your computer and use it in GitHub Desktop.
Save MasseGuillaume/e139b5a88ccf66de896951ee397d8291 to your computer and use it in GitHub Desktop.
sbt second segment
// sbt definition of version
// https://github.com/sbt/sbt/blob/0.13/ivy/src/main/scala/sbt/VersionNumber.scala#L3
case class SecondSegment(
numbers: List[Long],
tags: List[String],
extras: List[String]
) extends Version
// https://github.com/sbt/sbt/blob/0.13/ivy/src/main/scala/sbt/VersionNumber.scala#L40
private val SecondSegmentParser = {
val Numbers = (Number ~ ("." ~ Number).rep).map{ case (h, t) => h :: t.toList}
val Tags = ("-" ~ AnyChar.rep.!).rep.map(_.toList)
val Extras = ("+" ~ AnyChar.rep.!).rep.map(_.toList)
(Numbers ~ Tags ~ Extras).map(
(SecondSegment.apply _).tupled
)
}
def parse(v: String): Version = {
(Start ~ SemanticVersioningParser ~ End).parse(v) match {
case Parsed.Success(vp, _) => vp
case _ => (Start ~ SecondSegmentParser ~ End).parse(v) match {
case Parsed.Success(vp, _) => vp
case _ => InvalidVersion(v)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment