author | wenzelm |
Sat, 05 Sep 2009 00:35:37 +0200 | |
changeset 34707 | cc5d388fcbf2 |
parent 34703 | ff037c17332a |
child 34709 | 2f0c18f9b6c7 |
permissions | -rw-r--r-- |
34675 | 1 |
/* |
2 |
* Accumulating results from prover |
|
3 |
* |
|
4 |
* @author Fabian Immler, TU Munich |
|
5 |
*/ |
|
6 |
||
7 |
package isabelle.prover |
|
8 |
||
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
9 |
|
34697 | 10 |
class State( |
11 |
val command: Command, |
|
12 |
val status: Command.Status.Value, |
|
13 |
rev_results: List[XML.Tree], |
|
14 |
val markup_root: MarkupNode) |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
15 |
{ |
34697 | 16 |
def this(command: Command) = |
17 |
this(command, Command.Status.UNPROCESSED, Nil, command.empty_root_node) |
|
18 |
||
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
19 |
|
34697 | 20 |
/* content */ |
21 |
||
22 |
private def set_status(st: Command.Status.Value): State = |
|
23 |
new State(command, st, rev_results, markup_root) |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
24 |
|
34697 | 25 |
private def add_result(res: XML.Tree): State = |
26 |
new State(command, status, res :: rev_results, markup_root) |
|
27 |
||
28 |
private def add_markup(markup: MarkupNode): State = |
|
29 |
new State(command, status, rev_results, markup_root + markup) |
|
30 |
||
31 |
lazy val results = rev_results.reverse |
|
32 |
||
34688 | 33 |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
34 |
/* markup */ |
34697 | 35 |
|
34688 | 36 |
lazy val highlight_node: MarkupNode = |
37 |
{ |
|
38 |
markup_root.filter(_.info match { |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
39 |
case Command.RootInfo | Command.HighlightInfo(_) => true |
34688 | 40 |
case _ => false |
41 |
}).head |
|
42 |
} |
|
43 |
||
44 |
lazy private val types = |
|
45 |
markup_root.filter(_.info match { |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
46 |
case Command.TypeInfo(_) => true |
34688 | 47 |
case _ => false }).flatten(_.flatten) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
48 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
49 |
def type_at(pos: Int): String = |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
50 |
{ |
34688 | 51 |
types.find(t => t.start <= pos && t.stop > pos).map(t => |
52 |
t.content + ": " + (t.info match { |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
53 |
case Command.TypeInfo(i) => i |
34688 | 54 |
case _ => "" })). |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
55 |
getOrElse(null) |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
56 |
} |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
57 |
|
34688 | 58 |
lazy private val refs = |
59 |
markup_root.filter(_.info match { |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
60 |
case Command.RefInfo(_, _, _, _) => true |
34688 | 61 |
case _ => false }).flatten(_.flatten) |
62 |
||
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
63 |
def ref_at(pos: Int): Option[MarkupNode] = |
34703 | 64 |
refs.find(t => t.start <= pos && pos < t.stop) |
34688 | 65 |
|
66 |
||
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
67 |
|
34697 | 68 |
/* message dispatch */ |
69 |
||
70 |
def + (message: XML.Tree): State = |
|
71 |
{ |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
72 |
val changed: State = |
34703 | 73 |
message match { |
74 |
case XML.Elem(Markup.MESSAGE, (Markup.CLASS, Markup.WRITELN) :: _, _) |
|
75 |
| XML.Elem(Markup.MESSAGE, (Markup.CLASS, Markup.PRIORITY) :: _, _) |
|
76 |
| XML.Elem(Markup.MESSAGE, (Markup.CLASS, Markup.WARNING) :: _, _) => |
|
77 |
add_result(message) |
|
78 |
case XML.Elem(Markup.MESSAGE, (Markup.CLASS, Markup.ERROR) :: _, _) => |
|
79 |
set_status(Command.Status.FAILED).add_result(message) |
|
80 |
case XML.Elem(Markup.MESSAGE, (Markup.CLASS, Markup.STATUS) :: _, elems) => |
|
81 |
(this /: elems) ((st, e) => |
|
82 |
e match { |
|
83 |
// command status |
|
84 |
case XML.Elem(Markup.UNPROCESSED, _, _) => |
|
85 |
st.set_status(Command.Status.UNPROCESSED) |
|
86 |
case XML.Elem(Markup.FINISHED, _, _) => |
|
87 |
st.set_status(Command.Status.FINISHED) |
|
88 |
case XML.Elem(Markup.FAILED, _, _) => |
|
89 |
st.set_status(Command.Status.FAILED) |
|
90 |
case XML.Elem(kind, attr, body) => |
|
91 |
val (begin, end) = Position.offsets_of(attr) |
|
92 |
if (begin.isDefined && end.isDefined) { |
|
93 |
if (kind == Markup.ML_TYPING) { |
|
94 |
val info = body.first.asInstanceOf[XML.Text].content |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
95 |
st.add_markup( |
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
96 |
command.markup_node(begin.get - 1, end.get - 1, Command.TypeInfo(info))) |
34703 | 97 |
} |
98 |
else if (kind == Markup.ML_REF) { |
|
99 |
body match { |
|
100 |
case List(XML.Elem(Markup.ML_DEF, attr, _)) => |
|
101 |
st.add_markup(command.markup_node( |
|
102 |
begin.get - 1, end.get - 1, |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
103 |
Command.RefInfo( |
34703 | 104 |
Position.file_of(attr), |
105 |
Position.line_of(attr), |
|
106 |
Position.id_of(attr), |
|
107 |
Position.offset_of(attr)))) |
|
108 |
case _ => st |
|
109 |
} |
|
110 |
} |
|
111 |
else { |
|
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
112 |
st.add_markup( |
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34703
diff
changeset
|
113 |
command.markup_node(begin.get - 1, end.get - 1, Command.HighlightInfo(kind))) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
114 |
} |
34697 | 115 |
} |
34703 | 116 |
else st |
117 |
case _ => st |
|
118 |
}) |
|
119 |
case _ => |
|
120 |
System.err.println("ignored: " + message) |
|
121 |
this |
|
122 |
} |
|
34697 | 123 |
command.changed() |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
124 |
changed |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
125 |
} |
34675 | 126 |
} |