about summary refs log tree commit diff stats
path: root/dev/c/hello.html
diff options
context:
space:
mode:
authorSilvino <silvino@bk.ru>2019-06-11 04:03:30 +0100
committerSilvino <silvino@bk.ru>2019-06-11 04:03:30 +0100
commitf0c45e7842ef205123124ba7ec2a1d044749c328 (patch)
treea77351f4e189bfd7590a2e67d24f417be4be113c /dev/c/hello.html
parente52ad7baa28982fb63154d7eda40c54982f8d276 (diff)
downloaddoc-f0c45e7842ef205123124ba7ec2a1d044749c328.tar.gz
core pkgmk with pump variable
Diffstat (limited to 'dev/c/hello.html')
0 files changed, 0 insertions, 0 deletions
11-11 10:38:41 +0100 committer Andreas Rumpf <rumpf_a@web.de> 2018-11-11 10:39:20 +0100 nimpretty: explicit --indent option; fixes #9502; refs #9510 [backport]' href='/ahoang/Nim/commit/nimpretty/nimpretty.nim?h=devel&id=d1fe195dcc4026ee3f732bb38a0642ff6c4e0d91'>d1fe195dc ^
837d0c727 ^
f078f272e ^
ca4b971bc ^
a1bd4a6cb ^
d1fe195dc ^




a1bd4a6cb ^

a1bd4a6cb ^
eddf9abd1 ^

837d0c727 ^
821920aa3 ^




d1fe195dc ^
eddf9abd1 ^


604a15c0a ^
eddf9abd1 ^




837d0c727 ^
d1fe195dc ^
eddf9abd1 ^



821920aa3 ^



eddf9abd1 ^
821920aa3 ^


d1fe195dc ^
eddf9abd1 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95













                                                                

                                                                     










                                                                   



                                                                               











                              




                                                               
                           
                                                      
                                     
                           




                                                       

                                                        
                                                          

           
                             




                                                                             
                        


                                 
                                     




                                          
                                     
                                               



                                            



                                                                 
            


                                                                    
                                   

      
#
#
#           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,
  pathutils, layouter]

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:
  --output:file         set the output file (default: overwrite the input file)
  --indent:N[=2]        set the number of spaces that is used for indentation
  --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)

type
  PrettyOptions = object
    indWidth: int

proc prettyPrint(infile, outfile: string, opt: PrettyOptions) =
  var conf = newConfigRef()
  let fileIdx = fileInfoIdx(conf, AbsoluteFile infile)
  conf.outFile = RelativeFile outfile
  when defined(nimpretty2):
    var p: TParsers
    p.parser.em.indWidth = opt.indWidth
    if setupParsers(p, fileIdx, newIdentCache(), conf):
      discard parseAll(p)
      closeParsers(p)
  else:
    let tree = parseFile(fileIdx, newIdentCache(), conf)
    renderModule(tree, infile, outfile, {}, fileIdx, conf)

proc main =
  var infile, outfile: string
  var backup = false
    # when `on`, create a backup file of input in case
    # `prettyPrint` could over-write it (note that the backup may happen even
    # if input is not actually over-written, when nimpretty is a noop).
    # --backup was un-documented (rely on git instead).
  var opt: PrettyOptions
  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)
      of "output", "o": outfile = val
      of "indent": opt.indWidth = parseInt(val)
      else: writeHelp()
    of cmdEnd: assert(false) # cannot happen
  if infile.len == 0:
    quit "[Error] no input file."
  if outfile.len == 0:
    outfile = infile
  if not existsFile(outfile) or not sameFile(infile, outfile):
    backup = false # no backup needed since won't be over-written
  if backup:
    let infileBackup = infile & ".backup" # works with .nim or .nims
    echo "writing backup " & infile & " > " & infileBackup
    os.copyFile(source = infile, dest = infileBackup)
  prettyPrint(infile, outfile, opt)

main()