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