aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-01-21 12:37:51 -0600
committerGanesh Viswanathan <dev@genotrance.com>2019-01-21 12:37:51 -0600
commita8028a62ecaf642bb2cff06f7533dcd31e843fb5 (patch)
tree74accd98155343fb78dfe927a2c96b268cd008da
parent6584a304d5a32d82ee7663d7b8925b2831541a7e (diff)
downloadnimterop-a8028a62ecaf642bb2cff06f7533dcd31e843fb5.tar.gz
nimterop-a8028a62ecaf642bb2cff06f7533dcd31e843fb5.zip
Fix #55 - crash and no typedef name
-rw-r--r--nimterop/ast.nim9
-rw-r--r--nimterop/grammar.nim2
-rw-r--r--toast.nim4
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: