Fix for module alias inside brackets (#8726)
This commit is contained in:
parent
bf973d29da
commit
d6d3f092a3
3 changed files with 30 additions and 14 deletions
|
|
@ -174,20 +174,32 @@ proc impMod(c: PContext; it: PNode; importStmtResult: PNode) =
|
||||||
#importForwarded(c, m.ast, emptySet)
|
#importForwarded(c, m.ast, emptySet)
|
||||||
|
|
||||||
proc evalImport(c: PContext, n: PNode): PNode =
|
proc evalImport(c: PContext, n: PNode): PNode =
|
||||||
#result = n
|
|
||||||
result = newNodeI(nkImportStmt, n.info)
|
result = newNodeI(nkImportStmt, n.info)
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
let it = n.sons[i]
|
let it = n.sons[i]
|
||||||
if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
|
if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
|
||||||
let sep = it[0]
|
let sep = it[0]
|
||||||
let dir = it[1]
|
let dir = it[1]
|
||||||
let a = newNodeI(nkInfix, it.info)
|
var imp = newNodeI(nkInfix, it.info)
|
||||||
a.add sep
|
imp.add sep
|
||||||
a.add dir
|
imp.add dir
|
||||||
a.add sep # dummy entry, replaced in the loop
|
imp.add sep # dummy entry, replaced in the loop
|
||||||
for x in it[2]:
|
for x in it[2]:
|
||||||
a.sons[2] = x
|
if x.kind == nkInfix and x.sons[0].ident.s == "as":
|
||||||
impMod(c, a, result)
|
imp.sons[2] = x.sons[1]
|
||||||
|
let impAs = newNodeI(nkImportAs, it.info)
|
||||||
|
impAs.add imp
|
||||||
|
impAs.add x.sons[2]
|
||||||
|
imp = impAs
|
||||||
|
impMod(c, imp, result)
|
||||||
|
else:
|
||||||
|
imp.sons[2] = x
|
||||||
|
impMod(c, imp, result)
|
||||||
|
elif it.kind == nkInfix and it.sons[0].ident.s == "as":
|
||||||
|
let imp = newNodeI(nkImportAs, it.info)
|
||||||
|
imp.add it.sons[1]
|
||||||
|
imp.add it.sons[2]
|
||||||
|
impMod(c, imp, result)
|
||||||
else:
|
else:
|
||||||
impMod(c, it, result)
|
impMod(c, it, result)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,13 +126,6 @@ proc getModuleName*(conf: ConfigRef; n: PNode): string =
|
||||||
of nkInfix:
|
of nkInfix:
|
||||||
let n0 = n[0]
|
let n0 = n[0]
|
||||||
let n1 = n[1]
|
let n1 = n[1]
|
||||||
if n0.kind == nkIdent and n0.ident.s == "as":
|
|
||||||
# XXX hack ahead:
|
|
||||||
n.kind = nkImportAs
|
|
||||||
n.sons[0] = n.sons[1]
|
|
||||||
n.sons[1] = n.sons[2]
|
|
||||||
n.sons.setLen(2)
|
|
||||||
return getModuleName(conf, n.sons[0])
|
|
||||||
when false:
|
when false:
|
||||||
if n1.kind == nkPrefix and n1[0].kind == nkIdent and n1[0].ident.s == "$":
|
if n1.kind == nkPrefix and n1[0].kind == nkIdent and n1[0].ident.s == "$":
|
||||||
if n0.kind == nkIdent and n0.ident.s == "/":
|
if n0.kind == nkIdent and n0.ident.s == "/":
|
||||||
|
|
|
||||||
11
tests/modules/timportas.nim
Normal file
11
tests/modules/timportas.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
discard """
|
||||||
|
action: run
|
||||||
|
"""
|
||||||
|
|
||||||
|
import .. / modules / [definitions as foo]
|
||||||
|
import std / times as bar
|
||||||
|
import definitions as baz
|
||||||
|
|
||||||
|
discard foo.v
|
||||||
|
discard bar.now
|
||||||
|
discard baz.v
|
||||||
Loading…
Add table
Add a link
Reference in a new issue