diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-03 22:29:39 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-12-03 22:29:39 -0600 |
| commit | 4fe3b0380ccf14ebb8a241c51d0e0355ff4bb2d6 (patch) | |
| tree | 0bb37fb011bc5f9cf9fa0de3ad9f051729358886 | |
| parent | d3340d51e2d15a93fef46e4cf5be67ac69413cd9 (diff) | |
| download | nimterop-4fe3b0380ccf14ebb8a241c51d0e0355ff4bb2d6.tar.gz nimterop-4fe3b0380ccf14ebb8a241c51d0e0355ff4bb2d6.zip | |
Fixes for const, short and function returning pointer
| -rw-r--r-- | nimterop/ast.nim | 15 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 15 |
2 files changed, 21 insertions, 9 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index 1f397c1..ba7561e 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -28,9 +28,18 @@ proc saveNodeData(node: TSNode): bool = if name in ["primitive_type", "sized_type_specifier"]: val = val.getType() - if node.tsNodeParent().tsNodeType() == "pointer_declarator": - if gStateRT.data[^1].val != "object": - gStateRT.data[^1].val = "ptr " & gStateRT.data[^1].val + let + nparent = node.tsNodeParent() + if not nparent.tsNodeIsNull(): + let + npname = nparent.tsNodeType() + npparent = nparent.tsNodeParent() + if npname == "pointer_declarator" or + (npname == "function_declarator" and + not npparent.tsNodeIsNull() and npparent.tsNodeType() == "pointer_declarator"): + + if gStateRT.data[^1].val != "object": + gStateRT.data[^1].val = "ptr " & gStateRT.data[^1].val gStateRT.data.add((name, val)) diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index 1fc45c2..a07ad84 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -28,7 +28,7 @@ proc initGrammar() = (type_definition (primitive_type|type_identifier?) (sized_type_specifier? - (primitive_type) + (primitive_type?) ) (struct_specifier? (type_identifier) @@ -95,7 +95,7 @@ proc initGrammar() = (field_declaration+ (primitive_type|type_identifier?) (sized_type_specifier? - (primitive_type) + (primitive_type?) ) (struct_specifier? (type_identifier) @@ -171,9 +171,10 @@ proc initGrammar() = # typ function(typ param1, ...) gStateRT.grammar.add((""" (declaration + (type_qualifier?) (primitive_type|type_identifier?) (sized_type_specifier? - (primitive_type) + (primitive_type?) ) (struct_specifier? (type_identifier) @@ -182,9 +183,10 @@ proc initGrammar() = (identifier) (parameter_list (parameter_declaration* + (type_qualifier?) (primitive_type|type_identifier?) (sized_type_specifier? - (primitive_type) + (primitive_type?) ) (struct_specifier? (type_identifier) @@ -200,13 +202,14 @@ proc initGrammar() = ) ) (pointer_declarator? - (function_declarator? + (function_declarator (identifier) (parameter_list (parameter_declaration* + (type_qualifier?) (primitive_type|type_identifier?) (sized_type_specifier? - (primitive_type) + (primitive_type?) ) (struct_specifier? (type_identifier) |
