Fix debug output

This commit is contained in:
Ganesh Viswanathan 2019-10-17 12:01:37 -05:00
commit 8c57fbf602

View file

@ -74,11 +74,16 @@ proc searchAstForNode(ast: ref Ast, node: TSNode, nimState: NimState): bool =
if ast.isNil: if ast.isNil:
return return
if nimState.gState.debug:
nimState.nodeBranch.add $node.tsNodeType()
echo "#" & spaces(nimState.nodeBranch.len * 2) & nimState.nodeBranch[^1]
if ast.children.len != 0: if ast.children.len != 0:
if childNames.contains(ast.regex) or if childNames.contains(ast.regex) or
(childNames.len == 0 and ast.recursive): (childNames.len == 0 and ast.recursive):
if node.getTSNodeNamedChildCountSansComments() != 0: if node.getTSNodeNamedChildCountSansComments() != 0:
var flag = true var flag = true
for i in 0 .. node.tsNodeNamedChildCount()-1: for i in 0 .. node.tsNodeNamedChildCount()-1:
if $node.tsNodeNamedChild(i).tsNodeType() != "comment": if $node.tsNodeNamedChild(i).tsNodeType() != "comment":
let let
@ -89,31 +94,25 @@ proc searchAstForNode(ast: ref Ast, node: TSNode, nimState: NimState): bool =
else: else:
ast ast
if nimState.gState.debug:
nimState.nodeBranch.add $node.tsNodeType()
echo "#" & spaces(nimState.nodeBranch.len) & nimState.nodeBranch[^1]
if not searchAstForNode(astChild, nodeChild, nimState): if not searchAstForNode(astChild, nodeChild, nimState):
if nimState.gState.debug:
echo "#" & spaces(nimState.nodeBranch.len) & &" {$nodeChild.tsNodeType()} unexpected"
discard nimState.nodeBranch.pop()
flag = false flag = false
break break
if flag:
result = node.saveNodeData(nimState)
else:
result = node.saveNodeData(nimState)
else:
if nimState.gState.debug:
echo "#" & spaces(nimState.nodeBranch.len * 2) & &" {ast.getRegexForAstChildren()} !=~ {childNames}"
elif node.getTSNodeNamedChildCountSansComments() == 0:
result = node.saveNodeData(nimState)
if nimState.gState.debug: if nimState.gState.debug:
discard nimState.nodeBranch.pop() discard nimState.nodeBranch.pop()
if nimState.nodeBranch.len == 0: if nimstate.nodeBranch.len == 0:
echo "" echo ""
if flag:
return node.saveNodeData(nimState)
else:
echo "#" & spaces(nimState.nodeBranch.len+1) & $node.tsNodeType()
return node.saveNodeData(nimState)
elif node.getTSNodeNamedChildCountSansComments() == 0:
echo "#" & spaces(nimState.nodeBranch.len+1) & $node.tsNodeType()
return node.saveNodeData(nimState)
proc searchAst(root: TSNode, astTable: AstTable, nimState: NimState) = proc searchAst(root: TSNode, astTable: AstTable, nimState: NimState) =
var var
node = root node = root