Skip to content

Commit

Permalink
simplfy code with listType template
Browse files Browse the repository at this point in the history
* avoids code repetition and unnecessary nesting
  • Loading branch information
RickBarretto committed Sep 16, 2023
1 parent 71c20c8 commit b0c5a25
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/helpers/helper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -221,31 +221,31 @@ proc getInfo*(n: string, v: Value, aliases: SymbolDict):ValueDict =
template validSpec(value: Value, spec: untyped): bool =
value.info.spec.len > 0 and (toSeq(value.info.spec.keys))[0] != ""

template listTypes(values: untyped): Value =
newBlock collect(for val in values: newType val)

var funArgs = initOrderedTable[string,Value]()
var funAttrs = initOrderedTable[string,Value]()

if v.validSpec(args):
for key, spec in v.args:
funArgs[key] = newBlock collect do:
for s in spec: newType(s)
for key, spec in v.args:
funArgs[key] = spec.listTypes()

if v.validSpec(attrs):
for k,dd in v.info.attrs:
let spec = dd[0]
let descr = dd[1]
var ss = initOrderedTable[string,Value]()

ss["types"] = newBlock collect do:
for s in spec: newType(s)
ss["types"] = spec.listTypes()

ss["description"] = newString(descr)
funAttrs[k] = newDictionary(ss)

result["args"] = newDictionary(funArgs)
result["attrs"] = newDictionary(funAttrs)
result["returns"] = if v.info.returns.len == 0:
newBlock(@[newType(Nothing)]) else: newBlock collect do:
for ret in v.info.returns: newType(ret)
newBlock(@[newType(Nothing)]) else: v.info.returns.listTypes()

let alias = getAlias(n, aliases)
if alias[0]!="":
Expand Down

0 comments on commit b0c5a25

Please sign in to comment.