diff --git a/src/org/org_types.nim b/src/org/org_types.nim index ec9f47d..90f6347 100644 --- a/src/org/org_types.nim +++ b/src/org/org_types.nim @@ -85,7 +85,9 @@ proc `$`*(x: OrgInlineBlock): string = """ )""" -## Block +## OrgBlock +## -------- + type orgBlockKind* = enum orgHeading @@ -100,7 +102,7 @@ type headlineContent*: seq[OrgInlineBlock] headlineChildrenText*: string -proc `$`*(x: OrgBlock, indent = 0): string = +func pprint*(x: OrgBlock, indent = 0): string = let fieldIndent = indent + INDENT_SIZE let fields = @[ ("kind", $x.kind, true), @@ -119,14 +121,51 @@ proc `$`*(x: OrgBlock, indent = 0): string = ] .join("\n") +func `$`*(x: OrgBlock): string = pprint(x) + +func pprint*(xs: seq[OrgBlock], indent = 0): string = + let fieldIndent = indent + INDENT_SIZE + @[ + "@[", + xs + .mapIt(it.pprint()) + .join(",\n") + .indent(fieldIndent), + "]", + ] + .join("\n") + +func `$`*(xs: seq[OrgBlock]): string = pprint(xs) + +## OrgDocuemnt +## ----------- + type OrgDocument* = ref object children*: seq[OrgBlock] -proc `$`*(x: OrgDocument): string = - &"""OrgDocument( - children: {x.children} -)""" +func pprint*(x: OrgDocument, indent = 0): string = + let fieldIndent = indent + INDENT_SIZE + + let fields = @[ + ("children", $x.children, true), + ] + .stringifyFields() + + @[ + "OrgDocument(", + fields.indent(fieldIndent), + ")", + ] + .join("\n") + +func `$`*(xs: OrgDocument): string = pprint(xs) when isMainModule: - echo OrgBlock(kind: orgHeading) + echo OrgDocument( + children: @[ + OrgBlock(kind: orgHeading), + OrgBlock(kind: orgHeading), + OrgBlock(kind: orgHeading), + ] + )