From 9b0ad40f5567bdf447ab4500c6131c32e77331c5 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Tue, 9 Aug 2022 18:09:13 +0200 Subject: [PATCH] More readable but not perfect parser token pprint --- src/parser/parser_types.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/parser/parser_types.nim b/src/parser/parser_types.nim index 78392b2..02bf697 100644 --- a/src/parser/parser_types.nim +++ b/src/parser/parser_types.nim @@ -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 = "<<"