All Downloads are FREE. Search and download functionalities are using the official Maven repository.

izumi.idealingua.il.renderer.RStructure.scala Maven / Gradle / Ivy

The newest version!
package izumi.idealingua.il.renderer

import izumi.functional.Renderable
import izumi.idealingua.model.il.ast.typed.{Structure, Structures, Tuple}

class RStructure(context: IDLRenderingContext) extends Renderable[Structure] {
  import context._

  override def render(structure: Structure): String = {
    Seq(
      renderComposite(structure.superclasses.interfaces, "& "),
      renderComposite(structure.superclasses.concepts, "+ "),
      renderComposite(structure.superclasses.removedConcepts, "- "),
      renderAggregate(structure.fields, ""),
      renderAggregate(structure.removedFields, "- "),
    )
      .filterNot(_.isEmpty)
      .mkString("\n")
  }

  private def renderComposite(aggregate: Structures, prefix: String): String = {
    aggregate
      .map(_.render())
      .map(t => s"$prefix$t")
      .mkString("\n")
  }

  private def renderAggregate(aggregate: Tuple, prefix: String): String = {
    aggregate
      .map(_.render())
      .map(t => s"$prefix$t")
      .mkString("\n")
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy