Created
May 2, 2016 20:40
-
-
Save MasseGuillaume/e139b5a88ccf66de896951ee397d8291 to your computer and use it in GitHub Desktop.
sbt second segment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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