src/Pure/Tools/print_operation.scala
author wenzelm
Tue, 14 Mar 2017 00:13:38 +0100
changeset 65220 420f55912b3e
parent 65219 ed4b47b8c7dc
child 65344 b99283eed13c
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59720
f893472fff31 proper headers;
wenzelm
parents: 59366
diff changeset
     1
/*  Title:      Pure/Tools/print_operation.scala
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     3
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     4
Print operations as asynchronous query.
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     5
*/
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     6
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     7
package isabelle
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     8
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
     9
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    10
object Print_Operation
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    11
{
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    12
  def print_operations(session: Session): List[(String, String)] =
59366
e94df7f6b608 clarified build_theories: proper protocol handler;
wenzelm
parents: 56864
diff changeset
    13
    session.get_protocol_handler("isabelle.Print_Operation$Handler") match {
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    14
      case Some(handler: Handler) => handler.get
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    15
      case _ => Nil
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    16
    }
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    17
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    18
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    19
  /* protocol handler */
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    20
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    21
  class Handler extends Session.Protocol_Handler
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    22
  {
61590
wenzelm
parents: 59720
diff changeset
    23
    private val print_operations = Synchronized[List[(String, String)]](Nil)
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    24
65220
wenzelm
parents: 65219
diff changeset
    25
    override def init(session: Session): Unit =
wenzelm
parents: 65219
diff changeset
    26
      session.protocol_command(Markup.PRINT_OPERATIONS)
wenzelm
parents: 65219
diff changeset
    27
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    28
    def get: List[(String, String)] = print_operations.value
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    29
65219
ed4b47b8c7dc misc tuning and simplification;
wenzelm
parents: 65213
diff changeset
    30
    private def put(msg: Prover.Protocol_Output): Boolean =
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    31
    {
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    32
      val ops =
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    33
      {
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    34
        import XML.Decode._
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    35
        list(pair(string, string))(YXML.parse_body(msg.text))
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    36
      }
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    37
      print_operations.change(_ => ops)
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    38
      true
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    39
    }
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    40
65219
ed4b47b8c7dc misc tuning and simplification;
wenzelm
parents: 65213
diff changeset
    41
    val functions = List(Markup.PRINT_OPERATIONS -> put _)
56864
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    42
  }
0446c7ac2e32 support print operations as asynchronous query;
wenzelm
parents:
diff changeset
    43
}