src/Pure/Tools/update_theorems.scala
author wenzelm
Thu, 21 Dec 2023 21:03:02 +0100
changeset 79329 992c494bda25
parent 75906 2167b9e3157a
permissions -rw-r--r--
proper thm_name for stored zproof;

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

Update toplevel theorem keywords.
*/

package isabelle


object Update_Theorems {
  def update_theorems(path: Path): Unit = {
    val text0 = File.read(path)
    val text1 =
      (for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator)
        yield {
          tok.source match {
            case "theorems" => "lemmas"
            case "schematic_theorem" | "schematic_lemma" | "schematic_corollary" =>
              "schematic_goal"
            case s => s
        } }).mkString

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


  /* Isabelle tool wrapper */

  val isabelle_tool = Isabelle_Tool("update_theorems", "update toplevel theorem keywords",
    Scala_Project.here,
    { args =>
      val getopts = Getopts("""
Usage: isabelle update_theorems [FILES|DIRS...]

  Recursively find .thy files and update toplevel theorem keywords:

    theorems             ~>  lemmas
    schematic_theorem    ~>  schematic_goal
    schematic_lemma      ~>  schematic_goal
    schematic_corollary  ~>  schematic_goal

  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.is_thy(file.getName))
      } update_theorems(File.path(file))
    })
}