Creating and setting comment nodes in macros (#5850)

* strVal assingnable comment statement ast nodes
* Set comment instead of strVal for comment nodes
* Added test code for creating and setting comment nodes
* Modified the AST spec documentation for documentation comments
This commit is contained in:
Fredrik Høisæther Rasch 2017-05-31 13:08:08 +02:00 • committed by Andreas Rumpf
commit 6652ae9741
3 changed files with 12 additions and 2 deletions

View file

@ -1406,6 +1406,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
if dest.kind in {nkStrLit..nkTripleStrLit} and if dest.kind in {nkStrLit..nkTripleStrLit} and
regs[rb].kind in {rkNode}: regs[rb].kind in {rkNode}:
dest.strVal = regs[rb].node.strVal dest.strVal = regs[rb].node.strVal
elif dest.kind == nkCommentStmt:
dest.comment = regs[rb].node.strVal
else: else:
stackTrace(c, tos, pc, errFieldXNotFound, "strVal") stackTrace(c, tos, pc, errFieldXNotFound, "strVal")
of opcNNewNimNode: of opcNNewNimNode:

View file

@ -461,8 +461,8 @@ Documentation Comments
---------------------- ----------------------
Double-hash (``##``) comments in the code actually have their own format, Double-hash (``##``) comments in the code actually have their own format,
but the comments do not yet show up in the AST, which will only show that using ``strVal`` to get and set the comment text. Single-hash (``#``)
a comment exists, not what it contains. Single-hash (``#``) comments are ignored. comments are ignored.
Concrete syntax: Concrete syntax:

View file

@ -72,3 +72,11 @@ static:
echo "OK" echo "OK"
static:
echo "testing creation of comment node"
var docComment: NimNode = newNimNode(nnkCommentStmt)
docComment.strVal = "This is a doc comment"
assertEq repr(docComment), "## This is a doc comment"
echo "OK"