From 438160ac2a916ca0e8e18161d0a757e6bb338426 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Thu, 17 Oct 2019 15:41:24 -0500 Subject: Detect unknown --- nimterop/getters.nim | 3 +++ nimterop/grammar.nim | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nimterop/getters.nim b/nimterop/getters.nim index a88895d..7205213 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -320,6 +320,9 @@ proc getAstChildByName*(ast: ref Ast, name: string): ref Ast = if name in ast.children[i].name.split("|"): return ast.children[i] + if ast.children.len == 1 and ast.children[0].name == ".": + return ast.children[0] + proc getPxName*(node: TSNode, offset: int): string = var np = node diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index 8d98dde..89b3223 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -637,6 +637,23 @@ proc initGrammar(): Grammar = nimState.commentStr &= &"\n # {line.strip(leading=false)}" )) + # // unknown + result.add((&""" + (type_definition|struct_specifier|union_specifier|enum_specifier|declaration + (^.*) + ) + """, + proc (ast: ref Ast, node: TSNode, nimState: NimState) = + for i in nimState.data: + case $node.tsNodeType() + of "declaration": + if i.name == "identifier": + echo "# Unknown declaration " & i.val + else: + if i.name == "type_identifier": + echo "# Unknown type " & i.val + )) + proc initRegex(ast: ref Ast) = if ast.children.len != 0: if not ast.recursive: @@ -653,7 +670,7 @@ proc initRegex(ast: ref Ast) = raise newException(Exception, getCurrentExceptionMsg()) proc parseGrammar*(): AstTable = - let grammars = initGrammar() + const grammars = initGrammar() result = newTable[string, seq[ref Ast]]() for i in 0 .. grammars.len-1: -- cgit v1.2.3