prettybase.nim 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. import strutils except Letters
  10. import lexbase, streams
  11. import ".." / [ast, msgs, lineinfos, idents, options, linter]
  12. from os import splitFile
  13. proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent) =
  14. let line = sourceLine(conf, info)
  15. var first = min(info.col.int, line.len)
  16. if first < 0: return
  17. #inc first, skipIgnoreCase(line, "proc ", first)
  18. while first > 0 and line[first-1] in Letters: dec first
  19. if first < 0: return
  20. if line[first] == '`': inc first
  21. let last = first+identLen(line, first)-1
  22. if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
  23. var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
  24. system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
  25. conf.m.fileInfos[info.fileIndex.int32].dirty = true
  26. #if newSym.s == "File": writeStackTrace()
  27. proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PSym) =
  28. replaceDeprecated(conf, info, oldSym.name, newSym.name)
  29. proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
  30. let line = sourceLine(conf, info)
  31. var first = info.col.int
  32. if line[first] != '#': inc first
  33. var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
  34. system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
  35. conf.m.fileInfos[info.fileIndex.int32].dirty = true