author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Wed, 05 May 2010 15:30:01 +0200 | |
changeset 36675 | 806ea6e282e4 |
parent 36012 | 0614676f14d4 |
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 |
||
34871
e596a0b71f3c
incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents:
34865
diff
changeset
|
8 |
package isabelle |
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._ |
34497 | 12 |
import scala.collection.mutable |
34486 | 13 |
|
34451 | 14 |
|
34637 | 15 |
object Command |
16 |
{ |
|
17 |
object Status extends Enumeration |
|
18 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
19 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
20 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
21 |
val FAILED = Value("FAILED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
22 |
} |
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
23 |
|
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
24 |
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
|
25 |
case class TypeInfo(ty: String) |
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
26 |
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
|
27 |
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
|
28 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
29 |
|
34451 | 30 |
|
34697 | 31 |
class Command( |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
32 |
val id: Isar_Document.Command_ID, |
34859 | 33 |
val span: Thy_Syntax.Span) |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
34 |
extends Session.Entity |
34451 | 35 |
{ |
34859 | 36 |
/* classification */ |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
37 |
|
36012 | 38 |
def is_command: Boolean = !span.isEmpty && span.head.is_command |
34865 | 39 |
def is_ignored: Boolean = span.forall(_.is_ignored) |
34859 | 40 |
def is_malformed: Boolean = !is_command && !is_ignored |
41 |
||
36012 | 42 |
def name: String = if (is_command) span.head.content else "" |
34859 | 43 |
override def toString = if (is_command) name else if (is_ignored) "<ignored>" else "<malformed>" |
34495 | 44 |
|
34859 | 45 |
|
46 |
/* source text */ |
|
34451 | 47 |
|
34859 | 48 |
val source: String = span.map(_.source).mkString |
49 |
def source(i: Int, j: Int): String = source.substring(i, j) |
|
50 |
def length: Int = source.length |
|
34855
81d0410dc3ac
iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents:
34835
diff
changeset
|
51 |
|
34859 | 52 |
lazy val symbol_index = new Symbol.Index(source) |
34593 | 53 |
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
54 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
55 |
/* accumulated messages */ |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
56 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
57 |
@volatile protected var state = new State(this) |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
58 |
def current_state: State = state |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
59 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
60 |
private case class Consume(session: Session, message: XML.Tree) |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
61 |
private case object Assign |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
62 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
63 |
private val accumulator = actor { |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
64 |
var assigned = false |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
65 |
loop { |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
66 |
react { |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
67 |
case Consume(session: Session, message: XML.Tree) if !assigned => |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
68 |
state = state.+(session, message) |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
69 |
|
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
70 |
case Assign => |
34835
67733fd0e3fa
back to explicit management of documents -- not as generic Session.Entity -- to avoid ill-defined referencing of new states;
wenzelm
parents:
34832
diff
changeset
|
71 |
assigned = true // single assignment |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
72 |
reply(()) |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
73 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
74 |
case bad => System.err.println("command accumulator: ignoring bad message " + bad) |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
75 |
} |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
76 |
} |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
77 |
} |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
78 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
79 |
def consume(session: Session, message: XML.Tree) { accumulator ! Consume(session, message) } |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
80 |
|
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
81 |
def assign_state(state_id: Isar_Document.State_ID): Command = |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
82 |
{ |
34859 | 83 |
val cmd = new Command(state_id, span) |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
84 |
accumulator !? Assign |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
85 |
cmd.state = current_state |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
86 |
cmd |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
87 |
} |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
88 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
89 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
90 |
/* markup */ |
34508 | 91 |
|
34859 | 92 |
lazy val empty_markup = new Markup_Text(Nil, source) |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
93 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
94 |
def markup_node(begin: Int, end: Int, info: Any): Markup_Tree = |
34699 | 95 |
{ |
34703 | 96 |
val start = symbol_index.decode(begin) |
97 |
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
|
98 |
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
|
99 |
} |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
100 |
} |