aboutsummaryrefslogblamecommitdiff
path: root/compiler/test/dotty/tools/dotc/parsing/ParserTest.scala
blob: a89b34512f58c7f4ff9712c3098d7eb00fd6ff4b (plain) (tree)
1
2
3
4
5
6
7
8
9


                   

                         

             
                     
                          
                  
                     
                                          





                                                            





                                        


                                      
                                                 


                                   
                       










                                                              
 
package dotty.tools
package dotc
package parsing

import scala.reflect.io._
import util._
import core._
import scala.io.Codec
import Tokens._, Parsers._
import ast.untpd._
import org.junit.Test
import scala.collection.mutable.ListBuffer

class ParserTest extends DottyTest {

  def parse(name: String): Tree = parse(new PlainFile(name))

  var parsed = 0
  val parsedTrees = new ListBuffer[Tree]

  def reset() = {
    parsed = 0
    parsedTrees.clear()
  }

  def parse(file: PlainFile): Tree = {
    //println("***** parsing " + file)
    val source = new SourceFile(file, Codec.UTF8)
    val parser = new Parser(source)
    val tree = parser.parse()
    parsed += 1
    parsedTrees += tree
    tree
  }

  def parseDir(path: String): Unit = parseDir(Directory(path))

  def parseDir(dir: Directory): Unit = {
    for (f <- dir.files)
      if (f.name.endsWith(".scala")) parse(new PlainFile(f))
    for (d <- dir.dirs)
      parseDir(d.path)
  }
}