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