aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-01-09 14:18:31 -0600
committerGanesh Viswanathan <dev@genotrance.com>2019-01-09 14:18:31 -0600
commitd21017ac5bfade2194a50952e40257e80bd018dd (patch)
treeb5723797d7c29f20d9788ca18b9387bfdc524a53
parent960a8f68730d591084dc44807e098c3cc279446d (diff)
downloadnimterop-d21017ac5bfade2194a50952e40257e80bd018dd.tar.gz
nimterop-d21017ac5bfade2194a50952e40257e80bd018dd.zip
Support for nameless function params, unused enums
-rw-r--r--nimterop/grammar.nim38
1 files changed, 20 insertions, 18 deletions
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim
index b278872..9abbf87 100644
--- a/nimterop/grammar.nim
+++ b/nimterop/grammar.nim
@@ -60,6 +60,18 @@ proc initGrammar() =
gStateRT.typeStr &= &" {name}* = {typ}\n"
))
+ template funcParamCommon(pname, ptyp, pout, count, i: untyped): untyped =
+ ptyp = gStateRT.data[i].val.getIdentifier()
+ if i+1 < gStateRT.data.len and gStateRT.data[i+1].name == "identifier":
+ pname = gStateRT.data[i+1].val.getIdentifier()
+ i += 2
+ else:
+ pname = "a" & $count
+ count += 1
+ i += 1
+ if ptyp != "object":
+ pout &= &"{pname}: {ptyp},"
+
proc pStructCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int) =
var
nname = name.getIdentifier()
@@ -111,16 +123,7 @@ proc initGrammar() =
if gStateRT.data[i].name == "field_declaration":
break
- ptyp = gStateRT.data[i].val.getIdentifier()
- if gStateRT.data[i+1].name == "identifier":
- pname = gStateRT.data[i+1].val.getIdentifier()
- i += 2
- else:
- pname = "a" & $count
- count += 1
- i += 1
- if ptyp != "object":
- pout &= &"{pname}: {ptyp},"
+ funcParamCommon(pname, ptyp, pout, count, i)
if pout.len != 0 and pout[^1] == ',':
pout = pout[0 .. ^2]
@@ -214,7 +217,7 @@ proc initGrammar() =
if nname notin gStateRT.enums:
gStateRT.enums.add(nname)
gStateRT.enumStr &= &"\ntype {nname}* = distinct int"
- gStateRT.enumStr &= &"\nconverter enumToInt(en: {nname}): int = en.int\n"
+ gStateRT.enumStr &= &"\nconverter enumToInt(en: {nname}): int {{.used.}} = en.int\n"
var
i = fstart
@@ -306,15 +309,14 @@ proc initGrammar() =
if fnname notin gStateRT.procs:
var
- pout = ""
+ pout, pname, ptyp = ""
i = 2
+ count = 1
+
if gStateRT.data.len > 2:
- while i < gStateRT.data.len-1:
- let
- ptyp = gStateRT.data[i].val.getIdentifier()
- pname = gStateRT.data[i+1].val.getIdentifier()
- pout &= &"{pname}: {ptyp},"
- i += 2
+ while i < gStateRT.data.len:
+ funcParamCommon(pname, ptyp, pout, count, i)
+
if pout.len != 0 and pout[^1] == ',':
pout = pout[0 .. ^2]