Toolbox function doesn't execute `eval()`ed code

I follow the thread at

practicing compile and execute my customized script. But I notice that I can get the code working in REPL using code similar to that in stackoverflow as below

import scala.reflect.runtime.currentMirror
import scala.tools.reflect.ToolBox
val toolbox = currentMirror.mkToolBox()
import toolbox.u._
val fn = """def foreachline(line: String): String = {println(line); line +"_" }"""  
val tree = toolbox.parse("object W { "+fn+"} ")
val symbol = toolbox.define(tree.asInstanceOf[toolbox.u.ImplDef])
val line = "something along the line"; val x = toolbox.eval(q"$symbol.foreachline($line)")

The code above prints original string and return x: Any = something along the line_ without a problem.

Unfortunately, when I try to translate the logic applying to my real program, I find the line below import scala.reflect.runtime.universe.Quasiquote seems not getting executed even inserting log flag. How to debug this weird situation? (I am sure params passed in containing data not empty seq)

def exec(lines: Seq[String]) {
  log.info(s"${lines.length} lines") // here it prints  there are e.g. 16340 in seq
  import scala.reflect.runtime.currentMirror
  import scala.tools.reflect.ToolBox
  val toolbox = currentMirror.mkToolBox()
  import toolbox.u._
  val fnSymbol = toolbox.define(toolbox.parse(s"""
    object PerLineScript {
      def foreachline(line: String): mypkg.Data = {
        import mypkg._
        import mypkg.DSL._
        val log = org.slf4j.LoggerFactory.getLogger("PerLineScript")
        $content
      }
    }
  """).asInstanceOf[toolbox.u.ImplDef])
  import scala.reflect.runtime.universe.Quasiquote
  // log.info("lines here not printed in log")
  val records = lines.map { line => {
    log.info("Not seen at all. seemingly not getting executed")
    toolbox.eval(q"$fnSymbol.foreachline($line)")
  }}.toSeq.asInstanceOf[Seq[mypkg.Data]]
  log.info("nothing here shown in log")
}

The problem was solved. I found the issue basically relating to the wrong syntax in the script. This raises another question. Are there any functions in ToolBox or some other APIs help check if syntax in the script is valid (after combining with code in ToolBox.parse() function where object definition is defined)? Some problems I encountered without validation:

  1. With the script alone it can’t be compiled because it misses other code block such as object PerLineScript { … }. For instance, scalac complains error: expected class or object definition

  2. When integrating with other third party project, at runtime there is no error or exception will be thrown as if nothing is executed.

In addition, going with scripting because the logic in script is frequently changing. Recompiling with main project is not efficient.

I appreciate any suggestions on this. Thanks.