Add better printers
This commit is contained in:
@@ -1,8 +1,13 @@
|
|||||||
import std/options
|
import std/[
|
||||||
import std/strformat
|
options,
|
||||||
import std/sugar
|
sequtils,
|
||||||
import std/strutils
|
strformat,
|
||||||
import fp/maybe
|
strutils,
|
||||||
|
sugar,
|
||||||
|
]
|
||||||
|
import fp/[
|
||||||
|
maybe,
|
||||||
|
]
|
||||||
|
|
||||||
## Inline Block
|
## Inline Block
|
||||||
type
|
type
|
||||||
@@ -94,30 +99,35 @@ type
|
|||||||
headlineContent*: seq[OrgInlineBlock]
|
headlineContent*: seq[OrgInlineBlock]
|
||||||
headlineChildrenText*: string
|
headlineChildrenText*: string
|
||||||
|
|
||||||
func stringifySpecialFields(x: OrgBlock): string =
|
const INDENT_SIZE = 2;
|
||||||
let specialFields = case x.kind:
|
|
||||||
of orgHeading:
|
|
||||||
&"""level: {x.level}
|
|
||||||
todo: {x.todo}
|
|
||||||
headlineContent: {x.headlineContent}
|
|
||||||
headlineChildrenText: {x.headlineChildrenText}"""
|
|
||||||
else: ""
|
|
||||||
|
|
||||||
specialFields
|
func stringifySpecialFields(x: OrgBlock, indent = 0): string =
|
||||||
.just()
|
(
|
||||||
.notEmpty()
|
case x.kind:
|
||||||
.map(x => x.indent(2))
|
of orgHeading:
|
||||||
.map(x => "\n" & x & "\n")
|
@[
|
||||||
.getOrElse("")
|
("kind", $x.kind, true),
|
||||||
|
("level", $x.level, true),
|
||||||
|
("todo", $x.todo, x.todo.isSome()),
|
||||||
|
("headlineContent", $x.headlineContent, x.headlineContent.len != 0),
|
||||||
|
("headlineChildrenText", $x.headlineChildrenText, x.headlineChildrenText.len != 0),
|
||||||
|
("children", $x.children, true),
|
||||||
|
]
|
||||||
|
else: @[])
|
||||||
|
|
||||||
|
.filter(x => x[2])
|
||||||
|
.map(x => x[0] & ": " & x[1])
|
||||||
|
.join(",\n")
|
||||||
|
|
||||||
proc `$`*(x: OrgBlock): string =
|
proc `$`*(x: OrgBlock, indent = 0): string =
|
||||||
&"""OrgBlock(
|
let fieldIndent = indent + INDENT_SIZE
|
||||||
kind: {x.kind}""" &
|
|
||||||
stringifySpecialFields(x) &
|
@[
|
||||||
&"""
|
"OrgBlock(",
|
||||||
children: {x.children}
|
stringifySpecialFields(x).indent(fieldIndent),
|
||||||
)
|
")",
|
||||||
"""
|
]
|
||||||
|
.join("\n")
|
||||||
|
|
||||||
type
|
type
|
||||||
OrgDocument* = ref object
|
OrgDocument* = ref object
|
||||||
|
|||||||
Reference in New Issue
Block a user