summary refs log tree commit diff stats
diff options
context:
space:
mode:
authordef <dennis@felsin9.de>2015-02-22 23:03:46 +0100
committerdef <dennis@felsin9.de>2015-02-22 23:23:22 +0100
commitdca5508d13249c261d322b499098439b4fc294a9 (patch)
tree6aea1dba521efc6da8ef00e794f4cb30f79973b0
parent6f069dad8417c54c084290a1c63a4e8f4633c19e (diff)
downloadNim-dca5508d13249c261d322b499098439b4fc294a9.tar.gz
Make compiler read files from stdin
Special "-" file as stdin.
-rw-r--r--compiler/modules.nim2
-rw-r--r--compiler/passes.nim6
-rw-r--r--compiler/service.nim7
3 files changed, 12 insertions, 3 deletions
diff --git a/compiler/modules.nim b/compiler/modules.nim
index db05ccc6c..a2b739efc 100644
--- a/compiler/modules.nim
+++ b/compiler/modules.nim
@@ -116,7 +116,7 @@ proc newModule(fileIdx: int32): PSym =
   result.kind = skModule
   let filename = fileIdx.toFullPath
   result.name = getIdent(splitFile(filename).name)
-  if not isNimIdentifier(result.name.s):
+  if result.name.s != "-" and not isNimIdentifier(result.name.s):
     rawMessage(errInvalidModuleName, result.name.s)
   
   result.info = newLineInfo(fileIdx, 1, 1)
diff --git a/compiler/passes.nim b/compiler/passes.nim
index f9c3d75f9..149116502 100644
--- a/compiler/passes.nim
+++ b/compiler/passes.nim
@@ -170,7 +170,11 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) =
     openPasses(a, module)
     if stream == nil: 
       let filename = fileIdx.toFullPathConsiderDirty
-      s = llStreamOpen(filename, fmRead)
+      if module.name.s == "-":
+        module.name.s = "stdin"
+        s = llStreamOpen(stdin)
+      else:
+        s = llStreamOpen(filename, fmRead)
       if s == nil: 
         rawMessage(errCannotOpenFile, filename)
         return
diff --git a/compiler/service.nim b/compiler/service.nim
index 1d51ef2a1..7cb9d7d29 100644
--- a/compiler/service.nim
+++ b/compiler/service.nim
@@ -33,7 +33,12 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
     parseopt.next(p)
     case p.kind
     of cmdEnd: break
-    of cmdLongoption, cmdShortOption: processSwitch(pass, p)
+    of cmdLongoption, cmdShortOption:
+      if p.key == " ":
+        p.key = "-"
+        if processArgument(pass, p, argsCount): break
+      else:
+        processSwitch(pass, p)
     of cmdArgument:
       if processArgument(pass, p, argsCount): break
   if pass == passCmd2: