implements module grouping for the import statement
This commit is contained in:
parent
2bb49136de
commit
4e481cc316
4 changed files with 37 additions and 14 deletions
|
|
@ -186,16 +186,28 @@ proc myImportModule(c: PContext, n: PNode): PSym =
|
||||||
message(n.info, warnDeprecated, result.name.s)
|
message(n.info, warnDeprecated, result.name.s)
|
||||||
#suggestSym(n.info, result, false)
|
#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 =
|
proc evalImport(c: PContext, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
var emptySet: IntSet
|
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
var m = myImportModule(c, n.sons[i])
|
let it = n.sons[i]
|
||||||
if m != nil:
|
if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
|
||||||
# ``addDecl`` needs to be done before ``importAllSymbols``!
|
let sep = renderTree(it.sons[0], {renderNoComments})
|
||||||
addDecl(c, m, n.info) # add symbol to symbol table of module
|
let dir = renderTree(it.sons[1], {renderNoComments})
|
||||||
importAllSymbolsExcept(c, m, emptySet)
|
for x in it[2]:
|
||||||
#importForwarded(c, m.ast, emptySet)
|
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 =
|
proc evalFrom(c: PContext, n: PNode): PNode =
|
||||||
result = n
|
result = n
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,8 @@ when defined(nimfix):
|
||||||
# when we cannot find the identifier, retry with a changed identifer:
|
# when we cannot find the identifier, retry with a changed identifer:
|
||||||
proc altSpelling(x: PIdent): PIdent =
|
proc altSpelling(x: PIdent): PIdent =
|
||||||
case x.s[0]
|
case x.s[0]
|
||||||
of 'A'..'Z': result = getIdent(toLower(x.s[0]) & x.s.substr(1))
|
of 'A'..'Z': result = getIdent(toLowerAscii(x.s[0]) & x.s.substr(1))
|
||||||
of 'a'..'z': result = getIdent(toLower(x.s[0]) & x.s.substr(1))
|
of 'a'..'z': result = getIdent(toLowerAscii(x.s[0]) & x.s.substr(1))
|
||||||
else: result = x
|
else: result = x
|
||||||
|
|
||||||
template fixSpelling(n: PNode; ident: PIdent; op: untyped) =
|
template fixSpelling(n: PNode; ident: PIdent; op: untyped) =
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@
|
||||||
## Nimfix is a tool that helps to convert old-style Nimrod code to Nim code.
|
## Nimfix is a tool that helps to convert old-style Nimrod code to Nim code.
|
||||||
|
|
||||||
import strutils, os, parseopt
|
import strutils, os, parseopt
|
||||||
import compiler/options, compiler/commands, compiler/modules, compiler/sem,
|
import compiler/[options, commands, modules, sem,
|
||||||
compiler/passes, compiler/passaux, compiler/nimfix/pretty,
|
passes, passaux, nimfix/pretty,
|
||||||
compiler/msgs, compiler/nimconf,
|
msgs, nimconf,
|
||||||
compiler/extccomp, compiler/condsyms, compiler/lists,
|
extccomp, condsyms, lists,
|
||||||
compiler/modulegraphs, compiler/idents
|
modulegraphs, idents]
|
||||||
|
|
||||||
const Usage = """
|
const Usage = """
|
||||||
Nimfix - Tool to patch Nim code
|
Nimfix - Tool to patch Nim code
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,17 @@ Language Additions
|
||||||
v[0] = 6.0
|
v[0] = 6.0
|
||||||
echo v[0]
|
echo v[0]
|
||||||
|
|
||||||
|
- The ``import`` statement now supports importing multiple modules from
|
||||||
|
the same directory:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
import compiler / [ast, parser, lexer]
|
||||||
|
|
||||||
|
Is a shortcut for:
|
||||||
|
|
||||||
|
.. code-block:: nim
|
||||||
|
import compiler / ast, compiler / parser, compiler / lexer
|
||||||
|
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
--------
|
--------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue