author | wenzelm |
Wed, 30 Dec 2009 17:48:58 +0100 | |
changeset 34813 | f0107bc96961 |
parent 34778 | 8eccd35e975e |
child 34815 | 6bae73cd8e33 |
permissions | -rw-r--r-- |
34407 | 1 |
/* |
2 |
* Prover commands with semantic state |
|
3 |
* |
|
4 |
* @author Johannes Hölzl, TU Munich |
|
5 |
* @author Fabian Immler, TU Munich |
|
6 |
*/ |
|
7 |
||
34760 | 8 |
package isabelle.proofdocument |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
9 |
|
34451 | 10 |
|
34699 | 11 |
import scala.actors.Actor, Actor._ |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
12 |
|
34497 | 13 |
import scala.collection.mutable |
34486 | 14 |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34769
diff
changeset
|
15 |
import isabelle.jedit.Isabelle |
34476 | 16 |
import isabelle.XML |
34451 | 17 |
|
18 |
||
34675 | 19 |
trait Accumulator extends Actor |
20 |
{ |
|
21 |
start() // start actor |
|
22 |
||
23 |
protected var _state: State |
|
24 |
def state = _state |
|
25 |
||
26 |
override def act() { |
|
27 |
loop { |
|
28 |
react { |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
34769
diff
changeset
|
29 |
case (session: Session, message: XML.Tree) => _state = _state.+(session, message) |
34769 | 30 |
case bad => System.err.println("Accumulator: ignoring bad message " + bad) |
34675 | 31 |
} |
32 |
} |
|
33 |
} |
|
34 |
} |
|
35 |
||
34451 | 36 |
|
34637 | 37 |
object Command |
38 |
{ |
|
39 |
object Status extends Enumeration |
|
40 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
41 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
42 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
43 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
44 |
} |
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
45 |
|
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
46 |
case class HighlightInfo(highlight: String) { override def toString = highlight } |
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
47 |
case class TypeInfo(ty: String) |
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
48 |
case class RefInfo(file: Option[String], line: Option[Int], |
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
49 |
command_id: Option[String], offset: Option[Int]) |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
50 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
51 |
|
34451 | 52 |
|
34697 | 53 |
class Command( |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
54 |
val id: Isar_Document.Command_ID, |
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
55 |
val tokens: List[Token], |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
56 |
val starts: Map[Token, Int]) extends Accumulator with Session.Entity |
34451 | 57 |
{ |
34637 | 58 |
require(!tokens.isEmpty) |
59 |
||
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
60 |
// FIXME override equality as well |
34653 | 61 |
override def hashCode = id.hashCode |
34637 | 62 |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
63 |
def consume(session: Session, message: XML.Tree) { this ! (session, message) } |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
64 |
|
34674 | 65 |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
66 |
/* content */ |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
67 |
|
34495 | 68 |
override def toString = name |
69 |
||
34526 | 70 |
val name = tokens.head.content |
34582 | 71 |
val content: String = Token.string_from_tokens(tokens, starts) |
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
72 |
def content(i: Int, j: Int): String = content.substring(i, j) |
34637 | 73 |
val symbol_index = new Symbol.Index(content) |
34451 | 74 |
|
34760 | 75 |
def start(doc: Proof_Document) = doc.token_start(tokens.first) |
76 |
def stop(doc: Proof_Document) = doc.token_start(tokens.last) + tokens.last.length |
|
34451 | 77 |
|
34593 | 78 |
def contains(p: Token) = tokens.contains(p) |
79 |
||
34697 | 80 |
protected override var _state = new State(this) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
81 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
82 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
83 |
/* markup */ |
34508 | 84 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
85 |
lazy val empty_markup = new Markup_Text(Nil, content) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
86 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
87 |
def markup_node(begin: Int, end: Int, info: Any): Markup_Tree = |
34699 | 88 |
{ |
34703 | 89 |
val start = symbol_index.decode(begin) |
90 |
val stop = symbol_index.decode(end) |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
91 |
new Markup_Tree(new Markup_Node(start, stop, info), Nil) |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
92 |
} |
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
93 |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
94 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
95 |
/* results, markup, ... */ |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
96 |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
97 |
private val empty_cmd_state = new Command_State("", this) // FIXME ? |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
98 |
private def cmd_state(doc: Proof_Document) = // FIXME clarify |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
99 |
doc.states.getOrElse(this, empty_cmd_state) |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
100 |
|
34760 | 101 |
def status(doc: Proof_Document) = cmd_state(doc).state.status |
102 |
def results(doc: Proof_Document) = cmd_state(doc).results |
|
103 |
def markup_root(doc: Proof_Document) = cmd_state(doc).markup_root |
|
104 |
def highlight(doc: Proof_Document) = cmd_state(doc).highlight |
|
105 |
def type_at(doc: Proof_Document, offset: Int) = cmd_state(doc).type_at(offset) |
|
106 |
def ref_at(doc: Proof_Document, offset: Int) = cmd_state(doc).ref_at(offset) |
|
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
107 |
} |
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
108 |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
109 |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
110 |
class Command_State( |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
111 |
override val id: Isar_Document.State_ID, |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
112 |
val command: Command) extends Accumulator with Session.Entity |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
113 |
{ |
34698 | 114 |
protected override var _state = new State(command) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
115 |
|
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
116 |
def consume(session: Session, message: XML.Tree) { this ! (session, message) } |
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
117 |
|
34746 | 118 |
def results: List[XML.Tree] = |
119 |
command.state.results ::: state.results |
|
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
120 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
121 |
def markup_root: Markup_Text = |
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
122 |
(command.state.markup_root /: state.markup_root.markup)(_ + _) |
34557 | 123 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
124 |
def type_at(pos: Int): Option[String] = state.type_at(pos) |
34556 | 125 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
126 |
def ref_at(pos: Int): Option[Markup_Node] = state.ref_at(pos) |
34568
b517d0607297
implemented IsabelleHyperlinkSource (only links inside the current buffer)
immler@in.tum.de
parents:
34564
diff
changeset
|
127 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
128 |
def highlight: Markup_Text = |
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
129 |
(command.state.highlight /: state.highlight.markup)(_ + _) |
34688 | 130 |
} |