author | wenzelm |
Fri, 28 May 2010 22:21:08 +0200 | |
changeset 37178 | d52f934f8ff6 |
parent 37129 | 4c83696b340e |
child 37189 | 2b4e52ecf6fc |
permissions | -rw-r--r-- |
36676 | 1 |
/* Title: Pure/PIDE/command.scala |
2 |
Author: Johannes Hölzl, TU Munich |
|
3 |
Author: Fabian Immler, TU Munich |
|
4 |
Author: Makarius |
|
5 |
||
6 |
Prover commands with semantic state. |
|
7 |
*/ |
|
34407 | 8 |
|
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
|
9 |
package isabelle |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
10 |
|
34451 | 11 |
|
34699 | 12 |
import scala.actors.Actor, Actor._ |
34497 | 13 |
import scala.collection.mutable |
34486 | 14 |
|
34451 | 15 |
|
37129 | 16 |
case class Command_Set(set: Set[Command]) |
17 |
||
18 |
||
34637 | 19 |
object Command |
20 |
{ |
|
21 |
object Status extends Enumeration |
|
22 |
{ |
|
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
23 |
val UNPROCESSED = Value("UNPROCESSED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
24 |
val FINISHED = Value("FINISHED") |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
25 |
val FAILED = Value("FAILED") |
36990
449628c148cf
explicit Command.Status.UNDEFINED -- avoid fragile/cumbersome treatment of Option[State];
wenzelm
parents:
36676
diff
changeset
|
26 |
val UNDEFINED = Value("UNDEFINED") |
34318
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
27 |
} |
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
28 |
|
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
29 |
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
|
30 |
case class TypeInfo(ty: String) |
34707
cc5d388fcbf2
eliminated MarkupInfo, moved particular variants into object Command;
wenzelm
parents:
34705
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
} |
c13e168a8ae6
original sources from Johannes Hölzl a48e0c6ab1aea77c52d596f7efc007a543d3d10c with minor modifications of directory layout;
wenzelm
parents:
diff
changeset
|
34 |
|
34697 | 35 |
class Command( |
34813
f0107bc96961
more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents:
34778
diff
changeset
|
36 |
val id: Isar_Document.Command_ID, |
37129 | 37 |
val span: Thy_Syntax.Span, |
38 |
val static_parent: Option[Command] = None) |
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
39 |
extends Session.Entity |
34451 | 40 |
{ |
34859 | 41 |
/* classification */ |
34500
384427c750c8
state_results: separate buffer for messages from running command;
wenzelm
parents:
34497
diff
changeset
|
42 |
|
36012 | 43 |
def is_command: Boolean = !span.isEmpty && span.head.is_command |
34865 | 44 |
def is_ignored: Boolean = span.forall(_.is_ignored) |
34859 | 45 |
def is_malformed: Boolean = !is_command && !is_ignored |
46 |
||
36012 | 47 |
def name: String = if (is_command) span.head.content else "" |
37129 | 48 |
override def toString = |
49 |
if (is_command) name + "(" + id + ")" |
|
50 |
else if (is_ignored) "<ignored>" else "<malformed>" |
|
34495 | 51 |
|
34859 | 52 |
|
53 |
/* source text */ |
|
34451 | 54 |
|
34859 | 55 |
val source: String = span.map(_.source).mkString |
56 |
def source(i: Int, j: Int): String = source.substring(i, j) |
|
57 |
def length: Int = source.length |
|
34855
81d0410dc3ac
iterators for ranges of commands/starts -- avoid extra array per document;
wenzelm
parents:
34835
diff
changeset
|
58 |
|
34859 | 59 |
lazy val symbol_index = new Symbol.Index(source) |
34593 | 60 |
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
61 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
62 |
/* accumulated messages */ |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
63 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
64 |
@volatile protected var state = new State(this) |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
65 |
def current_state: State = state |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
66 |
|
37129 | 67 |
private case class Consume(message: XML.Tree, forward: Command => Unit) |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
68 |
private case object Assign |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
69 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
70 |
private val accumulator = actor { |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
71 |
var assigned = false |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
72 |
loop { |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
73 |
react { |
37129 | 74 |
case Consume(message, forward) if !assigned => |
75 |
val old_state = state |
|
37178
d52f934f8ff6
accumulate only local results -- no proper history support yet;
wenzelm
parents:
37129
diff
changeset
|
76 |
state = old_state.accumulate(message) |
37129 | 77 |
if (!(state eq old_state)) forward(static_parent getOrElse this) |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
78 |
|
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
79 |
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
|
80 |
assigned = true // single assignment |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
81 |
reply(()) |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
82 |
|
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
83 |
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
|
84 |
} |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
85 |
} |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
86 |
} |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
87 |
|
37129 | 88 |
def consume(message: XML.Tree, forward: Command => Unit) |
89 |
{ |
|
90 |
accumulator ! Consume(message, forward) |
|
91 |
} |
|
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
92 |
|
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
93 |
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
|
94 |
{ |
37129 | 95 |
val cmd = new Command(state_id, span, Some(this)) |
34832
d785f72ef388
more explicit treatment of command/document state;
wenzelm
parents:
34823
diff
changeset
|
96 |
accumulator !? Assign |
34815
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
97 |
cmd.state = current_state |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
98 |
cmd |
6bae73cd8e33
unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents:
34813
diff
changeset
|
99 |
} |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
100 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
101 |
|
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
102 |
/* markup */ |
34508 | 103 |
|
34859 | 104 |
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
|
105 |
|
34717
3f32e08bbb6c
sidekick root data: set buffer length to avoid crash of initial caret move;
wenzelm
parents:
34708
diff
changeset
|
106 |
def markup_node(begin: Int, end: Int, info: Any): Markup_Tree = |
34699 | 107 |
{ |
34703 | 108 |
val start = symbol_index.decode(begin) |
109 |
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
|
110 |
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
|
111 |
} |
34676
9e725d34df7b
Command and Command_State handle results from prover as Accumulator
immler@in.tum.de
parents:
34675
diff
changeset
|
112 |
} |