hamzaremmal/amy

View on GitHub
compiler/src/main/scala/amyc/utils/printers/NominalPrinter.scala

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
package amyc.utils.printers

import amyc.ast.NominalTreeModule
import amyc.utils.printers.NominalPrinter.treeModule
import amyc.utils.{Document, Lined, Raw}
import amyc.utils.printers.highlight.NoHighlight


object NominalPrinter extends Printer(NoHighlight) :
  import amyc.ast.NominalTreeModule.*
  val treeModule: NominalTreeModule.type = NominalTreeModule

  implicit def printName(name: Name)(implicit printUniqueIds: Boolean): Document = Raw(name)

  implicit def printQName(name: QualifiedName)(implicit printUniqueIds: Boolean): Document =
    Raw(name match {
      case QualifiedName(Some(module), name) =>
        s"$module.$name"
      case QualifiedName(None, name) =>
        name
    })

  override def printCall(c: treeModule.Call)(implicit printUniqueIDs: Boolean): Document =
    val Call(name, args) = c
    name <:> "(" <:> Lined(args map (toDoc(_)), ", ") <:> ")"