diff options
| -rw-r--r-- | nimterop/ast.nim | 9 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 2 | ||||
| -rw-r--r-- | toast.nim | 4 |
3 files changed, 10 insertions, 5 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index 62cf05e..c5810b3 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -88,9 +88,10 @@ proc searchAst(root: TSNode) = var node = root nextnode: TSNode + depth = 0 while true: - if not node.tsNodeIsNull(): + if not node.tsNodeIsNull() and depth > -1: let name = $node.tsNodeType() if name in gStateRT.ast: @@ -102,16 +103,20 @@ proc searchAst(root: TSNode) = break gStateRT.data = @[] else: - return + break if $node.tsNodeType() notin gStateRT.ast and node.tsNodeNamedChildCount() != 0: nextnode = node.tsNodeNamedChild(0) + depth += 1 else: nextnode = node.tsNodeNextNamedSibling() if nextnode.tsNodeIsNull(): while true: node = node.tsNodeParent() + depth -= 1 + if depth == -1: + break if node == root: break if not node.tsNodeNextNamedSibling().tsNodeIsNull(): diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index 6d5870a..979b9f4 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -249,7 +249,7 @@ proc initGrammar() = i += 1 if node.tsNodeType() == "type_definition" and - gStateRT.data[^1].name == "type_identifier": + gStateRT.data[^1].name == "type_identifier" and gStateRT.data[^1].val.len != 0: let dname = gStateRT.data[^1].val ndname = gStateRT.data[^1].val.getIdentifier() @@ -11,14 +11,14 @@ proc printLisp(root: TSNode) = depth = 0 while true: - if not node.tsNodeIsNull(): + if not node.tsNodeIsNull() and depth > -1: if gStateRT.pretty: stdout.write spaces(depth) let (line, col) = node.getLineCol() stdout.write &"({$node.tsNodeType()} {line} {col} {node.tsNodeEndByte() - node.tsNodeStartByte()}" else: - return + break if node.tsNodeNamedChildCount() != 0: if gStateRT.pretty: |
