author | wenzelm |
Sun, 03 Apr 2016 22:45:40 +0200 | |
changeset 62834 | 970cedec9748 |
parent 62814 | 29ca4cdd998d |
child 63997 | e11ccb5aa82f |
permissions | -rw-r--r-- |
62452 | 1 |
/* Title: Pure/Tools/check_sources.scala |
56791 | 2 |
Author: Makarius |
3 |
||
4 |
Some sanity checks for Isabelle sources. |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
62452 | 10 |
object Check_Sources |
56791 | 11 |
{ |
12 |
def check_file(path: Path) |
|
13 |
{ |
|
14 |
val file_name = path.implode |
|
15 |
val file_pos = path.position |
|
16 |
def line_pos(i: Int) = Position.Line_File(i + 1, file_name) |
|
17 |
||
18 |
val content = File.read(path) |
|
19 |
||
20 |
for { (line, i) <- split_lines(content).iterator.zipWithIndex } |
|
21 |
{ |
|
22 |
try { |
|
23 |
Symbol.decode_strict(line) |
|
24 |
||
25 |
for { c <- Word.codepoint_iterator(line); if c > 128 && !Character.isAlphabetic(c) } |
|
26 |
{ |
|
56792 | 27 |
Output.warning("Suspicious Unicode character " + quote(Word.codepoint(c)) + |
56791 | 28 |
Position.here(line_pos(i))) |
29 |
} |
|
30 |
} |
|
62814 | 31 |
catch { case ERROR(msg) => Output.warning(msg + Position.here(line_pos(i))) } |
56791 | 32 |
|
33 |
if (line.contains('\t')) |
|
56792 | 34 |
Output.warning("TAB character" + Position.here(line_pos(i))) |
56791 | 35 |
} |
36 |
||
37 |
if (content.contains('\r')) |
|
56792 | 38 |
Output.warning("CR character" + Position.here(file_pos)) |
62814 | 39 |
|
40 |
if (Word.bidi_detect(content)) |
|
41 |
Output.warning("Bidirectional Unicode text " + Position.here(file_pos)) |
|
56791 | 42 |
} |
56829 | 43 |
|
44 |
def check_hg(root: Path) |
|
45 |
{ |
|
56830
e760242101fc
tuned signature -- channels for diagnostic output for system tools means stderr;
wenzelm
parents:
56829
diff
changeset
|
46 |
Output.writeln("Checking " + root + " ...") |
62545
8ebffdaf2ce2
Bash.process always uses a closed script instead of an open argument list, for extra robustness on Windows, where quoting is not well-defined;
wenzelm
parents:
62454
diff
changeset
|
47 |
Isabelle_System.hg("--repository " + File.bash_path(root) + " root").check |
56829 | 48 |
for { |
62615 | 49 |
file <- Isabelle_System.hg("manifest", cwd = root.file).check.out_lines |
62226 | 50 |
if file.endsWith(".thy") || file.endsWith(".ML") || file.endsWith("/ROOT") |
56829 | 51 |
} check_file(root + Path.explode(file)) |
52 |
} |
|
53 |
||
54 |
||
62834 | 55 |
/* Isabelle tool wrapper */ |
56829 | 56 |
|
62834 | 57 |
val isabelle_tool = |
58 |
Isabelle_Tool("check_sources", "some sanity checks for Isabelle sources", args => |
|
59 |
{ |
|
62454 | 60 |
val getopts = Getopts(""" |
62452 | 61 |
Usage: isabelle check_sources [ROOT_DIRS...] |
62 |
||
63 |
Check .thy, .ML, ROOT files from manifest of Mercurial ROOT_DIRS. |
|
64 |
""") |
|
65 |
||
66 |
val specs = getopts(args) |
|
67 |
if (specs.isEmpty) getopts.usage() |
|
68 |
||
69 |
for (root <- specs) check_hg(Path.explode(root)) |
|
62834 | 70 |
}) |
56791 | 71 |
} |