support same-line doc comments in routines (#18595)

* support same-line comments in routines
* remove assert as per review comment
This commit is contained in:
Timothee Cour 2021-07-27 10:50:59 -07:00 • committed by GitHub
commit 8d2f6bba3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 205 additions and 1 deletions

View file

@ -1795,6 +1795,13 @@ proc parseRoutine(p: var Parser, kind: TNodeKind): PNode =
else:
result.add(p.emptyNode)
indAndComment(p, result, maybeMissEquals)
let body = result[^1]
if body.kind == nkStmtList and body.len > 0 and body[0].comment.len > 0 and body[0].kind != nkCommentStmt:
if result.comment.len == 0:
# proc fn*(a: int): int = a ## foo
# => moves comment `foo` to `fn`
swap(result.comment, body[0].comment)
else: discard # xxx either `assert false` or issue a warning (otherwise we'll never know of this edge case)
proc newCommentStmt(p: var Parser): PNode =
#| commentStmt = COMMENT