summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
blob: f1bf590ebfe0f929e10bbc75c67404a7d0963c3f (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
36
37
38
39
40
/* NSC -- new Scala compiler
 * Copyright 2005-2013 LAMP/EPFL
 * @author Martin Odersky
 */

package scala.tools.nsc
package ast.parser

import javac._

/** An nsc sub-component.
 */
abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParsers with Scanners with JavaParsers with JavaScanners {

  val phaseName = "parser"

  def newPhase(prev: Phase): StdPhase = new ParserPhase(prev)

  class ParserPhase(prev: scala.tools.nsc.Phase) extends StdPhase(prev) {
    override val checkable = false
    override val keepsTypeParams = false

    def apply(unit: global.CompilationUnit) {
      import global._
      informProgress("parsing " + unit)
      // if the body is already filled in, do nothing
      // otherwise compileLate is going to overwrite bodies of synthetic source files
      if (unit.body == EmptyTree) {
        unit.body =
          if (unit.isJava) new JavaUnitParser(unit).parse()
          else if (reporter.incompleteHandled) new UnitParser(unit).parse()
          else new UnitParser(unit).smartParse()
      }

      if (settings.Yrangepos.value && !reporter.hasErrors)
        validatePositions(unit.body)
    }
  }
}