From f8cef575b322d9736df369e2a33f5ade7d800f95 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Sat, 27 Oct 2018 09:10:05 -0400 Subject: Improve dumpLisp macro (#9515) * Improve dumpLisp macro - Remove commas from the lisp representation of the AST. - Make the dumpLisp output "pretty" and indented. - Improve docs of `dumpTree` and `dumpLisp` macros. With: dumpLisp: echo "Hello, World!" Output before this commit: StmtList(Command(Ident("echo"), StrLit("Hello, World!"))) Output after this commit: (StmtList (Command (Ident "echo") (StrLit "Hello, World!"))) * Re-use the traverse proc inside treeRepr for lispRepr too - Add module-local `treeTraverse` proc. - Also fix treeRepr/dumpTree not printing nnkCommentStmt node contents. * More doc string updates * Allow unindented lispRepr output for tests * Update a test affected by the lispRepr change * Fix dumpTree * Add note about lispRepr and dumpLisp to changelog [ci skip] --- tests/vm/tnimnode.nim | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/vm/tnimnode.nim b/tests/vm/tnimnode.nim index 4210ab41d..f1c4d5e5a 100644 --- a/tests/vm/tnimnode.nim +++ b/tests/vm/tnimnode.nim @@ -14,7 +14,7 @@ var nodeSeq {.compileTime.} = newSeq[NimNode](2) proc checkNode(arg: NimNode; name: string): void {. compileTime .} = echo "checking ", name - assertEq arg.lispRepr , "StmtList(DiscardStmt(Empty()))" + assertEq arg.lispRepr, """(StmtList (DiscardStmt (Empty)))""" node = arg nodeArray = [arg] @@ -24,12 +24,12 @@ proc checkNode(arg: NimNode; name: string): void {. compileTime .} = seqAppend.add(arg) # bit this creates a copy arg.add newCall(ident"echo", newLit("Hello World")) - assertEq arg.lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident("echo"), StrLit("Hello World")))""" - assertEq node.lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident("echo"), StrLit("Hello World")))""" - assertEq nodeArray[0].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident("echo"), StrLit("Hello World")))""" - assertEq nodeSeq[0].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident("echo"), StrLit("Hello World")))""" - assertEq seqAppend[0].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident("echo"), StrLit("Hello World")))""" - assertEq seqAppend[1].lispRepr , """StmtList(DiscardStmt(Empty()), Call(Ident("echo"), StrLit("Hello World")))""" + assertEq arg.lispRepr, """(StmtList (DiscardStmt (Empty)) (Call (Ident "echo") (StrLit "Hello World")))""" + assertEq node.lispRepr, """(StmtList (DiscardStmt (Empty)) (Call (Ident "echo") (StrLit "Hello World")))""" + assertEq nodeArray[0].lispRepr, """(StmtList (DiscardStmt (Empty)) (Call (Ident "echo") (StrLit "Hello World")))""" + assertEq nodeSeq[0].lispRepr, """(StmtList (DiscardStmt (Empty)) (Call (Ident "echo") (StrLit "Hello World")))""" + assertEq seqAppend[0].lispRepr, """(StmtList (DiscardStmt (Empty)) (Call (Ident "echo") (StrLit "Hello World")))""" + assertEq seqAppend[1].lispRepr, """(StmtList (DiscardStmt (Empty)) (Call (Ident "echo") (StrLit "Hello World")))""" echo "OK" -- cgit 1.4.1-2-gfad0