diff options
author | Den Shabalin <den.shabalin@gmail.com> | 2013-09-06 18:28:44 +0200 |
---|---|---|
committer | Den Shabalin <den.shabalin@gmail.com> | 2013-09-12 12:43:23 +0200 |
commit | 95fe19545d60ae9aa79d2c8d5665c7f3b0cbdb1a (patch) | |
tree | 7848cd767ac44c0e6e5790553d29afac9439a030 /src/compiler/scala/reflect/macros/contexts/Parsers.scala | |
parent | 5607bd137d8a22c6933e3692a4a1626928acf67f (diff) | |
download | scala-95fe19545d60ae9aa79d2c8d5665c7f3b0cbdb1a.tar.gz scala-95fe19545d60ae9aa79d2c8d5665c7f3b0cbdb1a.tar.bz2 scala-95fe19545d60ae9aa79d2c8d5665c7f3b0cbdb1a.zip |
SI-6489 parsing in macros should provide proper positions
1. macro parsing doesn't use toolbox any more but calls parser directly
2. in order for this to work parser has to be refactored to limit
usage of currentUnit and rewire it into parser's local unit
method which might use currentUnit for some parsers but will
user proper unit for UnitParser
3. similar change has to be done to make compilation unit's
reporter overridable
Diffstat (limited to 'src/compiler/scala/reflect/macros/contexts/Parsers.scala')
-rw-r--r-- | src/compiler/scala/reflect/macros/contexts/Parsers.scala | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/src/compiler/scala/reflect/macros/contexts/Parsers.scala b/src/compiler/scala/reflect/macros/contexts/Parsers.scala index 3dab02beba..ae6488b5a8 100644 --- a/src/compiler/scala/reflect/macros/contexts/Parsers.scala +++ b/src/compiler/scala/reflect/macros/contexts/Parsers.scala @@ -1,24 +1,20 @@ package scala.reflect.macros package contexts -import scala.language.existentials -import scala.tools.reflect.ToolBox -import scala.tools.reflect.ToolBoxError +import scala.tools.nsc.reporters.StoreReporter trait Parsers { self: Context => + import global._ - def parse(code: String): Tree = - // todo. provide decent implementation - // see `Typers.typedUseCase` for details - try { - import scala.reflect.runtime.{universe => ru} - val parsed = ru.rootMirror.mkToolBox().parse(code) - val importer = universe.mkImporter(ru) - importer.importTree(parsed) - } catch { - case ToolBoxError(msg, cause) => - // todo. provide a position - throw new ParseException(universe.NoPosition, msg) + def parse(code: String) = { + val sreporter = new StoreReporter() + val unit = new CompilationUnit(newSourceFile(code, "<macro>")) { override def reporter = sreporter } + val parser = newUnitParser(unit) + val tree = gen.mkTreeOrBlock(parser.parseStats()) + sreporter.infos.foreach { + case sreporter.Info(pos, msg, sreporter.ERROR) => throw ParseException(pos, msg) } -} + tree + } +}
\ No newline at end of file |