summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/Parsing.scala
blob: 9e5999ce4f0467d730f6d53182f97cfb81bbfae2 (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
24
25
26
27
28
29
30
31
32
33
34
35
/* NSC -- new Scala compiler
 * Copyright 2005-2014 LAMP/EPFL, Typesafe Inc.
 * @author  Adriaan Moors
 */

package scala
package tools.nsc

import scala.reflect.internal.Positions

/** Similar to Reporting: gather global functionality specific to parsing.
 */
trait Parsing { self : Positions with Reporting =>
  def currentRun: RunParsing

  trait RunParsing {
    val parsing: PerRunParsing = new PerRunParsing
  }

  class PerRunParsing {
    // for repl
    private[this] var incompleteHandler: (Position, String) => Unit = null
    def withIncompleteHandler[T](handler: (Position, String) => Unit)(thunk: => T) = {
      val saved = incompleteHandler
      incompleteHandler = handler
      try thunk
      finally incompleteHandler = saved
    }

    def incompleteHandled = incompleteHandler != null
    def incompleteInputError(pos: Position, msg: String): Unit =
      if (incompleteHandled) incompleteHandler(pos, msg)
      else reporter.error(pos, msg)
  }
}