src/Pure/PIDE/prover.scala
author wenzelm
Thu Apr 03 14:54:17 2014 +0200 (2014-04-03 ago)
changeset 56387 d92eb5c3960d
parent 56386 fe520afb8041
child 56393 22f533e6a049
permissions -rw-r--r--
more general prover operations;
wenzelm@56385
     1
/*  Title:      Pure/PIDE/prover.scala
wenzelm@56385
     2
    Author:     Makarius
wenzelm@56385
     3
wenzelm@56385
     4
General prover operations.
wenzelm@56385
     5
*/
wenzelm@56385
     6
wenzelm@56385
     7
package isabelle
wenzelm@56385
     8
wenzelm@56385
     9
wenzelm@56385
    10
object Prover
wenzelm@56385
    11
{
wenzelm@56385
    12
  /* messages */
wenzelm@56385
    13
wenzelm@56385
    14
  sealed abstract class Message
wenzelm@56385
    15
wenzelm@56386
    16
  class Input(val name: String, val args: List[String]) extends Message
wenzelm@56385
    17
  {
wenzelm@56385
    18
    override def toString: String =
wenzelm@56385
    19
      XML.Elem(Markup(Markup.PROVER_COMMAND, List((Markup.NAME, name))),
wenzelm@56385
    20
        args.map(s =>
wenzelm@56385
    21
          List(XML.Text("\n"), XML.elem(Markup.PROVER_ARG, YXML.parse_body(s)))).flatten).toString
wenzelm@56385
    22
  }
wenzelm@56385
    23
wenzelm@56385
    24
  class Output(val message: XML.Elem) extends Message
wenzelm@56385
    25
  {
wenzelm@56385
    26
    def kind: String = message.markup.name
wenzelm@56385
    27
    def properties: Properties.T = message.markup.properties
wenzelm@56385
    28
    def body: XML.Body = message.body
wenzelm@56385
    29
wenzelm@56385
    30
    def is_init = kind == Markup.INIT
wenzelm@56385
    31
    def is_exit = kind == Markup.EXIT
wenzelm@56385
    32
    def is_stdout = kind == Markup.STDOUT
wenzelm@56385
    33
    def is_stderr = kind == Markup.STDERR
wenzelm@56385
    34
    def is_system = kind == Markup.SYSTEM
wenzelm@56385
    35
    def is_status = kind == Markup.STATUS
wenzelm@56385
    36
    def is_report = kind == Markup.REPORT
wenzelm@56385
    37
    def is_syslog = is_init || is_exit || is_system || is_stderr
wenzelm@56385
    38
wenzelm@56385
    39
    override def toString: String =
wenzelm@56385
    40
    {
wenzelm@56385
    41
      val res =
wenzelm@56385
    42
        if (is_status || is_report) message.body.map(_.toString).mkString
wenzelm@56385
    43
        else Pretty.string_of(message.body)
wenzelm@56385
    44
      if (properties.isEmpty)
wenzelm@56385
    45
        kind.toString + " [[" + res + "]]"
wenzelm@56385
    46
      else
wenzelm@56385
    47
        kind.toString + " " +
wenzelm@56385
    48
          (for ((x, y) <- properties) yield x + "=" + y).mkString("{", ",", "}") + " [[" + res + "]]"
wenzelm@56385
    49
    }
wenzelm@56385
    50
  }
wenzelm@56385
    51
wenzelm@56385
    52
  class Protocol_Output(props: Properties.T, val bytes: Bytes)
wenzelm@56385
    53
    extends Output(XML.Elem(Markup(Markup.PROTOCOL, props), Nil))
wenzelm@56385
    54
  {
wenzelm@56385
    55
    lazy val text: String = bytes.toString
wenzelm@56385
    56
  }
wenzelm@56385
    57
}
wenzelm@56385
    58
wenzelm@56387
    59
trait Prover
wenzelm@56387
    60
{
wenzelm@56387
    61
  /* text and tree data */
wenzelm@56387
    62
wenzelm@56387
    63
  def encode(s: String): String
wenzelm@56387
    64
  def decode(s: String): String
wenzelm@56387
    65
wenzelm@56387
    66
  object Encode
wenzelm@56387
    67
  {
wenzelm@56387
    68
    val string: XML.Encode.T[String] = (s => XML.Encode.string(encode(s)))
wenzelm@56387
    69
  }
wenzelm@56387
    70
wenzelm@56387
    71
  def xml_cache: XML.Cache
wenzelm@56387
    72
wenzelm@56387
    73
wenzelm@56387
    74
  /* process management */
wenzelm@56387
    75
wenzelm@56387
    76
  def join(): Unit
wenzelm@56387
    77
  def terminate(): Unit
wenzelm@56387
    78
wenzelm@56387
    79
  def protocol_command_bytes(name: String, args: Bytes*): Unit
wenzelm@56387
    80
  def protocol_command(name: String, args: String*): Unit
wenzelm@56387
    81
wenzelm@56387
    82
wenzelm@56387
    83
  /* PIDE protocol commands */
wenzelm@56387
    84
wenzelm@56387
    85
  def options(opts: Options): Unit
wenzelm@56387
    86
wenzelm@56387
    87
  def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit
wenzelm@56387
    88
  def define_command(command: Command): Unit
wenzelm@56387
    89
wenzelm@56387
    90
  def discontinue_execution(): Unit
wenzelm@56387
    91
  def cancel_exec(id: Document_ID.Exec): Unit
wenzelm@56387
    92
wenzelm@56387
    93
  def update(old_id: Document_ID.Version, new_id: Document_ID.Version,
wenzelm@56387
    94
    edits: List[Document.Edit_Command]): Unit
wenzelm@56387
    95
  def remove_versions(versions: List[Document.Version]): Unit
wenzelm@56387
    96
wenzelm@56387
    97
  def dialog_result(serial: Long, result: String): Unit
wenzelm@56387
    98
}
wenzelm@56387
    99