<commit_before>/* NSC -- new Scala compiler
 * Copyright 2005-2013 LAMP/EPFL
 * @author  <NAME>
 */

package scala.tools.nsc
package backend
package js

import java.io.PrintWriter

trait JSPrinters { self: scalajs.JSGlobal =>
  /** Basically copied from scala.reflect.internal.Printers */
  trait JSIndentationManager {
    val out: PrintWriter

    protected var indentMargin = 0
    protected val indentStep = 2
    protected var indentString = "                                        " // 40

    protected def doPrintPositions = settings.Xprintpos.value

    def indent() = indentMargin += indentStep
    def undent() = indentMargin -= indentStep

    def printPosition(tree: js.Tree) = if (doPrintPositions) print(tree.pos.show)

    def println() {
      out.println()
      while (indentMargin > indentString.length())
        indentString += indentString
      if (indentMargin > 0)
        out.write(indentString, 0, indentMargin)
    }

    def printSeq[a](ls: List[a])(printelem: a => Unit)(printsep: => Unit) {
      ls match {
        case List() =>
        case List(x) => printelem(x)
        case x :: rest => printelem(x); printsep; printSeq(rest)(printelem)(printsep)
      }
    }

    def printColumn(ts: List[js.Tree], start: String, sep: String, end: String) {
      print(start); indent; println()
      printSeq(ts){print(_)}{print(sep); println()}; undent; println(); print(end)
    }

    def printRow(ts: List[js.Tree], start: String, sep: String, end: String) {
      print(start); printSeq(ts){print(_)}{print(sep)}; print(end)
    }

    def printRow(ts: List[js.Tree], sep: String) { printRow(ts, "", sep, "") }

    def print(args: Any*): Unit
  }

  class JSTreePrinter(val out: PrintWriter) extends JSIndentationManager {
    def printBlock(tree: js.Tree) {
      tree match {
        case js.Block(_, _) =>
          printTree(tree)
        case _ =>
          printColumn(List(tree), "{", ";", "}")
      }
    }

    def printTree(tree: js.Tree) {
      tree match {
        case js.EmptyTree =>
          print("<empty>")

        // Identifiers

        case js.Ident(name) =>
          print(name)

        // Definitions

        case js.VarDef(ident, js.EmptyTree) =>
          print("var ", ident)

        case js.VarDef(ident, rhs) =>
          print("var ", ident, " = ", rhs)

        case js.FunDef(name, args, body) =>
          print("function ", name)
          printRow(args, "(", ", ", ") ")
          printBlock(body)

        // Statement-only language constructs

        case js.Skip() =>
          print("<skip>")

        case js.Block(stats, expr) =>
          printColumn(stats :+ expr, "{", ";", "}")
<commit_msg>Fixed printing of skip.<commit_after>/* NSC -- new Scala compiler
 * Copyright 2005-2013 LAMP/EPFL
 * @author  <NAME>
 */

package scala.tools.nsc
package backend
package js

import java.io.PrintWriter

trait JSPrinters { self: scalajs.JSGlobal =>
  /** Basically copied from scala.reflect.internal.Printers */
  trait JSIndentationManager {
    val out: PrintWriter

    protected var indentMargin = 0
    protected val indentStep = 2
    protected var indentString = "                                        " // 40

    protected def doPrintPositions = settings.Xprintpos.value

    def indent() = indentMargin += indentStep
    def undent() = indentMargin -= indentStep

    def printPosition(tree: js.Tree) = if (doPrintPositions) print(tree.pos.show)

    def println() {
      out.println()
      while (indentMargin > indentString.length())
        indentString += indentString
      if (indentMargin > 0)
        out.write(indentString, 0, indentMargin)
    }

    def printSeq[a](ls: List[a])(printelem: a => Unit)(printsep: => Unit) {
      ls match {
        case List() =>
        case List(x) => printelem(x)
        case x :: rest => printelem(x); printsep; printSeq(rest)(printelem)(printsep)
      }
    }

    def printColumn(ts: List[js.Tree], start: String, sep: String, end: String) {
      print(start); indent; println()
      printSeq(ts){print(_)}{print(sep); println()}; undent; println(); print(end)
    }

    def printRow(ts: List[js.Tree], start: String, sep: String, end: String) {
      print(start); printSeq(ts){print(_)}{print(sep)}; print(end)
    }

    def printRow(ts: List[js.Tree], sep: String) { printRow(ts, "", sep, "") }

    def print(args: Any*): Unit
  }

  class JSTreePrinter(val out: PrintWriter) extends JSIndentationManager {
    def printBlock(tree: js.Tree) {
      tree match {
        case js.Block(_, _) =>
          printTree(tree)
        case _ =>
          printColumn(List(tree), "{", ";", "}")
      }
    }

    def printTree(tree: js.Tree) {
      tree match {
        case js.EmptyTree =>
          print("<empty>")

        // Identifiers

        case js.Ident(name) =>
          print(name)

        // Definitions

        case js.VarDef(ident, js.EmptyTree) =>
          print("var ", ident)

        case js.VarDef(ident, rhs) =>
          print("var ", ident, " = ", rhs)

        case js.FunDef(name, args, body) =>
          print("function ", name)
          printRow(args, "(", ", ", ") ")
          printBlock(body)

        // Statement-only language constructs

        case js.Skip() =>
          print("/*<skip>*/")

        case js.Block(stats, expr) =>
          printColumn(stats :+ expr, "{", ";", "}")

{'fraction_non_alphanumeric': 0.1444278792396571, 'fraction_numerical': 0.005218039508013418, 'mean_word_length': 2.3564727954971856, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7485117', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1636, 'n_words': 389}