mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
37 lines
1012 B
Nim
37 lines
1012 B
Nim
#
|
|
#
|
|
# The Nimrod Compiler
|
|
# (c) Copyright 2013 Andreas Rumpf
|
|
#
|
|
# See the file "copying.txt", included in this
|
|
# distribution, for details about the copyright.
|
|
#
|
|
|
|
import ast, types, msgs, osproc, streams, options
|
|
|
|
proc readOutput(p: PProcess): string =
|
|
result = ""
|
|
var output = p.outputStream
|
|
discard p.waitForExit
|
|
while not output.atEnd:
|
|
result.add(output.readLine)
|
|
|
|
proc opGorge*(cmd, input: string): string =
|
|
var p = startCmd(cmd)
|
|
if input.len != 0:
|
|
p.inputStream.write(input)
|
|
p.inputStream.close()
|
|
result = p.readOutput
|
|
|
|
proc opSlurp*(file: string, info: TLineInfo, module: PSym): string =
|
|
try:
|
|
let filename = file.findFile
|
|
result = readFile(filename)
|
|
# we produce a fake include statement for every slurped filename, so that
|
|
# the module dependencies are accurate:
|
|
appendToModule(module, newNode(nkIncludeStmt, info, @[
|
|
newStrNode(nkStrLit, filename)]))
|
|
except EIO:
|
|
localError(info, errCannotOpenFile, file)
|
|
result = ""
|