Extract common block pprint functionality

This commit is contained in:
Florian Schroedl
2022-05-04 17:00:00 +02:00
parent 4c6ca48b8b
commit 4fee450324

View File

@@ -103,7 +103,6 @@ type
headlineChildrenText*: string
func pprint*(x: OrgBlock, indent = 0): string =
let fieldIndent = indent + INDENT_SIZE
let fields = @[
("kind", $x.kind, true),
("level", $x.level, true),
@@ -114,12 +113,11 @@ func pprint*(x: OrgBlock, indent = 0): string =
]
.stringifyFields()
@[
"OrgBlock(",
fields.indent(fieldIndent),
")",
]
.join("\n")
stringifyBlock(
"OrgBlock",
indent,
fields,
)
func `$`*(x: OrgBlock): string = pprint(x)
@@ -136,6 +134,7 @@ func pprint*(xs: seq[OrgBlock], indent = 0): string =
.join("\n")
func `$`*(xs: seq[OrgBlock]): string = pprint(xs)
## OrgDocuemnt
## -----------
@@ -145,19 +144,16 @@ type
children*: seq[OrgBlock]
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")
stringifyBlock(
"OrgDocument",
indent,
fields,
)
func `$`*(xs: OrgDocument): string = pprint(xs)