| author | wenzelm |
| Sun, 12 Nov 2023 22:34:08 +0100 | |
| changeset 78966 | 7419b8d473ac |
| parent 78592 | fdfe9b91d96e |
| child 80884 | f097ca0989e0 |
| 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 |
|
| 75393 | 10 |
object Check_Keywords {
|
|
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
11 |
def conflicts( |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
12 |
keywords: Keyword.Keywords, |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
13 |
check: Set[String], |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
14 |
input: CharSequence, |
| 75393 | 15 |
start: Token.Pos |
16 |
): List[(Token, Position.T)] = {
|
|
| 75405 | 17 |
object Parsers extends Parse.Parsers {
|
|
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
18 |
private val conflict = |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
19 |
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
|
20 |
private val other = token("token", _ => true)
|
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
21 |
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
|
22 |
|
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
23 |
val result = |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
24 |
parse_all(rep(item), Token.reader(Token.explode(keywords, input), start)) match {
|
| 78592 | 25 |
case Success(res, _) => for (case Some(x) <- res) yield x |
|
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
26 |
case bad => error(bad.toString) |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
27 |
} |
|
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
28 |
} |
| 75405 | 29 |
Parsers.result |
|
59891
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 |
|
| 59895 | 32 |
def check_keywords( |
| 61276 | 33 |
progress: Progress, |
| 59895 | 34 |
keywords: Keyword.Keywords, |
35 |
check: Set[String], |
|
| 75393 | 36 |
paths: List[Path] |
37 |
): Unit = {
|
|
| 76883 | 38 |
val parallel_args = |
39 |
paths.map(path => (File.read(path), Token.Pos.file(File.standard_path(path)))) |
|
| 59895 | 40 |
|
41 |
val bad = |
|
| 75394 | 42 |
Par_List.map({ (arg: (String, Token.Pos)) =>
|
| 67880 | 43 |
progress.expose_interrupt() |
| 59895 | 44 |
conflicts(keywords, check, arg._1, arg._2) |
45 |
}, parallel_args).flatten |
|
46 |
||
47 |
for ((tok, pos) <- bad) {
|
|
| 65827 | 48 |
progress.echo_warning( |
49 |
"keyword conflict: " + tok.kind.toString + " " + quote(tok.content) + Position.here(pos)) |
|
| 59895 | 50 |
} |
51 |
} |
|
|
59891
9ce697050455
added isabelle build option -k, for fast off-line checking of theory sources;
wenzelm
parents:
diff
changeset
|
52 |
} |