Use gState.nocomments
This commit is contained in:
parent
c78dfd087c
commit
df3e73e965
2 changed files with 17 additions and 11 deletions
|
|
@ -691,7 +691,7 @@ proc newRecListTree(gState: State, name: string, node: TSNode): PNode =
|
||||||
let
|
let
|
||||||
fdecl = node[i].anyChildInTree("field_declaration_list")
|
fdecl = node[i].anyChildInTree("field_declaration_list")
|
||||||
edecl = node[i].anyChildInTree("enumerator_list")
|
edecl = node[i].anyChildInTree("enumerator_list")
|
||||||
commentNodes = node[i].getNextCommentNodes()
|
commentNodes = gState.getNextCommentNodes(node[i])
|
||||||
|
|
||||||
# `tname` is name of nested struct / union / enum just
|
# `tname` is name of nested struct / union / enum just
|
||||||
# added, passed on as type name for field in `newIdentDefs()`
|
# added, passed on as type name for field in `newIdentDefs()`
|
||||||
|
|
@ -727,7 +727,7 @@ proc addTypeObject(gState: State, node: TSNode, typeDef: PNode = nil, fname = ""
|
||||||
# If `fname` is set, use it as the name when creating new PNode
|
# If `fname` is set, use it as the name when creating new PNode
|
||||||
# If `istype` is set, this is a typedef, else struct/union
|
# If `istype` is set, this is a typedef, else struct/union
|
||||||
decho("addTypeObject()")
|
decho("addTypeObject()")
|
||||||
let commentNodes = node.tsNodeParent().getPrevCommentNodes()
|
let commentNodes = gState.getPrevCommentNodes(node.tsNodeParent())
|
||||||
|
|
||||||
let
|
let
|
||||||
# Object has fields or not
|
# Object has fields or not
|
||||||
|
|
@ -853,7 +853,7 @@ proc addTypeObject(gState: State, node: TSNode, typeDef: PNode = nil, fname = ""
|
||||||
# Current node has fields
|
# Current node has fields
|
||||||
let
|
let
|
||||||
origname = gState.getNodeVal(node.getAtom())
|
origname = gState.getNodeVal(node.getAtom())
|
||||||
commentNodes = node.getNextCommentNodes()
|
commentNodes = gState.getNextCommentNodes(node)
|
||||||
|
|
||||||
# Fix issue #185
|
# Fix issue #185
|
||||||
name =
|
name =
|
||||||
|
|
@ -898,7 +898,7 @@ proc addTypeTyped(gState: State, node: TSNode, ftname = "", offset = 0) =
|
||||||
decho("addTypeTyped()")
|
decho("addTypeTyped()")
|
||||||
let
|
let
|
||||||
start = getStartAtom(node)
|
start = getStartAtom(node)
|
||||||
commentNodes = node.getPrevCommentNodes()
|
commentNodes = gState.getPrevCommentNodes(node)
|
||||||
for i in start+1+offset ..< node.len:
|
for i in start+1+offset ..< node.len:
|
||||||
# Add a type of a specific type
|
# Add a type of a specific type
|
||||||
let
|
let
|
||||||
|
|
@ -1403,7 +1403,7 @@ proc addEnum(gState: State, node: TSNode) =
|
||||||
# nkIdent(name) <- set the comment here
|
# nkIdent(name) <- set the comment here
|
||||||
# )
|
# )
|
||||||
# )
|
# )
|
||||||
defineNode[0][1].comment = gState.getCommentsStr(node.getPrevCommentNodes())
|
defineNode[0][1].comment = gState.getCommentsStr(gState.getPrevCommentNodes(node))
|
||||||
gState.enumSection.add defineNode
|
gState.enumSection.add defineNode
|
||||||
|
|
||||||
# Create const for fields
|
# Create const for fields
|
||||||
|
|
@ -1420,7 +1420,7 @@ proc addEnum(gState: State, node: TSNode) =
|
||||||
|
|
||||||
let
|
let
|
||||||
atom = en.getAtom()
|
atom = en.getAtom()
|
||||||
commentNodes = en.getNextCommentNodes()
|
commentNodes = gState.getNextCommentNodes(en)
|
||||||
fname = gState.getIdentifier(gState.getNodeVal(atom), nskEnumField)
|
fname = gState.getIdentifier(gState.getNodeVal(atom), nskEnumField)
|
||||||
|
|
||||||
if fname.nBl and gState.addNewIdentifer(fname):
|
if fname.nBl and gState.addNewIdentifer(fname):
|
||||||
|
|
@ -1638,7 +1638,7 @@ proc addDecl(gState: State, node: TSNode) =
|
||||||
|
|
||||||
let
|
let
|
||||||
start = getStartAtom(node)
|
start = getStartAtom(node)
|
||||||
commentNodes = node.getPrevCommentNodes()
|
commentNodes = gState.getPrevCommentNodes(node)
|
||||||
|
|
||||||
for i in start+1 ..< node.len:
|
for i in start+1 ..< node.len:
|
||||||
if not node[i].firstChildInTree("function_declarator").isNil:
|
if not node[i].firstChildInTree("function_declarator").isNil:
|
||||||
|
|
@ -1663,7 +1663,7 @@ proc addDef(gState: State, node: TSNode) =
|
||||||
|
|
||||||
let
|
let
|
||||||
start = getStartAtom(node)
|
start = getStartAtom(node)
|
||||||
commentNodes = node.getPrevCommentNodes()
|
commentNodes = gState.getPrevCommentNodes(node)
|
||||||
|
|
||||||
if node[start+1].getName() == "function_declarator":
|
if node[start+1].getName() == "function_declarator":
|
||||||
if gState.isIncludeHeader():
|
if gState.isIncludeHeader():
|
||||||
|
|
|
||||||
|
|
@ -644,12 +644,16 @@ proc getCommentsStr*(gState: State, commentNodes: seq[TSNode]): string =
|
||||||
if commentNodes.len > 0:
|
if commentNodes.len > 0:
|
||||||
result = "::"
|
result = "::"
|
||||||
for commentNode in commentNodes:
|
for commentNode in commentNodes:
|
||||||
result &= "\n " & gState.getNodeVal(commentNode).replace(re" *(//|/\*\*|\*\*/|/\*|\*/|\*)", "").replace("\n", "\n ").strip()
|
result &= "\n " & gState.getNodeVal(commentNode).
|
||||||
|
replace(re" *(//|/\*\*|\*\*/|/\*|\*/|\*)", "").replace("\n", "\n ").strip()
|
||||||
|
|
||||||
proc getPrevCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] =
|
proc getPrevCommentNodes*(gState: State, node: TSNode, maxSearch=1): seq[TSNode] =
|
||||||
## Here we want to go until the node we get is not a comment
|
## Here we want to go until the node we get is not a comment
|
||||||
## for cases with multiple ``//`` comments instead of one ``/* */``
|
## for cases with multiple ``//`` comments instead of one ``/* */``
|
||||||
## section
|
## section
|
||||||
|
if gState.nocomments:
|
||||||
|
return
|
||||||
|
|
||||||
var sibling = node.tsNodePrevNamedSibling()
|
var sibling = node.tsNodePrevNamedSibling()
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
|
|
@ -670,9 +674,11 @@ proc getPrevCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] =
|
||||||
# reverse the comments because we got them in reverse order
|
# reverse the comments because we got them in reverse order
|
||||||
result.reverse
|
result.reverse
|
||||||
|
|
||||||
proc getNextCommentNodes*(node: TSNode, maxSearch=1): seq[TSNode] =
|
proc getNextCommentNodes*(gState: State, node: TSNode, maxSearch=1): seq[TSNode] =
|
||||||
## Searches the next nodes up to maxSearch nodes away for a comment
|
## Searches the next nodes up to maxSearch nodes away for a comment
|
||||||
|
|
||||||
|
if gState.nocomments:
|
||||||
|
return
|
||||||
# We only want to search for the next comment node (ie: inline)
|
# We only want to search for the next comment node (ie: inline)
|
||||||
# but we want to keep the same interface as getPrevCommentNodes,
|
# but we want to keep the same interface as getPrevCommentNodes,
|
||||||
# so we keep a returned seq but only store one element
|
# so we keep a returned seq but only store one element
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue