diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-06-19 20:06:04 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-06-19 20:06:04 +0200 |
commit | 837d0c7270a67ea632d492586843807075eefb88 (patch) | |
tree | 623d37614015a3ab382e49cc7d2eedcfdbc84173 /tools | |
parent | 0c33244c23542ef3d09ef824718a87acb38b25ac (diff) | |
download | Nim-837d0c7270a67ea632d492586843807075eefb88.tar.gz |
nimpretty: proper command line handling; added tests; travis ensures these stay green
Diffstat (limited to 'tools')
-rw-r--r-- | tools/nimpretty.nim | 72 | ||||
-rw-r--r-- | tools/nimpretty.nim.cfg | 2 |
2 files changed, 0 insertions, 74 deletions
diff --git a/tools/nimpretty.nim b/tools/nimpretty.nim deleted file mode 100644 index 89e6ef905..000000000 --- a/tools/nimpretty.nim +++ /dev/null @@ -1,72 +0,0 @@ -# -# -# The Nim Compiler -# (c) Copyright 2017 Andreas Rumpf -# -# See the file "copying.txt", included in this -# distribution, for details about the copyright. -# - -## Standard tool for pretty printing. - -when not defined(nimpretty): - {.error: "This needs to be compiled with --define:nimPretty".} - -import ../compiler / [idents, msgs, ast, syntaxes, renderer, options] - -import parseopt, strutils, os - -const - Version = "0.1" - Usage = "nimpretty - Nim Pretty Printer Version " & Version & """ - - (c) 2017 Andreas Rumpf -Usage: - nimpretty [options] file.nim -Options: - --backup:on|off create a backup file before overwritting (default: ON) - --version show the version - --help show this help -""" - -proc writeHelp() = - stdout.write(Usage) - stdout.flushFile() - quit(0) - -proc writeVersion() = - stdout.write(Version & "\n") - stdout.flushFile() - quit(0) - -proc prettyPrint(infile: string) = - let conf = newConfigRef() - let fileIdx = fileInfoIdx(conf, infile) - when defined(nimpretty2): - discard parseFile(fileIdx, newIdentCache(), conf) - else: - let tree = parseFile(fileIdx, newIdentCache(), conf) - let outfile = changeFileExt(infile, ".pretty.nim") - renderModule(tree, infile, outfile, {}, fileIdx, conf) - -proc main = - var infile: string - var backup = true - for kind, key, val in getopt(): - case kind - of cmdArgument: - infile = key.addFileExt(".nim") - of cmdLongoption, cmdShortOption: - case normalize(key) - of "help", "h": writeHelp() - of "version", "v": writeVersion() - of "backup": backup = parseBool(val) - else: writeHelp() - of cmdEnd: assert(false) # cannot happen - if infile.len == 0: - quit "[Error] no input file." - if backup: - os.copyFile(source=infile, dest=changeFileExt(infile, ".nim.backup")) - prettyPrint(infile) - -main() diff --git a/tools/nimpretty.nim.cfg b/tools/nimpretty.nim.cfg deleted file mode 100644 index 5fafa6d2a..000000000 --- a/tools/nimpretty.nim.cfg +++ /dev/null @@ -1,2 +0,0 @@ ---define: nimpretty ---define: nimpretty2 |