-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No more quasiquotes, add test for ordering
- Loading branch information
Showing
5 changed files
with
80 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package enumeratum | ||
|
||
import scala.tools.reflect.ToolBox | ||
import java.io.File | ||
|
||
/** | ||
* Eval with bits and pieces stolen from here and there... | ||
*/ | ||
object Eval { | ||
|
||
def apply[A](string: String, | ||
compileOptions: String = s"-cp ${macroToolboxClassPath.mkString(";")}"): A = { | ||
import scala.reflect.runtime.currentMirror | ||
val toolbox = currentMirror.mkToolBox(options = compileOptions) | ||
val tree = toolbox.parse(string) | ||
toolbox.eval(tree).asInstanceOf[A] | ||
} | ||
|
||
def macroToolboxClassPath = { | ||
val paths = Seq( | ||
new java.io.File(s"macros/target/scala-${scalaBinaryVersion}/classes") | ||
) | ||
paths.foreach { p => | ||
if (!p.exists) sys.error(s"output directory ${p.getAbsolutePath} does not exist.") | ||
} | ||
paths.map(_.getAbsolutePath) | ||
} | ||
|
||
def scalaBinaryVersion: String = { | ||
val PreReleasePattern = """.*-(M|RC).*""".r | ||
val Pattern = """(\d+\.\d+)\..*""".r | ||
val SnapshotPattern = """(\d+\.\d+\.\d+)-\d+-\d+-.*""".r | ||
scala.util.Properties.versionNumberString match { | ||
case s @ PreReleasePattern(_) => s | ||
case SnapshotPattern(v) => v + "-SNAPSHOT" | ||
case Pattern(v) => v | ||
case _ => "" | ||
} | ||
} | ||
|
||
} |
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
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