Skip to content

Commit

Permalink
Introduce file.writeLines
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Oct 10, 2020
1 parent c689f58 commit adc0e01
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ object Main {
def doCompile(sourceFile: Path, compiler: Compiler) = {
val file = CompileFile1(sourceFile, compiler.id)
val res = compiler.compile1(file.src2)
val writeBody = s"// exitCode: ${res.exitCode}" +: res.lines.asScala :+ ""
val allLines = writeBody.init :+ writeBody.last.stripLineEnd
Files.writeString(file.chkPath, allLines.iterator.mkString("\n"))
file.writeLines((s"// exitCode: ${res.exitCode}" +: res.lines.asScala).toList)
res
}

Expand Down Expand Up @@ -127,9 +125,8 @@ object Main {
}

val statusSummary = results.map { case (_, res) => statusPadded(res) }.mkString(" ").trim
val allLines = s"// src: $line" +: lines :+ "" :+ statusSummary :+ ""

Files.writeString(file.chkPath, allLines.iterator.mkString("\n"))
file.writeLines((s"// src: $line" +: lines :+ "" :+ statusSummary).toList)

val lineNo = setup.linesIterator.size + 2 + _idx
println(f"> ${s"$sourceFile:$lineNo"}%-45s ${statusLine(results.map(_._2))}$line%-100s")
Expand Down Expand Up @@ -177,6 +174,11 @@ sealed abstract class CompileFile(src: Path) {
def chkPath: Path

Files.createDirectories(dir)

def writeLines(xs: List[String]) = xs match {
case init :+ last => Files.writeString(chkPath, (init :+ last.stripLineEnd :+ "").mkString("\n"))
case _ => Files.writeString(chkPath, "")
}
}

final case class CompileFile1(src: Path, id: String) extends CompileFile(src) {
Expand Down

0 comments on commit adc0e01

Please sign in to comment.