src/Pure/PIDE/prover.scala
author wenzelm
Mon Aug 11 22:29:48 2014 +0200 (2014-08-11)
changeset 57901 e1abca2527da
parent 56394 bbf4d512f395
child 57905 c0c5652e796e
permissions -rw-r--r--
more explicit type Span in Scala, according to ML version;
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@56393
    12
  /* syntax */
wenzelm@56393
    13
wenzelm@56393
    14
  trait Syntax
wenzelm@56393
    15
  {
wenzelm@56393
    16
    def add_keywords(keywords: Thy_Header.Keywords): Syntax
wenzelm@56393
    17
    def scan(input: CharSequence): List[Token]
wenzelm@57901
    18
    def load_command(name: String): Option[List[String]]
wenzelm@56393
    19
    def load_commands_in(text: String): Boolean
wenzelm@56393
    20
  }
wenzelm@56393
    21
wenzelm@56393
    22
wenzelm@56385
    23
  /* messages */
wenzelm@56385
    24
wenzelm@56385
    25
  sealed abstract class Message
wenzelm@56385
    26
wenzelm@56386
    27
  class Input(val name: String, val args: List[String]) extends Message
wenzelm@56385
    28
  {
wenzelm@56385
    29
    override def toString: String =
wenzelm@56385
    30
      XML.Elem(Markup(Markup.PROVER_COMMAND, List((Markup.NAME, name))),
wenzelm@56385
    31
        args.map(s =>
wenzelm@56385
    32
          List(XML.Text("\n"), XML.elem(Markup.PROVER_ARG, YXML.parse_body(s)))).flatten).toString
wenzelm@56385
    33
  }
wenzelm@56385
    34
wenzelm@56385
    35
  class Output(val message: XML.Elem) extends Message
wenzelm@56385
    36
  {
wenzelm@56385
    37
    def kind: String = message.markup.name
wenzelm@56385
    38
    def properties: Properties.T = message.markup.properties
wenzelm@56385
    39
    def body: XML.Body = message.body
wenzelm@56385
    40
wenzelm@56385
    41
    def is_init = kind == Markup.INIT
wenzelm@56385
    42
    def is_exit = kind == Markup.EXIT
wenzelm@56385
    43
    def is_stdout = kind == Markup.STDOUT
wenzelm@56385
    44
    def is_stderr = kind == Markup.STDERR
wenzelm@56385
    45
    def is_system = kind == Markup.SYSTEM
wenzelm@56385
    46
    def is_status = kind == Markup.STATUS
wenzelm@56385
    47
    def is_report = kind == Markup.REPORT
wenzelm@56385
    48
    def is_syslog = is_init || is_exit || is_system || is_stderr
wenzelm@56385
    49
wenzelm@56385
    50
    override def toString: String =
wenzelm@56385
    51
    {
wenzelm@56385
    52
      val res =
wenzelm@56385
    53
        if (is_status || is_report) message.body.map(_.toString).mkString
wenzelm@56385
    54
        else Pretty.string_of(message.body)
wenzelm@56385
    55
      if (properties.isEmpty)
wenzelm@56385
    56
        kind.toString + " [[" + res + "]]"
wenzelm@56385
    57
      else
wenzelm@56385
    58
        kind.toString + " " +
wenzelm@56385
    59
          (for ((x, y) <- properties) yield x + "=" + y).mkString("{", ",", "}") + " [[" + res + "]]"
wenzelm@56385
    60
    }
wenzelm@56385
    61
  }
wenzelm@56385
    62
wenzelm@56385
    63
  class Protocol_Output(props: Properties.T, val bytes: Bytes)
wenzelm@56385
    64
    extends Output(XML.Elem(Markup(Markup.PROTOCOL, props), Nil))
wenzelm@56385
    65
  {
wenzelm@56385
    66
    lazy val text: String = bytes.toString
wenzelm@56385
    67
  }
wenzelm@56385
    68
}
wenzelm@56385
    69
wenzelm@56393
    70
wenzelm@56387
    71
trait Prover
wenzelm@56387
    72
{
wenzelm@56387
    73
  /* text and tree data */
wenzelm@56387
    74
wenzelm@56387
    75
  def encode(s: String): String
wenzelm@56387
    76
  def decode(s: String): String
wenzelm@56387
    77
wenzelm@56387
    78
  object Encode
wenzelm@56387
    79
  {
wenzelm@56387
    80
    val string: XML.Encode.T[String] = (s => XML.Encode.string(encode(s)))
wenzelm@56387
    81
  }
wenzelm@56387
    82
wenzelm@56387
    83
  def xml_cache: XML.Cache
wenzelm@56387
    84
wenzelm@56387
    85
wenzelm@56387
    86
  /* process management */
wenzelm@56387
    87
wenzelm@56387
    88
  def join(): Unit
wenzelm@56387
    89
  def terminate(): Unit
wenzelm@56387
    90
wenzelm@56387
    91
  def protocol_command_bytes(name: String, args: Bytes*): Unit
wenzelm@56387
    92
  def protocol_command(name: String, args: String*): Unit
wenzelm@56387
    93
wenzelm@56387
    94
wenzelm@56387
    95
  /* PIDE protocol commands */
wenzelm@56387
    96
wenzelm@56387
    97
  def options(opts: Options): Unit
wenzelm@56387
    98
wenzelm@56387
    99
  def define_blob(digest: SHA1.Digest, bytes: Bytes): Unit
wenzelm@56387
   100
  def define_command(command: Command): Unit
wenzelm@56387
   101
wenzelm@56387
   102
  def discontinue_execution(): Unit
wenzelm@56387
   103
  def cancel_exec(id: Document_ID.Exec): Unit
wenzelm@56387
   104
wenzelm@56387
   105
  def update(old_id: Document_ID.Version, new_id: Document_ID.Version,
wenzelm@56387
   106
    edits: List[Document.Edit_Command]): Unit
wenzelm@56387
   107
  def remove_versions(versions: List[Document.Version]): Unit
wenzelm@56387
   108
wenzelm@56387
   109
  def dialog_result(serial: Long, result: String): Unit
wenzelm@56387
   110
}
wenzelm@56387
   111