| 61216 |      1 | /*  Title:      Pure/Tools/update_then.scala
 | 
|  |      2 |     Author:     Makarius
 | 
|  |      3 | 
 | 
|  |      4 | Expand old Isar command conflations 'hence' and 'thus'.
 | 
|  |      5 | */
 | 
|  |      6 | 
 | 
|  |      7 | package isabelle
 | 
|  |      8 | 
 | 
|  |      9 | 
 | 
|  |     10 | object Update_Then
 | 
|  |     11 | {
 | 
|  |     12 |   def update_then(path: Path)
 | 
|  |     13 |   {
 | 
|  |     14 |     val text0 = File.read(path)
 | 
|  |     15 |     val text1 =
 | 
|  |     16 |       (for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator)
 | 
|  |     17 |         yield {
 | 
|  |     18 |           tok.source match {
 | 
|  |     19 |             case "hence" => "then have"
 | 
|  |     20 |             case "thus" => "then show"
 | 
|  |     21 |             case s => s
 | 
|  |     22 |         } }).mkString
 | 
|  |     23 | 
 | 
|  |     24 |     if (text0 != text1) {
 | 
|  |     25 |       Output.writeln("changing " + path)
 | 
|  |     26 |       File.write_backup2(path, text1)
 | 
|  |     27 |     }
 | 
|  |     28 |   }
 | 
|  |     29 | 
 | 
|  |     30 | 
 | 
| 62836 |     31 |   /* Isabelle tool wrapper */
 | 
| 61216 |     32 | 
 | 
| 62836 |     33 |   val isabelle_tool =
 | 
| 72763 |     34 |     Isabelle_Tool("update_then", "expand old Isar command conflations 'hence' and 'thus'",
 | 
|  |     35 |       Scala_Project.here, args =>
 | 
| 62836 |     36 |     {
 | 
| 62454 |     37 |       val getopts = Getopts("""
 | 
| 62449 |     38 | Usage: isabelle update_then [FILES|DIRS...]
 | 
|  |     39 | 
 | 
|  |     40 |   Recursively find .thy files and expand old Isar command conflations:
 | 
|  |     41 | 
 | 
|  |     42 |     hence  ~>  then have
 | 
|  |     43 |     thus   ~>  then show
 | 
|  |     44 | 
 | 
|  |     45 |   Old versions of files are preserved by appending "~~".
 | 
|  |     46 | """)
 | 
|  |     47 | 
 | 
|  |     48 |       val specs = getopts(args)
 | 
|  |     49 |       if (specs.isEmpty) getopts.usage()
 | 
|  |     50 | 
 | 
|  |     51 |       for {
 | 
|  |     52 |         spec <- specs
 | 
|  |     53 |         file <- File.find_files(Path.explode(spec).file, file => file.getName.endsWith(".thy"))
 | 
| 68994 |     54 |       } update_then(File.path(file))
 | 
| 62836 |     55 |     })
 | 
| 61216 |     56 | }
 |