diff options
| author | Joey Yakimowich-Payne <jyapayne@gmail.com> | 2020-04-26 09:28:58 -0600 |
|---|---|---|
| committer | genotrance <dev@genotrance.com> | 2020-05-04 16:43:07 -0500 |
| commit | c8c2efdc3054d4f4377a41f6e1894dec4ffd0607 (patch) | |
| tree | db6e93a5ec8502ac6d973af66c81c4beb58847c6 | |
| parent | 4f1464bdfb0545f06edf23b2fc92a72733403a5c (diff) | |
| download | nimterop-c8c2efdc3054d4f4377a41f6e1894dec4ffd0607.tar.gz nimterop-c8c2efdc3054d4f4377a41f6e1894dec4ffd0607.zip | |
Add comments explaining comment node procs
| -rw-r--r-- | nimterop/getters.nim | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/nimterop/getters.nim b/nimterop/getters.nim index 281e3a4..89fde10 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -639,6 +639,8 @@ proc getNameKind*(name: string): tuple[name: string, kind: Kind, recursive: bool result.name = result.name[0 .. ^2] proc getCommentsStr*(gState: State, commentNodes: seq[TSNode]): string = + ## Generate a comment from a set of comment nodes. Comment is guaranteed + ## to be able to be rendered using nim doc if commentNodes.len > 0: result = "::" for commentNode in commentNodes: @@ -650,25 +652,37 @@ proc getPrevCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] = ## section var sibling = node.tsNodePrevNamedSibling() var i = 0 + + # Search for the starting comment up to maxSearch nodes away while not sibling.isNil and i < maxSearch: + # Once a comment is found, find all of the comments right next to + # it so that we can get multiple // style comments while not sibling.isNil and sibling.getName() == "comment": result.add(sibling) sibling = sibling.tsNodePrevNamedSibling() + if sibling.isNil: - result.reverse - return + break + sibling = sibling.tsNodePrevNamedSibling() i += 1 + # reverse the comments because we got them in reverse order result.reverse proc getNextCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] = - ## We only want to search for the next comment node (ie: inline) + ## Searches the next nodes up to maxSearch nodes away for a comment + + # We only want to search for the next comment node (ie: inline) + # but we want to keep the same interface as getPrevCommentNodes, + # so we keep a returned seq but only store one element var sibling = node.tsNodeNextNamedSibling() var i = 0 + # Search for the comment up to maxSearch nodes away while not sibling.isNil and i < maxSearch: if sibling.getName() == "comment": - return @[sibling] + result.add sibling + break sibling = sibling.tsNodeNextNamedSibling() i += 1 |
