summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/macros/contexts/Parsers.scala
blob: 9975bd22a01e2382214e5c79a17506dbaf0d0c52 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package scala.reflect.macros
package contexts

import scala.tools.nsc.reporters.StoreReporter

trait Parsers {
  self: Context =>
  import global._

  def parse(code: String) = {
    val sreporter = new StoreReporter()
    val unit = new CompilationUnit(newSourceFile(code, "<macro>")) {
      override def reporter = sreporter
      override def reporting = new PerRunReporting { override def reporter = sreporter }
    }
    val parser = newUnitParser(unit)
    val tree = gen.mkTreeOrBlock(parser.parseStatsOrPackages())
    sreporter.infos.foreach {
      case sreporter.Info(pos, msg, sreporter.ERROR) => throw ParseException(pos, msg)
    }
    tree
  }
}