Fix #55 - crash and no typedef name
This commit is contained in:
parent
6584a304d5
commit
a8028a62ec
3 changed files with 10 additions and 5 deletions
|
|
@ -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():
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue