implements module grouping for the import statement

This commit is contained in:
Andreas Rumpf 2016-12-21 22:13:50 +01:00
commit 4e481cc316
4 changed files with 37 additions and 14 deletions

View file

@ -186,16 +186,28 @@ proc myImportModule(c: PContext, n: PNode): PSym =
message(n.info, warnDeprecated, result.name.s)
#suggestSym(n.info, result, false)
proc impMod(c: PContext; it: PNode) =
let m = myImportModule(c, it)
if m != nil:
var emptySet: IntSet
# ``addDecl`` needs to be done before ``importAllSymbols``!
addDecl(c, m, it.info) # add symbol to symbol table of module
importAllSymbolsExcept(c, m, emptySet)
#importForwarded(c, m.ast, emptySet)
proc evalImport(c: PContext, n: PNode): PNode =
result = n
var emptySet: IntSet
for i in countup(0, sonsLen(n) - 1):
var m = myImportModule(c, n.sons[i])
if m != nil:
# ``addDecl`` needs to be done before ``importAllSymbols``!
addDecl(c, m, n.info) # add symbol to symbol table of module
importAllSymbolsExcept(c, m, emptySet)
#importForwarded(c, m.ast, emptySet)
let it = n.sons[i]
if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
let sep = renderTree(it.sons[0], {renderNoComments})
let dir = renderTree(it.sons[1], {renderNoComments})
for x in it[2]:
let f = renderTree(x, {renderNoComments})
let a = newStrNode(nkStrLit, (dir & sep & f).replace(" "))
impMod(c, a)
else:
impMod(c, it)
proc evalFrom(c: PContext, n: PNode): PNode =
result = n