aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2018-11-28 16:51:32 -0600
committerGanesh Viswanathan <dev@genotrance.com>2018-11-28 16:51:32 -0600
commitc9b57c567cf065ca4ff5dcb4f4a5ee2eb1f01a52 (patch)
tree3ddd8b5dd31d25ba2e4d1476ca7c398f327507c6
parenta2ff8ea64c5ff4cd54157ce3c35cbeef59d3187e (diff)
downloadnimterop-c9b57c567cf065ca4ff5dcb4f4a5ee2eb1f01a52.tar.gz
nimterop-c9b57c567cf065ca4ff5dcb4f4a5ee2eb1f01a52.zip
Fix #23 - handle inline comments, handle typedef enum X {} Y;
-rw-r--r--nimterop/ast.nim13
1 files changed, 11 insertions, 2 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim
index 4cee1db..fe0111f 100644
--- a/nimterop/ast.nim
+++ b/nimterop/ast.nim
@@ -77,6 +77,8 @@ proc pStructSpecifier(node: TSNode, name = "") =
if node.tsNodeNamedChild(0).tsNodeNamedChildCount() != 0:
for i in 0 .. node.tsNodeNamedChild(0).tsNodeNamedChildCount()-1:
+ if $node.tsNodeNamedChild(0).tsNodeNamedChild(i).tsNodeType() == "comment":
+ continue
let ts = typeScan(node.tsNodeNamedChild(0).tsNodeNamedChild(i), "field_declaration", "field_identifier", " ")
if ts.len == 0:
return
@@ -95,6 +97,8 @@ proc pStructSpecifier(node: TSNode, name = "") =
if node.tsNodeNamedChild(1).tsNodeNamedChildCount() != 0:
for i in 0 .. node.tsNodeNamedChild(1).tsNodeNamedChildCount()-1:
+ if $node.tsNodeNamedChild(1).tsNodeNamedChild(i).tsNodeType() == "comment":
+ continue
let ts = typeScan(node.tsNodeNamedChild(1).tsNodeNamedChild(i), "field_declaration", "field_identifier", " ")
if ts.len == 0:
return
@@ -114,8 +118,11 @@ proc pEnumSpecifier(node: TSNode, name = "") =
ename = name
elid = 0
stmt = &" {name.getIdentifier()}* = enum #1 pEnumSpecifier()\n"
- elif name.len == 0 and node.tsNodeNamedChildCount() == 2 and $node.tsNodeNamedChild(1).tsNodeType() == "enumerator_list":
- ename = getNodeValIf(node.tsNodeNamedChild(0), "type_identifier")
+ elif node.tsNodeNamedChildCount() == 2 and $node.tsNodeNamedChild(1).tsNodeType() == "enumerator_list":
+ if name.len == 0:
+ ename = getNodeValIf(node.tsNodeNamedChild(0), "type_identifier")
+ else:
+ ename = name
elid = 1
if ename.nBl:
# enum X { fields }
@@ -128,6 +135,8 @@ proc pEnumSpecifier(node: TSNode, name = "") =
if node.tsNodeNamedChild(elid).tsNodeNamedChildCount() != 0:
for i in 0 .. node.tsNodeNamedChild(elid).tsNodeNamedChildCount()-1:
let field = node.tsNodeNamedChild(elid).tsNodeNamedChild(i)
+ if $field.tsNodeType() == "comment":
+ continue
if not field.tsNodeIsNull() and $field.tsNodeType() == "enumerator":
let fname = getNodeValIf(field.tsNodeNamedChild(0), "identifier")
if field.tsNodeNamedChildCount() == 1: