================================================================================
api/renderDirective
================================================================================

amends ".../snippetTest.pkl"

import "pkl:xml"
import "pkl:jsonnet"
import "pkl:protobuf"

examples {
  for (format, renderer in new Mapping {
    ["pcf"] = new PcfRenderer {}
    ["json"] = new JsonRenderer {}
    ["jsonnet"] = new jsonnet.Renderer {} 
    ["plist"] = new PListRenderer {}
    ["properties"] = new PropertiesRenderer {}
    ["textproto"] = new protobuf.Renderer {}
    ["xml"] = new xml.Renderer {}
    ["yaml"] = new YamlRenderer {}
  }) {
    [format] {
      renderer.renderValue(new RenderDirective { text = "1\"2\n3\t4'" })
      renderer.renderValue(new RenderDirective { text = #"+* /\-;)❌#✅<>"# })
      renderer.renderDocument(new NestedDirectives {
        when (format == "properties") {
          listing = null
          mapping = null
        }
        when (format == "textproto") {
          dynamic = null
        }
      })
      renderer.renderDocument(new RenderDirective { text = #"✅\❌ /-#;)<>"# })
    }
  }
}

local class NestedDirectives {
  directiveProperty: RenderDirective = new { text = #"✅/&\;)*❌"# }
  normalProperty: Int = 42
  dynamic: Dynamic? = new Dynamic {
    foo {
      bar {
        baz = new RenderDirective { text = #"+#✅<;)❌* /\->"# }
      }
      qux = new RenderDirective { text = #"+\✅)❌#-;<* />"# }
    }
  }
  listing: Listing? = new {
    "foo"
    new RenderDirective { text = "💰" }
    "baz"
  }
  mapping: Mapping? = new {
    ["key"] = "value"
    [new RenderDirective { text = "🔑" }] = 42
    ["other"] = new RenderDirective { text = "💰" }
  }
}

--------------------------------------------------------------------------------

(module
  (moduleHeader
    (extendsOrAmendsClause
      (stringConstant)))
  (importClause
    (stringConstant))
  (importClause
    (stringConstant))
  (importClause
    (stringConstant))
  (classProperty
    (identifier)
    (objectBody
      (forGenerator
        (typedIdentifier
          (identifier))
        (typedIdentifier
          (identifier))
        (newExpr
          (type
            (qualifiedIdentifier
              (identifier)))
          (objectBody
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)
                    (identifier)))
                (objectBody)))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody)))))
        (objectBody
          (objectEntry
            (variableExpr
              (identifier))
            (objectBody
              (objectElement
                (methodCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)
                  (argumentList
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectProperty
                          (identifier)
                          (slStringLiteral
                            (escapeSequence)
                            (escapeSequence)
                            (escapeSequence))))))))
              (objectElement
                (methodCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)
                  (argumentList
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectProperty
                          (identifier)
                          (slStringLiteral)))))))
              (objectElement
                (methodCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)
                  (argumentList
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (whenGenerator
                          (binaryExpr
                            (variableExpr
                              (identifier))
                            (slStringLiteral))
                          (objectBody
                            (objectProperty
                              (identifier)
                              (nullLiteral))
                            (objectProperty
                              (identifier)
                              (nullLiteral))))
                        (whenGenerator
                          (binaryExpr
                            (variableExpr
                              (identifier))
                            (slStringLiteral))
                          (objectBody
                            (objectProperty
                              (identifier)
                              (nullLiteral)))))))))
              (objectElement
                (methodCallExpr
                  (variableExpr
                    (identifier))
                  (identifier)
                  (argumentList
                    (newExpr
                      (type
                        (qualifiedIdentifier
                          (identifier)))
                      (objectBody
                        (objectProperty
                          (identifier)
                          (slStringLiteral)))))))))))))
  (clazz
    (modifier)
    (identifier)
    (classBody
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier))))
        (newExpr
          (objectBody
            (objectProperty
              (identifier)
              (slStringLiteral)))))
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (qualifiedIdentifier
              (identifier))))
        (intLiteral))
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (type
              (qualifiedIdentifier
                (identifier)))))
        (newExpr
          (type
            (qualifiedIdentifier
              (identifier)))
          (objectBody
            (objectProperty
              (identifier)
              (objectBody
                (objectProperty
                  (identifier)
                  (objectBody
                    (objectProperty
                      (identifier)
                      (newExpr
                        (type
                          (qualifiedIdentifier
                            (identifier)))
                        (objectBody
                          (objectProperty
                            (identifier)
                            (slStringLiteral)))))))
                (objectProperty
                  (identifier)
                  (newExpr
                    (type
                      (qualifiedIdentifier
                        (identifier)))
                    (objectBody
                      (objectProperty
                        (identifier)
                        (slStringLiteral))))))))))
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (type
              (qualifiedIdentifier
                (identifier)))))
        (newExpr
          (objectBody
            (objectElement
              (slStringLiteral))
            (objectElement
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectProperty
                    (identifier)
                    (slStringLiteral)))))
            (objectElement
              (slStringLiteral)))))
      (classProperty
        (identifier)
        (typeAnnotation
          (type
            (type
              (qualifiedIdentifier
                (identifier)))))
        (newExpr
          (objectBody
            (objectEntry
              (slStringLiteral)
              (slStringLiteral))
            (objectEntry
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectProperty
                    (identifier)
                    (slStringLiteral))))
              (intLiteral))
            (objectEntry
              (slStringLiteral)
              (newExpr
                (type
                  (qualifiedIdentifier
                    (identifier)))
                (objectBody
                  (objectProperty
                    (identifier)
                    (slStringLiteral)))))))))))
