diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-10-16 21:25:31 -0500 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-10-16 21:25:31 -0500 |
| commit | 8dc327d02b851a6447e971823cb440f973c5a146 (patch) | |
| tree | 9a7f481fd0fac683a734da231686e255fe378083 | |
| parent | 48955b3aa140ee7a903e5bf6bb6e36527a0a8359 (diff) | |
| download | nimterop-issue139.tar.gz nimterop-issue139.zip | |
Implement var procissue139
| -rw-r--r-- | nimterop/ast.nim | 14 | ||||
| -rw-r--r-- | nimterop/grammar.nim | 17 | ||||
| -rw-r--r-- | tests/tpcre.nim | 7 |
3 files changed, 28 insertions, 10 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim index b5176fb..128a7e6 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -47,14 +47,16 @@ proc saveNodeData(node: TSNode, nimState: NimState): bool = nimState.data.add((name, val)) - if name == "field_identifier" and - pname == "pointer_declarator" and + if pname == "pointer_declarator" and ppname == "function_declarator": - if pppname == "pointer_declarator": - nimState.data.insert(("pointer_declarator", ""), nimState.data.len-1) - if ppppname == "pointer_declarator": + if name == "field_identifier": + if pppname == "pointer_declarator": nimState.data.insert(("pointer_declarator", ""), nimState.data.len-1) - nimState.data.add(("function_declarator", "")) + if ppppname == "pointer_declarator": + nimState.data.insert(("pointer_declarator", ""), nimState.data.len-1) + nimState.data.add(("function_declarator", "")) + elif name == "identifier": + nimState.data.add(("pointer_declarator", "")) elif name in gExpressions and name != "escape_sequence": if $node.tsNodeParent.tsNodeType() notin gExpressions: diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index bd9a851..8d98dde 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -86,7 +86,7 @@ proc initGrammar(): Grammar = (pointer_declarator! (type_identifier) ) - (type_identifier) + (type_identifier|identifier) ) {paramListGrammar} (noexcept|throw_specifier?) @@ -588,8 +588,13 @@ proc initGrammar(): Grammar = pout, pname, ptyp, pptr = "" count = 1 flen = "" + fVar = false i += 1 + if i < nimState.data.len and nimState.data[i].name == "pointer_declarator": + fVar = true + i += 1 + while i < nimState.data.len: if nimState.data[i].name == "function_declarator": break @@ -605,9 +610,15 @@ proc initGrammar(): Grammar = pragma = nimState.getPragma(nimState.getImportC(fname, fnname), "cdecl") if fptr.len != 0 or ftyp != "object": - nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}): {getPtrType(fptr&ftyp)}{pragma}" + if fVar: + nimState.procStr &= &"{nimState.getComments(true)}\nvar {fnname}*: proc ({pout}): {getPtrType(fptr&ftyp)}{{.cdecl.}}" + else: + nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}): {getPtrType(fptr&ftyp)}{pragma}" else: - nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}){pragma}" + if fVar: + nimState.procStr &= &"{nimState.getComments(true)}\nvar {fnname}*: proc ({pout}){{.cdecl.}}" + else: + nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}){pragma}" )) # // comment diff --git a/tests/tpcre.nim b/tests/tpcre.nim index 5bc97da..41809cb 100644 --- a/tests/tpcre.nim +++ b/tests/tpcre.nim @@ -1,6 +1,6 @@ import os -import nimterop/[cimport, build, paths] +import nimterop/[cimport, build] const baseDir = getProjectCacheDir("nimterop" / "tests" / "pcre") @@ -33,3 +33,8 @@ cPlugin: cImport(pcreH, dynlib="dynpcre") echo version() + +proc my_malloc(a1: cuint) {.cdecl.} = + discard + +malloc = my_malloc |
