Fix #55 - crash and no typedef name

This commit is contained in:
Ganesh Viswanathan 2019-01-21 12:37:51 -06:00
commit a8028a62ec
3 changed files with 10 additions and 5 deletions

View file

@ -88,9 +88,10 @@ proc searchAst(root: TSNode) =
var var
node = root node = root
nextnode: TSNode nextnode: TSNode
depth = 0
while true: while true:
if not node.tsNodeIsNull(): if not node.tsNodeIsNull() and depth > -1:
let let
name = $node.tsNodeType() name = $node.tsNodeType()
if name in gStateRT.ast: if name in gStateRT.ast:
@ -102,16 +103,20 @@ proc searchAst(root: TSNode) =
break break
gStateRT.data = @[] gStateRT.data = @[]
else: else:
return break
if $node.tsNodeType() notin gStateRT.ast and node.tsNodeNamedChildCount() != 0: if $node.tsNodeType() notin gStateRT.ast and node.tsNodeNamedChildCount() != 0:
nextnode = node.tsNodeNamedChild(0) nextnode = node.tsNodeNamedChild(0)
depth += 1
else: else:
nextnode = node.tsNodeNextNamedSibling() nextnode = node.tsNodeNextNamedSibling()
if nextnode.tsNodeIsNull(): if nextnode.tsNodeIsNull():
while true: while true:
node = node.tsNodeParent() node = node.tsNodeParent()
depth -= 1
if depth == -1:
break
if node == root: if node == root:
break break
if not node.tsNodeNextNamedSibling().tsNodeIsNull(): if not node.tsNodeNextNamedSibling().tsNodeIsNull():

View file

@ -249,7 +249,7 @@ proc initGrammar() =
i += 1 i += 1
if node.tsNodeType() == "type_definition" and 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 let
dname = gStateRT.data[^1].val dname = gStateRT.data[^1].val
ndname = gStateRT.data[^1].val.getIdentifier() ndname = gStateRT.data[^1].val.getIdentifier()

View file

@ -11,14 +11,14 @@ proc printLisp(root: TSNode) =
depth = 0 depth = 0
while true: while true:
if not node.tsNodeIsNull(): if not node.tsNodeIsNull() and depth > -1:
if gStateRT.pretty: if gStateRT.pretty:
stdout.write spaces(depth) stdout.write spaces(depth)
let let
(line, col) = node.getLineCol() (line, col) = node.getLineCol()
stdout.write &"({$node.tsNodeType()} {line} {col} {node.tsNodeEndByte() - node.tsNodeStartByte()}" stdout.write &"({$node.tsNodeType()} {line} {col} {node.tsNodeEndByte() - node.tsNodeStartByte()}"
else: else:
return break
if node.tsNodeNamedChildCount() != 0: if node.tsNodeNamedChildCount() != 0:
if gStateRT.pretty: if gStateRT.pretty: