author | wenzelm |
Mon, 27 Feb 2023 15:09:59 +0100 | |
changeset 77398 | 19e9cafaafc5 |
parent 75906 | 2167b9e3157a |
permissions | -rw-r--r-- |
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 |
||
75393 | 10 |
object Update_Then { |
11 |
def update_then(path: Path): Unit = { |
|
61216 | 12 |
val text0 = File.read(path) |
13 |
val text1 = |
|
14 |
(for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator) |
|
15 |
yield { |
|
16 |
tok.source match { |
|
17 |
case "hence" => "then have" |
|
18 |
case "thus" => "then show" |
|
19 |
case s => s |
|
20 |
} }).mkString |
|
21 |
||
22 |
if (text0 != text1) { |
|
23 |
Output.writeln("changing " + path) |
|
24 |
File.write_backup2(path, text1) |
|
25 |
} |
|
26 |
} |
|
27 |
||
28 |
||
62836 | 29 |
/* Isabelle tool wrapper */ |
61216 | 30 |
|
62836 | 31 |
val isabelle_tool = |
72763 | 32 |
Isabelle_Tool("update_then", "expand old Isar command conflations 'hence' and 'thus'", |
75394 | 33 |
Scala_Project.here, |
34 |
{ args => |
|
35 |
val getopts = Getopts(""" |
|
62449 | 36 |
Usage: isabelle update_then [FILES|DIRS...] |
37 |
||
38 |
Recursively find .thy files and expand old Isar command conflations: |
|
39 |
||
40 |
hence ~> then have |
|
41 |
thus ~> then show |
|
42 |
||
43 |
Old versions of files are preserved by appending "~~". |
|
44 |
""") |
|
45 |
||
75394 | 46 |
val specs = getopts(args) |
47 |
if (specs.isEmpty) getopts.usage() |
|
48 |
||
49 |
for { |
|
50 |
spec <- specs |
|
75906
2167b9e3157a
clarified signature: support for adhoc file types;
wenzelm
parents:
75394
diff
changeset
|
51 |
file <- File.find_files(Path.explode(spec).file, file => File.is_thy(file.getName)) |
75394 | 52 |
} update_then(File.path(file)) |
53 |
}) |
|
61216 | 54 |
} |