diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-12-21 22:13:50 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-12-21 22:13:50 +0100 |
commit | 4e481cc316229436b87aaf035d70f686d0aaee5f (patch) | |
tree | 67c85a8fef0c5b0ebb7384712ad0a0bbf020aad4 | |
parent | 2bb49136de3e3d798c4bf37d23f34ee868e7ebf7 (diff) | |
download | Nim-4e481cc316229436b87aaf035d70f686d0aaee5f.tar.gz |
implements module grouping for the import statement
-rw-r--r-- | compiler/importer.nim | 26 | ||||
-rw-r--r-- | compiler/lookups.nim | 4 | ||||
-rw-r--r-- | compiler/nimfix/nimfix.nim | 10 | ||||
-rw-r--r-- | web/news/e029_version_0_16_0.rst | 11 |
4 files changed, 37 insertions, 14 deletions
diff --git a/compiler/importer.nim b/compiler/importer.nim index feebf97c4..615d01693 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -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 diff --git a/compiler/lookups.nim b/compiler/lookups.nim index fe159011c..61ecdb24b 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -216,8 +216,8 @@ when defined(nimfix): # when we cannot find the identifier, retry with a changed identifer: proc altSpelling(x: PIdent): PIdent = case x.s[0] - of 'A'..'Z': result = getIdent(toLower(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)) + of 'a'..'z': result = getIdent(toLowerAscii(x.s[0]) & x.s.substr(1)) else: result = x template fixSpelling(n: PNode; ident: PIdent; op: untyped) = diff --git a/compiler/nimfix/nimfix.nim b/compiler/nimfix/nimfix.nim index d1cf9615d..4afb16912 100644 --- a/compiler/nimfix/nimfix.nim +++ b/compiler/nimfix/nimfix.nim @@ -10,11 +10,11 @@ ## Nimfix is a tool that helps to convert old-style Nimrod code to Nim code. import strutils, os, parseopt -import compiler/options, compiler/commands, compiler/modules, compiler/sem, - compiler/passes, compiler/passaux, compiler/nimfix/pretty, - compiler/msgs, compiler/nimconf, - compiler/extccomp, compiler/condsyms, compiler/lists, - compiler/modulegraphs, compiler/idents +import compiler/[options, commands, modules, sem, + passes, passaux, nimfix/pretty, + msgs, nimconf, + extccomp, condsyms, lists, + modulegraphs, idents] const Usage = """ Nimfix - Tool to patch Nim code diff --git a/web/news/e029_version_0_16_0.rst b/web/news/e029_version_0_16_0.rst index 905504791..4f5571256 100644 --- a/web/news/e029_version_0_16_0.rst +++ b/web/news/e029_version_0_16_0.rst @@ -77,6 +77,17 @@ Language Additions v[0] = 6.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 -------- |