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