title: Scala parser cuts last bracket
body: <pre class="lang-scala prettyprint-override"><code>Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_121).
  Type in expressions for evaluation. Or try :help.
  
  scala&gt; :paste
  // Entering paste mode (ctrl-D to finish)
  
  import scala.reflect.runtime._
  import scala.reflect.runtime.universe._
  import scala.tools.reflect.ToolBox
  
  val mirror = universe.runtimeMirror(universe.getClass.getClassLoader)
  val toolbox = mirror.mkToolBox(options = "-Yrangepos")
  val text =
    """
      |libraryDependencies ++= Seq("org.scala-lang" % "scala-compiler" % "2.10.4") map {
      |    (dependency) =&gt;{
      |        dependency
      |    }
      |}
    """.stripMargin
  val parsed = toolbox.parse(text)
  
  val parsedTrees = parsed match {
    case Block(stmt, expr) =&gt;
      stmt :+ expr
    case t: Tree =&gt;
      Seq(t)
  }
  
  val statements = parsedTrees.map { (t: Tree) =&gt;
      text.substring(t.pos.start, t.pos.end)
  }
  
  
  // Exiting paste mode, now interpreting.
  
  import scala.reflect.runtime._
  import scala.reflect.runtime.universe._
  import scala.tools.reflect.ToolBox
  mirror: reflect.runtime.universe.Mirror = JavaMirror with primordial classloader with boot classpath...
  scala&gt; statements.head
  res0: String =
  libraryDependencies ++= Seq("org.scala-lang" % "scala-compiler" % "2.10.4") map {
      (dependency) =&gt;{
          dependency
      }      
  </code></pre>
  
  <p>The result is:
  </p>
  
  <pre><code>scala&gt; statements.head
  res1: String =
  libraryDependencies ++= Seq("org.scala-lang" % "scala-compiler" % "2.10.4") map {
      (dependency) =&gt;{
          dependency
      }
  </code></pre>
  
  <p>I expected:
  </p>
  
  <pre><code>libraryDependencies ++= Seq("org.scala-lang" % "scala-compiler" % "2.10.4") map {
      (dependency) =&gt;{
          dependency
      }
  }
  </code></pre>
  
  <p>The last brackets <code>}</code> (and end of line) is missing if I use position from Tree object: <code>text.substring(t.pos.start, t.pos.end)</code></p>
  
  <p>Any proposal how to extract all text from scala.reflect.api.Trees#Tree object?</p>
  
  <p><strong>Update</strong></p>
  
  <p>Affected scala versions : </p>
  
  <ul>
  <li>2.10.6 - needed for sbt 0.13.x</li>
  <li>2.11.8 </li>
  <li>2.12.7</li>
  </ul>
  
  <p>For scala 2.10.6/2.12.7 result is the same like in above output.</p>
  
  <p><strong>Add project to github</strong></p>
  
  <p><a href="https://github.com/ajozwik/scala-parser" rel="nofollow noreferrer">Example project for searching the solution</a></p>