Fix part of #127 - file output for toast

This commit is contained in:
Ganesh Viswanathan 2019-12-19 15:11:59 -06:00
commit cf372eb061

View file

@ -106,6 +106,7 @@ proc main(
mode = modeDefault, mode = modeDefault,
nim: string = "nim", nim: string = "nim",
nocomments = false, nocomments = false,
output = "",
past = false, past = false,
pgrammar = false, pgrammar = false,
pluginSourcePath: string = "", pluginSourcePath: string = "",
@ -146,6 +147,9 @@ proc main(
if pluginSourcePath.nBl: if pluginSourcePath.nBl:
gState.loadPlugin(pluginSourcePath) gState.loadPlugin(pluginSourcePath)
if output.len != 0:
doAssert reopen(stdout, output, fmWrite), "Failed to write to " & output
let let
astTable = parseGrammar() astTable = parseGrammar()
if pgrammar: if pgrammar:
@ -167,6 +171,7 @@ when isMainModule:
"mode": "language parser: c or cpp", "mode": "language parser: c or cpp",
"nim": "use a particular Nim executable (default: $PATH/nim)", "nim": "use a particular Nim executable (default: $PATH/nim)",
"nocomments": "exclude top-level comments from output", "nocomments": "exclude top-level comments from output",
"output": "file to output content - default stdout",
"past": "print AST output", "past": "print AST output",
"pgrammar": "print grammar", "pgrammar": "print grammar",
"pluginSourcePath": "Nim file to build and load as a plugin", "pluginSourcePath": "Nim file to build and load as a plugin",
@ -183,6 +188,7 @@ when isMainModule:
"dynlib": 'l', "dynlib": 'l',
"includeDirs": 'I', "includeDirs": 'I',
"nocomments": 'c', "nocomments": 'c',
"output": 'o',
"past": 'a', "past": 'a',
"pgrammar": 'g', "pgrammar": 'g',
"pnim": 'n', "pnim": 'n',