From a8028a62ecaf642bb2cff06f7533dcd31e843fb5 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Mon, 21 Jan 2019 12:37:51 -0600 Subject: Fix #55 - crash and no typedef name --- nimterop/ast.nim | 9 +++++++-- nimterop/grammar.nim | 2 +- 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() diff --git a/toast.nim b/toast.nim index 7781369..c6bc92d 100644 --- a/toast.nim +++ b/toast.nim @@ -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: -- cgit v1.2.3