author | wenzelm |
Fri, 17 Mar 2017 09:33:58 +0100 | |
changeset 65282 | f4c5f10829a0 |
parent 61276 | 8a4bd05c1735 |
child 65827 | 3bba3856b56c |
permissions | -rw-r--r-- |
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
1 |
/* Title: Pure/Tools/check_keywords.scala |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
3 |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
4 |
Check theory sources for conflicts with proposed keywords. |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
5 |
*/ |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
6 |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
7 |
package isabelle |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
8 |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
9 |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
10 |
object Check_Keywords |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
11 |
{ |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
12 |
def conflicts( |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
13 |
keywords: Keyword.Keywords, |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
14 |
check: Set[String], |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
15 |
input: CharSequence, |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
16 |
start: Token.Pos): List[(Token, Position.T)] = |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
17 |
{ |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
18 |
object Parser extends Parse.Parser |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
19 |
{ |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
20 |
private val conflict = |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
21 |
position(token("token", tok => !(tok.is_command || tok.is_keyword) && check(tok.source))) |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
22 |
private val other = token("token", _ => true) |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
23 |
private val item = conflict ^^ (x => Some(x)) | other ^^ (_ => None) |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
24 |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
25 |
val result = |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
26 |
parse_all(rep(item), Token.reader(Token.explode(keywords, input), start)) match { |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
27 |
case Success(res, _) => for (Some(x) <- res) yield x |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
28 |
case bad => error(bad.toString) |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
29 |
} |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
30 |
} |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
31 |
Parser.result |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
32 |
} |
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
33 |
|
59895 | 34 |
def check_keywords( |
61276 | 35 |
progress: Progress, |
59895 | 36 |
keywords: Keyword.Keywords, |
37 |
check: Set[String], |
|
38 |
paths: List[Path]) |
|
39 |
{ |
|
40 |
val parallel_args = paths.map(path => (File.read(path), Token.Pos.file(path.expand.implode))) |
|
41 |
||
42 |
val bad = |
|
43 |
Par_List.map((arg: (String, Token.Pos)) => { |
|
44 |
if (progress.stopped) throw Exn.Interrupt() |
|
45 |
conflicts(keywords, check, arg._1, arg._2) |
|
46 |
}, parallel_args).flatten |
|
47 |
||
48 |
for ((tok, pos) <- bad) { |
|
49 |
progress.echo(Output.warning_text( |
|
50 |
"keyword conflict: " + tok.kind.toString + " " + quote(tok.content) + |
|
51 |
Position.here(pos))) |
|
52 |
} |
|
53 |
} |
|
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
54 |
} |