src/Pure/Tools/update_then.scala
author wenzelm
Mon, 07 Mar 2016 20:44:47 +0100
changeset 62548 f8ebb715e06d
parent 62454 38c89353b349
child 62836 98dbed6cfa44
permissions -rw-r--r--
clarified treatment of DEL; tuned signature;

/*  Title:      Pure/Tools/update_then.scala
    Author:     Makarius

Expand old Isar command conflations 'hence' and 'thus'.
*/

package isabelle


object Update_Then
{
  def update_then(path: Path)
  {
    val text0 = File.read(path)
    val text1 =
      (for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator)
        yield {
          tok.source match {
            case "hence" => "then have"
            case "thus" => "then show"
            case s => s
        } }).mkString

    if (text0 != text1) {
      Output.writeln("changing " + path)
      File.write_backup2(path, text1)
    }
  }


  /* command line entry point */

  def main(args: Array[String])
  {
    Command_Line.tool0 {
      val getopts = Getopts("""
Usage: isabelle update_then [FILES|DIRS...]

  Recursively find .thy files and expand old Isar command conflations:

    hence  ~>  then have
    thus   ~>  then show

  Old versions of files are preserved by appending "~~".
""")

      val specs = getopts(args)
      if (specs.isEmpty) getopts.usage()

      for {
        spec <- specs
        file <- File.find_files(Path.explode(spec).file, file => file.getName.endsWith(".thy"))
      } update_then(Path.explode(File.standard_path(file)))
    }
  }
}