epc skeleton

This commit is contained in:
Simon Hafner 2015-04-22 06:32:02 +05:00
commit f0f72613d8

View file

@ -23,18 +23,20 @@ Options:
--address:HOST binds to that address, by default "" --address:HOST binds to that address, by default ""
--stdin read commands from stdin and write results to --stdin read commands from stdin and write results to
stdout instead of using sockets stdout instead of using sockets
--sexp talk in sexp, mainly for emacs epc. --epc use emacs epc mode
The server then listens to the connection and takes line-based commands. The server then listens to the connection and takes line-based commands.
In addition, all command line options of Nim that do not affect code generation In addition, all command line options of Nim that do not affect code generation
are supported. are supported.
""" """
type
Mode = enum mstdin, mtcp, mepc
var var
gPort = 6000.Port gPort = 6000.Port
gAddress = "" gAddress = ""
gUseStdin: bool gMode: Mode
const const
seps = {':', ';', ' ', '\t'} seps = {':', ';', ' ', '\t'}
@ -109,14 +111,15 @@ proc action(cmd: string) =
proc serve() = proc serve() =
# do not stop after the first error: # do not stop after the first error:
msgs.gErrorMax = high(int) msgs.gErrorMax = high(int)
if gUseStdin: case gMode:
of mstdin:
echo Help echo Help
var line = "" var line = ""
while readLineFromStdin("> ", line): while readLineFromStdin("> ", line):
action line action line
echo "" echo ""
flushFile(stdout) flushFile(stdout)
else: of mtcp:
var server = newSocket() var server = newSocket()
server.bindAddr(gPort, gAddress) server.bindAddr(gPort, gAddress)
var inp = "".TaintedString var inp = "".TaintedString
@ -134,6 +137,8 @@ proc serve() =
stdoutSocket.send("\c\L") stdoutSocket.send("\c\L")
stdoutSocket.close() stdoutSocket.close()
of mepc:
discard
proc mainCommand = proc mainCommand =
registerPass verbosePass registerPass verbosePass
@ -157,9 +162,14 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) =
of cmdEnd: break of cmdEnd: break
of cmdLongoption, cmdShortOption: of cmdLongoption, cmdShortOption:
case p.key.normalize case p.key.normalize
of "port": gPort = parseInt(p.val).Port of "port":
of "address": gAddress = p.val gPort = parseInt(p.val).Port
of "stdin": gUseStdin = true gMode = mtcp
of "address":
gAddress = p.val
gMode = mtcp
of "stdin": gMode = mstdin
of "epc": gMode = mepc
else: processSwitch(pass, p) else: processSwitch(pass, p)
of cmdArgument: of cmdArgument:
options.gProjectName = unixToNativePath(p.key) options.gProjectName = unixToNativePath(p.key)