More readable but not perfect parser token pprint

This commit is contained in:
Florian Schroedl
2022-08-09 18:09:13 +02:00
parent e0722edb57
commit 9b0ad40f55

View File

@@ -330,10 +330,14 @@ proc foldBuilder*[T, T2](
# -- Stringifiers
proc `$`*(x: ParserToken): string =
&"""ParserToken(
value: {tokenStringValue(x)},
)"""
func pprint*(x: ParserToken): string =
let str = tokenStringValue(x)
let escapedChar = if str == "\n": "\\n"
else: str
&"""ParserToken("{escapedChar}")
"""
func `$`*(x: ParserToken): string = pprint(x)
const LEFT_HIGHLIGHT_CHAR = ">>"
const RIGHT_HIGHLIGHT_CHAR = "<<"