63603
|
1 |
/* Title: Pure/Isar/line_structure.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Line-oriented document structure, e.g. for fold handling.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
75393
|
10 |
object Line_Structure {
|
71601
|
11 |
val init: Line_Structure = Line_Structure()
|
63603
|
12 |
}
|
|
13 |
|
|
14 |
sealed case class Line_Structure(
|
|
15 |
improper: Boolean = true,
|
66177
|
16 |
blank: Boolean = true,
|
63603
|
17 |
command: Boolean = false,
|
|
18 |
depth: Int = 0,
|
|
19 |
span_depth: Int = 0,
|
|
20 |
after_span_depth: Int = 0,
|
75393
|
21 |
element_depth: Int = 0
|
|
22 |
) {
|
|
23 |
def update(keywords: Keyword.Keywords, tokens: List[Token]): Line_Structure = {
|
68730
|
24 |
val improper1 = tokens.forall(tok => !tok.is_proper)
|
66177
|
25 |
val blank1 = tokens.forall(_.is_space)
|
63603
|
26 |
val command1 = tokens.exists(_.is_begin_or_command)
|
|
27 |
|
|
28 |
val command_depth =
|
73345
|
29 |
tokens.iterator.filter(_.is_proper).nextOption() match {
|
63603
|
30 |
case Some(tok) =>
|
|
31 |
if (keywords.is_command(tok, Keyword.close_structure))
|
|
32 |
Some(after_span_depth - 1)
|
|
33 |
else None
|
|
34 |
case None => None
|
|
35 |
}
|
|
36 |
|
|
37 |
val depth1 =
|
|
38 |
if (tokens.exists(tok =>
|
|
39 |
keywords.is_before_command(tok) ||
|
|
40 |
!tok.is_end && keywords.is_command(tok, Keyword.theory))) element_depth
|
|
41 |
else if (command_depth.isDefined) command_depth.get
|
|
42 |
else if (command1) after_span_depth
|
|
43 |
else span_depth
|
|
44 |
|
|
45 |
val (span_depth1, after_span_depth1, element_depth1) =
|
73359
|
46 |
tokens.foldLeft((span_depth, after_span_depth, element_depth)) {
|
63603
|
47 |
case (depths @ (x, y, z), tok) =>
|
|
48 |
if (tok.is_begin) (z + 2, z + 1, z + 1)
|
|
49 |
else if (tok.is_end) (z + 1, z - 1, z - 1)
|
|
50 |
else if (tok.is_command) {
|
|
51 |
val depth0 = element_depth
|
|
52 |
if (keywords.is_command(tok, Keyword.theory_goal)) (depth0 + 2, depth0 + 1, z)
|
|
53 |
else if (keywords.is_command(tok, Keyword.theory)) (depth0 + 1, depth0, z)
|
|
54 |
else if (keywords.is_command(tok, Keyword.proof_open)) (y + 2, y + 1, z)
|
|
55 |
else if (keywords.is_command(tok, Set(Keyword.PRF_BLOCK))) (y + 2, y + 1, z)
|
|
56 |
else if (keywords.is_command(tok, Set(Keyword.QED_BLOCK))) (y - 1, y - 2, z)
|
|
57 |
else if (keywords.is_command(tok, Set(Keyword.PRF_CLOSE))) (y, y - 1, z)
|
|
58 |
else if (keywords.is_command(tok, Keyword.proof_close)) (y + 1, y - 1, z)
|
|
59 |
else if (keywords.is_command(tok, Keyword.qed_global)) (depth0 + 1, depth0, z)
|
|
60 |
else depths
|
|
61 |
}
|
|
62 |
else depths
|
|
63 |
}
|
|
64 |
|
66177
|
65 |
Line_Structure(
|
|
66 |
improper1, blank1, command1, depth1, span_depth1, after_span_depth1, element_depth1)
|
63603
|
67 |
}
|
|
68 |
}
|