equal
deleted
inserted
replaced
1 /* Title: Pure/Tools/update_cartouches.scala |
1 /* Title: Pure/Tools/update_cartouches.scala |
2 Author: Makarius |
2 Author: Makarius |
3 |
3 |
4 Update theory syntax to use cartouches. |
4 Update theory syntax to use cartouches etc. |
5 */ |
5 */ |
6 |
6 |
7 package isabelle |
7 package isabelle |
8 |
8 |
9 |
9 |
35 if (ants == ants1) content else ants1.map(_.source).mkString |
35 if (ants == ants1) content else ants1.map(_.source).mkString |
36 case None => content |
36 case None => content |
37 } |
37 } |
38 } |
38 } |
39 |
39 |
40 def update_cartouches(replace_text: Boolean, path: Path) |
40 def update_cartouches(replace_comment: Boolean, replace_text: Boolean, path: Path) |
41 { |
41 { |
42 val text0 = File.read(path) |
42 val text0 = File.read(path) |
43 |
43 |
44 // outer syntax cartouches |
44 // outer syntax cartouches and comment markers |
45 val text1 = |
45 val text1 = |
46 (for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator) |
46 (for (tok <- Token.explode(Keyword.Keywords.empty, text0).iterator) |
47 yield { |
47 yield { |
48 if (tok.kind == Token.Kind.ALT_STRING) cartouche(tok.content) |
48 if (tok.kind == Token.Kind.ALT_STRING) cartouche(tok.content) |
49 else if (tok.kind == Token.Kind.VERBATIM) { |
49 else if (tok.kind == Token.Kind.VERBATIM) { |
50 tok.content match { |
50 tok.content match { |
51 case Verbatim_Body(s) => cartouche(s) |
51 case Verbatim_Body(s) => cartouche(s) |
52 case s => tok.source |
52 case s => tok.source |
53 } |
53 } |
54 } |
54 } |
|
55 else if (replace_comment && tok.source == "--") Symbol.comment |
55 else tok.source |
56 else tok.source |
56 } |
57 } |
57 ).mkString |
58 ).mkString |
58 |
59 |
59 // cartouches within presumed text tokens |
60 // cartouches within presumed text tokens |
85 |
86 |
86 def main(args: Array[String]) |
87 def main(args: Array[String]) |
87 { |
88 { |
88 Command_Line.tool0 { |
89 Command_Line.tool0 { |
89 args.toList match { |
90 args.toList match { |
90 case Properties.Value.Boolean(replace_text) :: files => |
91 case Properties.Value.Boolean(replace_comment) :: |
91 files.foreach(file => update_cartouches(replace_text, Path.explode(file))) |
92 Properties.Value.Boolean(replace_text) :: files => |
|
93 files.foreach(file => |
|
94 update_cartouches(replace_comment, replace_text, Path.explode(file))) |
92 case _ => error("Bad arguments:\n" + cat_lines(args)) |
95 case _ => error("Bad arguments:\n" + cat_lines(args)) |
93 } |
96 } |
94 } |
97 } |
95 } |
98 } |
96 } |
99 } |