summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/macros/runtime/Parsers.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/scala/reflect/macros/runtime/Parsers.scala')
-rw-r--r--src/compiler/scala/reflect/macros/runtime/Parsers.scala25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/Parsers.scala b/src/compiler/scala/reflect/macros/runtime/Parsers.scala
new file mode 100644
index 0000000000..6d89b71f39
--- /dev/null
+++ b/src/compiler/scala/reflect/macros/runtime/Parsers.scala
@@ -0,0 +1,25 @@
+package scala.reflect.macros
+package runtime
+
+import language.existentials
+import scala.tools.reflect.ToolBox
+import scala.tools.reflect.ToolBoxError
+
+trait Parsers {
+ self: Context =>
+
+ def parse(code: String): Tree =
+ // todo. provide decent implementation
+ try {
+ import scala.reflect.runtime.{universe => ru}
+ val parsed = ru.rootMirror.mkToolBox().parseExpr(code)
+ val importer = universe.mkImporter(ru)
+ importer.importTree(parsed)
+ } catch {
+ case ToolBoxError(msg, cause) =>
+ throw new ParseError(universe.NoPosition, msg)
+ }
+
+ case class ParseError(val pos: Position, val msg: String) extends Throwable(msg)
+ object ParseError extends ParseErrorExtractor
+} \ No newline at end of file