prettybase.nim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 ".." / [ast, msgs, lineinfos, idents, options, linter]
  11. proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent) =
  12. let line = sourceLine(conf, info)
  13. var first = min(info.col.int, line.len)
  14. if first < 0: return
  15. #inc first, skipIgnoreCase(line, "proc ", first)
  16. while first > 0 and line[first-1] in Letters: dec first
  17. if first < 0: return
  18. if line[first] == '`': inc first
  19. let last = first+identLen(line, first)-1
  20. if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
  21. var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
  22. system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
  23. conf.m.fileInfos[info.fileIndex.int32].dirty = true
  24. #if newSym.s == "File": writeStackTrace()
  25. proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PSym) =
  26. replaceDeprecated(conf, info, oldSym.name, newSym.name)
  27. proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
  28. let line = sourceLine(conf, info)
  29. var first = info.col.int
  30. if line[first] != '#': inc first
  31. var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
  32. system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
  33. conf.m.fileInfos[info.fileIndex.int32].dirty = true