summary refs log tree commit diff stats
path: root/compiler/ast.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2011-12-11 09:41:04 +0200
committerZahary Karadjov <zahary@gmail.com>2011-12-11 11:24:52 +0200
commitd171a8b36f10f42d35e64a7ddefa57376b419908 (patch)
tree24e69d89090696d1e139addeddc7a2b2df4361ba /compiler/ast.nim
parentde4b894541f6304b29c5714b032f415f567c2f3c (diff)
downloadNim-d171a8b36f10f42d35e64a7ddefa57376b419908.tar.gz
path canonicalization for imported modules, relative paths written in rod files
Diffstat (limited to 'compiler/ast.nim')
-rwxr-xr-xcompiler/ast.nim17
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 2b84c415f..6ac7dc0de 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -11,7 +11,7 @@
 
 import 
   msgs, hashes, nversion, options, strutils, crc, ropes, idents, lists, 
-  intsets, idgen
+  intsets, idgen, os
 
 const
   ImportTablePos* = 0         # imported symbols are at level 0
@@ -1030,3 +1030,18 @@ proc getStrOrChar*(a: PNode): string =
     internalError(a.info, "getStrOrChar")
     result = ""
 
+proc getModuleName*(n: PNode): string =
+  # This returns a short relative module name without the nim extension
+  # e.g. like "system", "importer" or "somepath/module"
+  # The proc won't perform any checks that the path is actually valid
+  case n.kind
+  of nkStrLit, nkRStrLit, nkTripleStrLit:
+    result = UnixToNativePath(n.strVal)
+  of nkIdent:
+    result = n.ident.s
+  of nkSym:
+    result = n.sym.name.s
+  else:
+    internalError(n.info, "getModuleName")
+    result = ""
+