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:
parent
4920b06973
commit
8d2f6bba3a
6 changed files with 205 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue