src/Doc/System/Server.thy
author wenzelm
Sat, 19 May 2018 15:45:45 +0200
changeset 68219 c0341c0080e2
parent 68152 619de043389f
child 68224 1f7308050349
permissions -rw-r--r--
clarified store directories; discontinued settings ISABELLE_PATH, ISABELLE_OUTPUT;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     1
(*:maxLineLen=78:*)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     2
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     3
theory Server
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     4
imports Base
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     5
begin
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     6
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     7
chapter \<open>The Isabelle server\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     8
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
     9
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    10
  An Isabelle session requires at least two processes, which are both rather
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    11
  heavy: Isabelle/Scala for the system infrastructure and Isabelle/ML for the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    12
  logic session (e.g.\ HOL). In principle, these processes can be invoked
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    13
  directly on the command-line, e.g.\ via @{tool java}, @{tool scala}, @{tool
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    14
  process}, @{tool console}, but this approach is inadequate for reactive
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    15
  applications that require quick responses from the prover.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    16
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    17
  In contrast, the Isabelle server exposes Isabelle/Scala as a
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    18
  ``terminate-stay-resident'' application that manages multiple logic
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    19
  \<^emph>\<open>sessions\<close> and concurrent tasks to use \<^emph>\<open>theories\<close>. This provides an
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    20
  analogous to @{ML Thy_Info.use_theories} in Isabelle/ML, but with full
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    21
  concurrency and Isabelle/PIDE markup.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    22
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    23
  The client/server arrangement via TCP sockets also opens possibilities for
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    24
  remote Isabelle services that are accessed by local applications, e.g.\ via
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    25
  an SSH tunnel.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    26
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    27
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    28
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    29
section \<open>Command-line tools\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    30
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    31
subsection \<open>Server \label{sec:tool-server}\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    32
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    33
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    34
  The @{tool_def server} tool manages resident server processes:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    35
  @{verbatim [display]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    36
\<open>Usage: isabelle server [OPTIONS]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    37
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    38
  Options are:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    39
    -L FILE      logging on FILE
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    40
    -c           console interaction with specified server
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    41
    -l           list servers (alternative operation)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    42
    -n NAME      explicit server name (default: isabelle)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    43
    -p PORT      explicit server port
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    44
    -s           assume existing server, no implicit startup
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    45
    -x           exit specified server (alternative operation)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    46
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    47
  Manage resident Isabelle servers.\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    48
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    49
  The main operation of \<^verbatim>\<open>isabelle server\<close> is to ensure that a named server is
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    50
  running, either by finding an already running process (according to the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    51
  central database file @{path "$ISABELLE_HOME_USER/servers.db"}) or by
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    52
  becoming itself a new server that accepts connections on a particular TCP
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    53
  socket. The server name and its address are printed as initial output line.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    54
  If another server instance is already running, the current
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    55
  \<^verbatim>\<open>isabelle server\<close> process will terminate; otherwise, it keeps running as a
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    56
  new server process until an explicit \<^verbatim>\<open>shutdown\<close> command is received.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    57
  Further details of the server socket protocol are explained in
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    58
  \secref{sec:server-protocol}.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    59
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    60
  Other server management operations are invoked via options \<^verbatim>\<open>-l\<close> and \<^verbatim>\<open>-x\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    61
  (see below).
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    62
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    63
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    64
  Option \<^verbatim>\<open>-n\<close> specifies an alternative server name: at most one process for
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    65
  each name may run, but each server instance supports multiple connections
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    66
  and logic sessions.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    67
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    68
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    69
  Option \<^verbatim>\<open>-p\<close> specifies an explicit TCP port for the server socket (which is
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    70
  always on \<^verbatim>\<open>localhost\<close>): the default is to let the operating system assign a
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    71
  free port number.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    72
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    73
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    74
  Option \<^verbatim>\<open>-s\<close> strictly assumes that the specified server process is already
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    75
  running, skipping the optional server startup phase.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    76
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    77
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    78
  Option \<^verbatim>\<open>-c\<close> connects the console in/out channels after the initial check
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    79
  for a suitable server process. Also note that the @{tool client} tool
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    80
  (\secref{sec:tool-client}) provides a command-line editor to interact with
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    81
  the server.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    82
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    83
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    84
  Option \<^verbatim>\<open>-L\<close> specifies a log file for exceptional output of internal server
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    85
  and session operations.
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    86
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    87
  \<^medskip>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    88
  Operation \<^verbatim>\<open>-l\<close> lists all active server processes with their connection
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    89
  details.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    90
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    91
  \<^medskip>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    92
  Operation \<^verbatim>\<open>-x\<close> exits the specified server process by sending it a
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
    93
  \<^verbatim>\<open>shutdown\<close> command.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    94
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    95
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    96
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    97
subsection \<open>Client \label{sec:tool-client}\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    98
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
    99
text \<open>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   100
  The @{tool_def client} tool provides console interaction for Isabelle
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   101
  servers:
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   102
  @{verbatim [display]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   103
\<open>Usage: isabelle client [OPTIONS]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   104
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   105
  Options are:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   106
    -n NAME      explicit server name
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   107
    -p PORT      explicit server port
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   108
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   109
  Console interaction for Isabelle server (with line-editor).\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   110
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   111
  This is a wrapper to \<^verbatim>\<open>isabelle server -s -c\<close> for interactive
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   112
  experimentation, which uses @{setting ISABELLE_LINE_EDITOR} if available.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   113
  The server name is sufficient for identification, as the client can
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   114
  determine the connection details from the local database of active servers.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   115
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   116
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   117
  Option \<^verbatim>\<open>-n\<close> specifies an explicit server name as in @{tool server}.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   118
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   119
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   120
  Option \<^verbatim>\<open>-p\<close> specifies an explicit server port as in @{tool server}.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   121
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   122
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   123
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   124
subsection \<open>Examples\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   125
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   126
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   127
  Ensure that a particular server instance is running in the background:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   128
  @{verbatim [display] \<open>isabelle server -n test &\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   129
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   130
  The first line of output presents the connection details:\<^footnote>\<open>This information
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   131
  may be used in other TCP clients, without access to Isabelle/Scala and the
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   132
  underlying database of running servers.\<close>
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   133
  @{verbatim [display] \<open>server "test" = 127.0.0.1:4711 (password "XYZ")\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   134
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   135
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   136
  List available server processes:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   137
  @{verbatim [display] \<open>isabelle server -l\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   138
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   139
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   140
  Connect the command-line client to the above test server:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   141
  @{verbatim [display] \<open>isabelle client -n test\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   142
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   143
  Interaction now works on a line-by-line basis, with commands like \<^verbatim>\<open>help\<close> or
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   144
  \<^verbatim>\<open>echo\<close>. For example, some JSON values may be echoed like this:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   145
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   146
  @{verbatim [display]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   147
\<open>echo 42
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   148
echo [1, 2, 3]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   149
echo {"a": "text", "b": true, "c": 42}\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   150
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   151
  Closing the connection (via CTRL-D) leaves the server running: it is
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   152
  possible to reconnect again, and have multiple connections at the same time.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   153
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   154
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   155
  Exit the named server on the command-line:
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   156
  @{verbatim [display] \<open>isabelle server -n test -x\<close>}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   157
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   158
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   159
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   160
section \<open>Protocol messages \label{sec:server-protocol}\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   161
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   162
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   163
  The Isabelle server listens on a regular TCP socket, using a line-oriented
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   164
  protocol of structured messages. Input \<^emph>\<open>commands\<close> and output \<^emph>\<open>results\<close>
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   165
  (via \<^verbatim>\<open>OK\<close> or \<^verbatim>\<open>ERROR\<close>) are strictly alternating on the toplevel, but
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   166
  commands may also return a \<^emph>\<open>task\<close> identifier to indicate an ongoing
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   167
  asynchronous process that is joined later (via \<^verbatim>\<open>FINISHED\<close> or \<^verbatim>\<open>FAILED\<close>).
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   168
  Asynchronous \<^verbatim>\<open>NOTE\<close> messages may occur at any time: they are independent of
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   169
  the main command-result protocol.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   170
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   171
  For example, the synchronous \<^verbatim>\<open>echo\<close> command immediately returns its
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   172
  argument as \<^verbatim>\<open>OK\<close> result. In contrast, the asynchronous \<^verbatim>\<open>session_build\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   173
  command returns \<^verbatim>\<open>OK {"task":\<close>\<open>id\<close>\<^verbatim>\<open>}\<close> and continues in the background. It
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   174
  will eventually produce \<^verbatim>\<open>FINISHED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> or
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   175
  \<^verbatim>\<open>FAILED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> with the final result. Intermediately, it
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   176
  may emit asynchronous messages of the form \<^verbatim>\<open>NOTE {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   177
  to inform about its progress. Due to the explicit task identifier, the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   178
  client can show these messages in the proper context, e.g.\ a GUI window for
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   179
  this particular session build job.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   180
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   181
  \medskip Subsequently, the protocol message formats are described in further
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   182
  detail.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   183
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   184
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   185
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   186
subsection \<open>Byte messages\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   187
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   188
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   189
  The client-server connection is a raw byte-channel for bidirectional
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   190
  communication, but the Isabelle server always works with messages of a
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   191
  particular length. Messages are written as a single chunk that is flushed
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   192
  immediately.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   193
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   194
  Message boundaries are determined as follows:
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   195
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   196
    \<^item> A \<^emph>\<open>short message\<close> consists of a single line: it is a sequence of
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   197
    arbitrary bytes excluding CR (13) and LF (10), and terminated by CR-LF or
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   198
    just LF.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   199
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   200
    \<^item> A \<^emph>\<open>long message\<close> starts with a single that consists only of decimal
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   201
    digits: these are interpreted as length of the subsequent block of
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   202
    arbitrary bytes. A final line-terminator (as above) may be included here,
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   203
    but is not required.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   204
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   205
  Messages in JSON format (see below) always fit on a single line, due to
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   206
  escaping of newline characters within string literals. This is convenient
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   207
  for interactive experimentation, but it can impact performance for very long
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   208
  messages. If the message byte-length is given on the preceding line, the
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   209
  server can read the message more efficiently as a single block.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   210
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   211
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   212
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   213
subsection \<open>Text messages\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   214
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   215
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   216
  Messages are read and written as byte streams (with byte lengths), but the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   217
  content is always interpreted as plain text in terms of the UTF-8
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   218
  encoding.\<^footnote>\<open>See also the ``UTF-8 Everywhere Manifesto''
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   219
  \<^url>\<open>http://utf8everywhere.org\<close>.\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   220
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   221
  Note that line-endings and other formatting characters are invariant wrt.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   222
  UTF-8 representation of text: thus implementations are free to determine the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   223
  overall message structure before or after applying the text encoding.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   224
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   225
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   226
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   227
subsection \<open>Input and output messages \label{sec:input-output-messages}\<close>
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   228
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   229
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   230
  Server input and output messages have a uniform format as follows:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   231
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   232
    \<^item> \<open>name argument\<close> such that:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   233
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   234
    \<^item> \<open>name\<close> is the longest prefix consisting of ASCII letters, digits,
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   235
    ``\<^verbatim>\<open>_\<close>'', ``\<^verbatim>\<open>.\<close>'',
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   236
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   237
    \<^item> the separator between \<open>name\<close> and \<open>argument\<close> is the longest possible
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   238
    sequence of ASCII blanks (it could be empty, e.g.\ when the argument
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   239
    starts with a quote or bracket),
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   240
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   241
    \<^item> \<open>argument\<close> is the rest of the message without line terminator.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   242
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   243
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   244
  Input messages are sent from the client to the server. Here the \<open>name\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   245
  specifies a \<^emph>\<open>server command\<close>: the list of known commands may be
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   246
  retrieved via the \<^verbatim>\<open>help\<close> command.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   247
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   248
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   249
  Output messages are sent from the server to the client. Here the \<open>name\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   250
  specifies the \<^emph>\<open>server reply\<close>, which always has a specific meaning as
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   251
  follows:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   252
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   253
    \<^item> synchronous results: \<^verbatim>\<open>OK\<close> or \<^verbatim>\<open>ERROR\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   254
    \<^item> asynchronous results: \<^verbatim>\<open>FINISHED\<close> or \<^verbatim>\<open>FAILED\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   255
    \<^item> intermediate notifications: \<^verbatim>\<open>NOTE\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   256
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   257
  \<^medskip>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   258
  The \<open>argument\<close> format is uniform for both input and output messages:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   259
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   260
    \<^item> empty argument (Scala type \<^verbatim>\<open>Unit\<close>)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   261
    \<^item> XML element in YXML notation (Scala type \<^verbatim>\<open>XML.Elem\<close>)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   262
    \<^item> JSON value (Scala type \<^verbatim>\<open>JSON.T\<close>)
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   263
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   264
  JSON values may consist of objects (records), arrays (lists), strings,
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   265
  numbers, bools, null.\<^footnote>\<open>See also the official specification
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   266
  \<^url>\<open>https://www.json.org\<close> and unofficial explorations ``Parsing JSON is a
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   267
  Minefield'' \<^url>\<open>http://seriot.ch/parsing_json.php\<close>.\<close> Since JSON requires
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   268
  explicit quotes and backslash-escapes to represent arbitrary text, the YXML
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   269
  notation for XML trees (\secref{sec:yxml-vs-xml}) works better
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   270
  for large messages with a lot of PIDE markup.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   271
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   272
  Nonetheless, the most common commands use JSON by default: big chunks of
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   273
  text (theory sources etc.) are taken from the underlying file-system and
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   274
  results are pre-formatted for plain-text output, without PIDE markup
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   275
  information. This is a concession to simplicity: the server imitates the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   276
  appearance of command-line tools on top of the Isabelle/PIDE infrastructure.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   277
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   278
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   279
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   280
subsection \<open>Initial password exchange\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   281
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   282
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   283
  Whenever a new client opens the server socket, the initial message needs to
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   284
  be its unique password. The server replies either with \<^verbatim>\<open>OK\<close> (and some
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   285
  information about the Isabelle version) or by silent disconnection of what
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   286
  is considered an illegal connection attempt. Note that @{tool client}
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   287
  already presents the correct password internally.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   288
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   289
  Server passwords are created as Universally Unique Identifier (UUID) in
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   290
  Isabelle/Scala and stored in a per-user database, with restricted
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   291
  file-system access only for the current user. The Isabelle/Scala server
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   292
  implementation is careful to expose the password only on private output
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   293
  channels, and not on a process command-line (which is accessible to other
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   294
  users, e.g.\ via the \<^verbatim>\<open>ps\<close> command).
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   295
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   296
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   297
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   298
subsection \<open>Synchronous commands\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   299
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   300
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   301
  A \<^emph>\<open>synchronous command\<close> corresponds to regular function application in
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   302
  Isabelle/Scala, with single argument and result (regular or error). Both the
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   303
  argument and the result may consist of type \<^verbatim>\<open>Unit\<close>, \<^verbatim>\<open>XML.Elem\<close>, \<^verbatim>\<open>JSON.T\<close>.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   304
  An error result typically consists of a JSON object with error message and
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   305
  potentially further result fields (this resembles exceptions in Scala).
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   306
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   307
  These are the protocol exchanges for both cases of command execution:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   308
  \begin{center}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   309
  \begin{tabular}{rl}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   310
  \<^bold>\<open>input:\<close> & \<open>command argument\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   311
  (a) regular \<^bold>\<open>output:\<close> & \<^verbatim>\<open>OK\<close> \<open>result\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   312
  (b) error \<^bold>\<open>output:\<close> & \<^verbatim>\<open>ERROR\<close> \<open>result\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   313
  \end{tabular}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   314
  \end{center}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   315
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   316
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   317
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   318
subsection \<open>Asynchronous commands\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   319
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   320
text \<open>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   321
  An \<^emph>\<open>asynchronous command\<close> corresponds to an ongoing process that finishes
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   322
  or fails eventually, while emitting arbitrary notifications in between.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   323
  Formally, it starts as synchronous command with immediate result \<^verbatim>\<open>OK\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   324
  giving the \<^verbatim>\<open>task\<close> identifier, or an immediate \<^verbatim>\<open>ERROR\<close> that indicates bad
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   325
  command syntax. For a running task, the termination is indicated later by
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   326
  \<^verbatim>\<open>FINISHED\<close> or \<^verbatim>\<open>FAILED\<close>, together with its ultimate result value.
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   327
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   328
  These are the protocol exchanges for various cases of command task
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   329
  execution:
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   330
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   331
  \begin{center}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   332
  \begin{tabular}{rl}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   333
  \<^bold>\<open>input:\<close> & \<open>command argument\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   334
  immediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>OK {"task":\<close>\<open>id\<close>\<^verbatim>\<open>}\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   335
  intermediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>NOTE {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   336
  (a) regular \<^bold>\<open>output:\<close> & \<^verbatim>\<open>FINISHED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   337
  (b) error \<^bold>\<open>output:\<close> & \<^verbatim>\<open>FAILED {"task":\<close>\<open>id\<close>\<^verbatim>\<open>,\<close>\<open>\<dots>\<close>\<^verbatim>\<open>}\<close> \\[3ex]
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   338
  \<^bold>\<open>input:\<close> & \<open>command argument\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   339
  immediate \<^bold>\<open>output:\<close> & \<^verbatim>\<open>ERROR\<close>~\<open>\<dots>\<close> \\
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   340
  \end{tabular}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   341
  \end{center}
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   342
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   343
  All asynchronous messages are decorated with the task identifier that was
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   344
  revealed in the immediate (synchronous) result. Thus the client can
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   345
  invoke further asynchronous commands and still dispatch the resulting stream of
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   346
  asynchronous messages properly.
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
   347
67920
c3c74310154e clarified signature;
wenzelm
parents: 67919
diff changeset
   348
  The synchronous command \<^verbatim>\<open>cancel {"task":\<close>~\<open>id\<close>\<^verbatim>\<open>}\<close> tells the specified task
c3c74310154e clarified signature;
wenzelm
parents: 67919
diff changeset
   349
  to terminate prematurely: usually causing a \<^verbatim>\<open>FAILED\<close> result, but this is
c3c74310154e clarified signature;
wenzelm
parents: 67919
diff changeset
   350
  not guaranteed: the cancel event may come too late or the running process
c3c74310154e clarified signature;
wenzelm
parents: 67919
diff changeset
   351
  may just ignore it.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   352
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   353
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   354
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   355
section \<open>Types for JSON values \label{sec:json-types}\<close>
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   356
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   357
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   358
  In order to specify concrete JSON types for command arguments and result
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   359
  messages, the following type definition language shall be used:
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   360
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   361
  \<^rail>\<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   362
    @{syntax type_def}: @'type' @{syntax name} '=' @{syntax type}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   363
    ;
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   364
    @{syntax type}: @{syntax name} | @{syntax value} | 'any' | 'null' |
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   365
      'bool' | 'int' | 'long' | 'double' | 'string' | '[' @{syntax type} ']' |
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   366
      '{' (@{syntax field_type} ',' *) '}' |
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   367
      @{syntax type} '\<oplus>' @{syntax type} |
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   368
      @{syntax type} '|' @{syntax type} |
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   369
      '(' @{syntax type} ')'
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   370
    ;
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   371
    @{syntax field_type}: @{syntax name} ('?'?) ':' @{syntax type}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   372
  \<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   373
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   374
  This is a simplified variation of TypeScript
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   375
  interfaces.\<^footnote>\<open>\<^url>\<open>https://www.typescriptlang.org/docs/handbook/interfaces.html\<close>\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   376
  The meaning of these types is specified wrt. the Isabelle/Scala
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   377
  implementation as follows.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   378
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   379
  \<^item> A \<open>name\<close> refers to a type defined elsewhere. The environment of type
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   380
  definitions is given informally: put into proper foundational order, it
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   381
  needs to specify a strongly normalizing system of syntactic abbreviations;
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   382
  type definitions may not be recursive.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   383
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   384
  \<^item> A \<open>value\<close> in JSON notation represents the singleton type of the given
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   385
  item. For example, the string \<^verbatim>\<open>"error"\<close> can be used as type for a slot that
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   386
  is guaranteed to contain that constant.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   387
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   388
  \<^item> Type \<open>any\<close> is the super type of all other types: it is an untyped slot in
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   389
  the specification and corresponds to \<^verbatim>\<open>Any\<close> or \<^verbatim>\<open>JSON.T\<close> in Isabelle/Scala.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   390
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   391
  \<^item> Type \<open>null\<close> is the type of the improper value \<open>null\<close>; it corresponds to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   392
  type \<^verbatim>\<open>Null\<close> in Scala and is normally not used in Isabelle/Scala.\<^footnote>\<open>See also
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   393
  ``Null References: The Billion Dollar Mistake'' by Tony Hoare
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   394
  \<^url>\<open>https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare\<close>.\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   395
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   396
  \<^item> Type \<open>bool\<close> is the type of the truth values \<^verbatim>\<open>true\<close> and \<^verbatim>\<open>false\<close>; it
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   397
  corresponds to \<^verbatim>\<open>Boolean\<close> in Scala.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   398
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   399
  \<^item> Types \<open>int\<close>, \<open>long\<close>, \<open>double\<close> are specific versions of the generic
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   400
  \<open>number\<close> type, corresponding to \<^verbatim>\<open>Int\<close>, \<^verbatim>\<open>Long\<close>, \<^verbatim>\<open>Double\<close> in Scala, but
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   401
  \<^verbatim>\<open>Long\<close> is limited to 53 bit precision.\<^footnote>\<open>Implementations of JSON typically
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   402
  standardize \<open>number\<close> to \<^verbatim>\<open>Double\<close>, which can absorb \<^verbatim>\<open>Int\<close> faithfully, but
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   403
  not all of \<^verbatim>\<open>Long\<close>.\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   404
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   405
  \<^item> Type \<open>string\<close> represents Unicode text; it corresponds to type \<^verbatim>\<open>String\<close> in
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   406
  Scala.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   407
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   408
  \<^item> Type \<open>[t]\<close> is the array (or list) type over \<open>t\<close>; it corresponds to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   409
  \<^verbatim>\<open>List[t]\<close> in Scala. The list type is co-variant as usual (i.e.\ monotonic
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   410
  wrt. the subtype relation).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   411
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   412
  \<^item> Object types describe the possible content of JSON records, with field
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   413
  names and types. A question mark after a field name means that it is
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   414
  optional. In Scala this could refer to an explicit type \<^verbatim>\<open>Option[t]\<close>, e.g.\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   415
  \<open>{a: int, b?: string}\<close> corresponding to a Scala case class with arguments
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   416
  \<^verbatim>\<open>a: Int\<close>, \<^verbatim>\<open>b: Option[String]\<close>.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   417
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   418
  Alternatively, optional fields can have a default value. If nothing else is
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   419
  specified, a standard ``empty value'' is used for each type, i.e.\ \<^verbatim>\<open>0\<close> for
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   420
  the number types, \<^verbatim>\<open>false\<close> for \<open>bool\<close>, or the empty string, array, object
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   421
  etc.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   422
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   423
  Object types are \<^emph>\<open>permissive\<close> in the sense that only the specified field
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   424
  names need to conform to the given types, but unspecified fields may be
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   425
  present as well.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   426
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   427
  \<^item> The type expression \<open>t\<^sub>1 \<oplus> t\<^sub>2\<close> only works for two object types with
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   428
  disjoint field names: it is the concatenation of the respective @{syntax
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   429
  field_type} specifications taken together. For example: \<open>{task: string} \<oplus>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   430
  {ok: bool}\<close> is the equivalent to \<open>{task: string, ok: bool}\<close>.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   431
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   432
  \<^item> The type expression \<open>t\<^sub>1 | t\<^sub>2\<close> is the disjoint union of two types, either
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   433
  one of the two cases may occur.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   434
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   435
  \<^item> Parentheses \<open>(t)\<close> merely group type expressions syntactically.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   436
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   437
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   438
  These types correspond to JSON values in an obvious manner, which is not
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   439
  further described here. For example, the JSON array \<^verbatim>\<open>[1, 2, 3]\<close> conforms to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   440
  types \<open>[int]\<close>, \<open>[long]\<close>, \<open>[double]\<close>, \<open>[any]\<close>, \<open>any\<close>.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   441
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   442
  Note that JSON objects require field names to be quoted, but the type
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   443
  language omits quotes for clarity. Thus the object \<^verbatim>\<open>{"a": 42, "b": "xyz"}\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   444
  conforms to the type \<open>{a: int, b: string}\<close>, for example.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   445
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   446
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   447
  The absence of an argument or result is represented by the Scala type
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   448
  \<^verbatim>\<open>Unit\<close>: it is written as empty text in the message \<open>argument\<close>
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   449
  (\secref{sec:input-output-messages}). This is not part of the JSON language.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   450
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   451
  Server replies have name tags like \<^verbatim>\<open>OK\<close>, \<^verbatim>\<open>ERROR\<close>: these are used literally
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   452
  together with type specifications to indicate the particular name with the
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   453
  type of its argument, e.g.\ \<^verbatim>\<open>OK\<close>~\<open>[string]\<close> for a regular result that is a
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   454
  list (JSON array) of strings.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   455
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   456
  \<^bigskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   457
  Here are some common type definitions, for use in particular specifications
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   458
  of command arguments and results.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   459
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   460
  \<^item> \<^bold>\<open>type\<close>~\<open>position = {line?: int, offset?: int, end_offset?: int, file?:
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   461
  string, id?: long}\<close> describes a source position within Isabelle text. Only
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   462
  the \<open>line\<close> and \<open>file\<close> fields make immediate sense to external programs.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   463
  Detailed \<open>offset\<close> and \<open>end_offset\<close> positions are counted according to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   464
  Isabelle symbols, see @{ML_type Symbol.symbol} in Isabelle/ML @{cite
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   465
  "isabelle-implementation"}. The position \<open>id\<close> belongs to the representation
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   466
  of command transactions in the Isabelle/PIDE protocol: it normally does not
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   467
  occur in externalized positions.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   468
67931
f7917c15b566 field "kind" is always present, with default "writeln";
wenzelm
parents: 67927
diff changeset
   469
  \<^item> \<^bold>\<open>type\<close>~\<open>message = {kind: string, message: string, pos?: position}\<close> where
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   470
  the \<open>kind\<close> provides some hint about the role and importance of the message.
67923
3e072441c96a clarified exported messages, e.g. suppress "information", "tracing";
wenzelm
parents: 67922
diff changeset
   471
  The main message kinds are \<^verbatim>\<open>writeln\<close> (for regular output), \<^verbatim>\<open>warning\<close>,
67931
f7917c15b566 field "kind" is always present, with default "writeln";
wenzelm
parents: 67927
diff changeset
   472
  \<^verbatim>\<open>error\<close>.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   473
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   474
  \<^item> \<^bold>\<open>type\<close>~\<open>error_message = {kind:\<close>~\<^verbatim>\<open>"error"\<close>\<open>, message: string}\<close> refers to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   475
  error messages in particular. These occur routinely with \<^verbatim>\<open>ERROR\<close> or
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   476
  \<^verbatim>\<open>FAILED\<close> replies, but also as initial command syntax errors (which are
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   477
  omitted in the command specifications below).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   478
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   479
  \<^item> \<^bold>\<open>type\<close>~\<open>theory_progress = {kind:\<close>~\<^verbatim>\<open>"writeln"\<close>\<open>, message: string, theory:
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   480
  string, session: string}\<close> reports formal progress in loading theories (e.g.\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   481
  when building a session image). Apart from a regular output message, it also
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   482
  reveals the formal theory name (e.g.\ \<^verbatim>\<open>"HOL.Nat"\<close>) and session name (e.g.\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   483
  \<^verbatim>\<open>"HOL"\<close>). Note that some rare theory names lack a proper session prefix,
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   484
  e.g. theory \<^verbatim>\<open>"Main"\<close> in session \<^verbatim>\<open>"HOL"\<close>.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   485
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   486
  \<^item> \<^bold>\<open>type\<close>~\<open>timing = {elapsed: double, cpu: double, gc: double}\<close> refers to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   487
  common Isabelle timing information in seconds, usually with a precision of
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   488
  three digits after the point (whole milliseconds).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   489
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   490
  \<^item> \<^bold>\<open>type\<close>~\<open>uuid = string\<close> refers to a Universally Unique Identifier (UUID)
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   491
  as plain text.\<^footnote>\<open>See \<^url>\<open>https://www.ietf.org/rfc/rfc4122.txt\<close> and
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   492
  \<^url>\<open>https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html\<close>.\<close> Such
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   493
  identifiers are created as private random numbers of the server and only
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   494
  revealed to the client that creates a certain resource (e.g.\ task or
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   495
  session). A client may disclose this information for use in a different
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   496
  client connection: this allows to share sessions between multiple
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   497
  connections.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   498
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   499
  Client commands need to provide syntactically wellformed UUIDs: this is
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   500
  trivial to achieve by using only identifiers that have been produced by the
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   501
  server beforehand.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   502
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   503
  \<^item> \<^bold>\<open>type\<close>~\<open>task = {task: uuid}\<close> identifies a newly created asynchronous task
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   504
  and thus allows the client to control it by the \<^verbatim>\<open>cancel\<close> command. The same
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   505
  task identification is included in all messages produced by this task.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   506
67921
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   507
  \<^item> \<^bold>\<open>type\<close> \<open>session_id = {session_id: uuid}\<close> identifies a newly created PIDE
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   508
  session managed by the server. Sessions are independent of client
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   509
  connections and may be shared by different clients, as long as the internal
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   510
  session identifier is known.
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   511
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   512
  \<^item> \<^bold>\<open>type\<close> \<open>node = {node_name: string, theory_name: string}\<close> represents the
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   513
  internal node name of a theory. The \<open>node_name\<close> is derived from the
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   514
  canonical theory file-name (e.g.\ \<^verbatim>\<open>"~~/src/HOL/ex/Seq.thy"\<close> after
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   515
  normalization within the file-system). The \<open>theory_name\<close> is the
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   516
  session-qualified theory name (e.g.\ \<^verbatim>\<open>HOL-ex.Seq\<close>).
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   517
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   518
  \<^item> \<^bold>\<open>type\<close> \<open>node_status = {ok: bool, total: int, unprocessed: int, running:
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   519
  int, warned: int, failed: int, finished: int, consolidated: bool}\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   520
  represents a formal theory node status of the PIDE document model. Fields
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   521
  \<open>total\<close>, \<open>unprocessed\<close>, \<open>running\<close>, \<open>warned\<close>, \<open>failed\<close>, \<open>finished\<close> account
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   522
  for individual commands within a theory node; \<open>ok\<close> is an abstraction for
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   523
  \<open>failed = 0\<close>. The \<open>consolidated\<close> flag indicates whether the outermost theory
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   524
  command structure has finished (or failed) and the final \<^theory_text>\<open>end\<close> command has
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   525
  been checked.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   526
\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   527
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   528
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   529
section \<open>Server commands and results\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   530
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   531
text \<open>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   532
  Here follows an overview of particular Isabelle server commands with their
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   533
  results, which are usually represented as JSON values with types according
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   534
  to \secref{sec:json-types}. The general format of input and output messages
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   535
  is described in \secref{sec:input-output-messages}. The relevant
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   536
  Isabelle/Scala source files are:
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   537
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   538
  \<^medskip>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   539
  \begin{tabular}{l}
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   540
  \<^file>\<open>$ISABELLE_HOME/src/Pure/Tools/server_commands.scala\<close> \\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   541
  \<^file>\<open>$ISABELLE_HOME/src/Pure/Tools/server.scala\<close> \\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   542
  \<^file>\<open>$ISABELLE_HOME/src/Pure/General/json.scala\<close> \\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   543
  \end{tabular}
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   544
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   545
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   546
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   547
subsection \<open>Command \<^verbatim>\<open>help\<close>\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   548
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   549
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   550
  \begin{tabular}{ll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   551
  regular result: & \<^verbatim>\<open>OK\<close> \<open>[string]\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   552
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   553
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   554
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   555
  The \<^verbatim>\<open>help\<close> command has no argument and returns the list of server command
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   556
  names. This is occasionally useful for interactive experimentation (see also
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   557
  @{tool client} in \secref{sec:tool-client}).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   558
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   559
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   560
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   561
subsection \<open>Command \<^verbatim>\<open>echo\<close>\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   562
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   563
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   564
  \begin{tabular}{ll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   565
  argument: & \<open>any\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   566
  regular result: & \<^verbatim>\<open>OK\<close> \<open>any\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   567
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   568
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   569
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   570
  The \<^verbatim>\<open>echo\<close> command is the identity function: it returns its argument as
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   571
  regular result. This is occasionally useful for testing and interactive
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   572
  experimentation (see also @{tool client} in \secref{sec:tool-client}).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   573
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   574
  The Scala type of \<^verbatim>\<open>echo\<close> is actually more general than given above:
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   575
  \<^verbatim>\<open>Unit\<close>, \<^verbatim>\<open>XML.Elem\<close>, \<^verbatim>\<open>JSON.T\<close> work uniformly. Note that \<^verbatim>\<open>XML.Elem\<close> might
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   576
  be difficult to type on the console in its YXML syntax
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   577
  (\secref{sec:yxml-vs-xml}).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   578
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   579
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   580
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   581
subsection \<open>Command \<^verbatim>\<open>shutdown\<close>\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   582
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   583
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   584
  \begin{tabular}{ll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   585
  regular result: & \<^verbatim>\<open>OK\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   586
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   587
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   588
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   589
  The \<^verbatim>\<open>shutdown\<close> command has no argument and result value. It forces a
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   590
  shutdown of the connected server process, stopping all open sessions and
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   591
  closing the server socket. This may disrupt pending commands on other
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   592
  connections!
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   593
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   594
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   595
  The command-line invocation \<^verbatim>\<open>isabelle server -x\<close> opens a server connection
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   596
  and issues a \<^verbatim>\<open>shutdown\<close> command (see also \secref{sec:tool-server}).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   597
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   598
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   599
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   600
subsection \<open>Command \<^verbatim>\<open>cancel\<close>\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   601
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   602
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   603
  \begin{tabular}{ll}
67920
c3c74310154e clarified signature;
wenzelm
parents: 67919
diff changeset
   604
  argument: & \<open>task\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   605
  regular result: & \<^verbatim>\<open>OK\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   606
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   607
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   608
67921
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   609
  The command \<^verbatim>\<open>cancel {"task":\<close>~\<open>id\<close>\<^verbatim>\<open>}\<close> attempts to cancel the specified
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   610
  task.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   611
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   612
  Cancellation is merely a hint that the client prefers an ongoing process to
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   613
  be stopped. The command always succeeds formally, but it may get ignored by
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   614
  a task that is still running; it might also refer to a non-existing or
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   615
  no-longer existing task (without producing an error).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   616
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   617
  Successful cancellation typically leads to an asynchronous failure of type
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   618
  \<^verbatim>\<open>FAILED {\<close>\<open>task: uuid, message:\<close>~\<^verbatim>\<open>"Interrupt"}\<close>. A different message is
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   619
  also possible, depending how the task handles the event.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   620
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   621
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   622
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   623
subsection \<open>Command \<^verbatim>\<open>session_build\<close> \label{sec:command-session-build}\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   624
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   625
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   626
  \begin{tabular}{lll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   627
  argument: & \<open>session_build_args\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   628
  immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   629
  notifications: & \<^verbatim>\<open>NOTE\<close> \<open>task \<oplus> (theory_progress | message)\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   630
  regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>task \<oplus> session_build_results\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   631
  error result: & \<^verbatim>\<open>FAILED\<close> \<open>task \<oplus> error_message \<oplus> session_build_results\<close> \\[2ex]
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   632
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   633
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   634
  \begin{tabular}{lll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   635
  \<^bold>\<open>type\<close> \<open>session_build_args =\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   636
  \quad\<open>{session: string,\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   637
  \quad~~\<open>preferences?: string,\<close> & \<^bold>\<open>default:\<close> server preferences \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   638
  \quad~~\<open>options?: [string],\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   639
  \quad~~\<open>dirs?: [string],\<close> \\
67922
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   640
  \quad~~\<open>include_sessions: [string],\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   641
  \quad~~\<open>system_mode?: bool,\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   642
  \quad~~\<open>verbose?: bool}\<close> \\[2ex]
67919
dd90faed43b2 clarified signature: do not expose somewhat accidental internal options;
wenzelm
parents: 67918
diff changeset
   643
  \end{tabular}
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   644
67919
dd90faed43b2 clarified signature: do not expose somewhat accidental internal options;
wenzelm
parents: 67918
diff changeset
   645
  \begin{tabular}{ll}
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   646
  \<^bold>\<open>type\<close> \<open>session_build_result =\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   647
  \quad\<open>{session: string,\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   648
  \quad~~\<open>ok: bool,\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   649
  \quad~~\<open>return_code: int,\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   650
  \quad~~\<open>timeout: bool,\<close> \\
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   651
  \quad~~\<open>timing: timing}\<close> \\[2ex]
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   652
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   653
  \<^bold>\<open>type\<close> \<open>session_build_results =\<close> \\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   654
  \quad\<open>{ok: bool,\<close> \\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   655
  \quad~~\<open>return_code: int,\<close> \\
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   656
  \quad~~\<open>sessions: [session_build_result]}\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   657
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   658
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   659
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   660
text \<open>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   661
  The \<^verbatim>\<open>session_build\<close> command prepares a session image for interactive use of
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   662
  theories. This is a limited version of command-line tool @{tool build}
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   663
  (\secref{sec:tool-build}), with specific options to request a formal context
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   664
  for an interactive PIDE session.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   665
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   666
  The build process is asynchronous, with notifications that inform about the
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   667
  progress of loaded theories. Some further informative messages are output as
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   668
  well.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   669
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   670
  Coordination of independent build processes is at the discretion of the
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   671
  client (or end-user), just as for @{tool build} and @{tool jedit}. There is
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   672
  no built-in coordination of conflicting builds with overlapping hierarchies
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   673
  of session images. In the worst case, a session image produced by one task
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   674
  may get overwritten by another task!
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   675
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   676
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   677
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   678
subsubsection \<open>Arguments\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   679
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   680
text \<open>
67919
dd90faed43b2 clarified signature: do not expose somewhat accidental internal options;
wenzelm
parents: 67918
diff changeset
   681
  The \<open>session\<close> field specifies the target session name. The build process
dd90faed43b2 clarified signature: do not expose somewhat accidental internal options;
wenzelm
parents: 67918
diff changeset
   682
  will produce all required ancestor images according to the overall session
dd90faed43b2 clarified signature: do not expose somewhat accidental internal options;
wenzelm
parents: 67918
diff changeset
   683
  graph.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   684
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   685
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   686
  The environment of Isabelle system options is determined from \<open>preferences\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   687
  that are augmented by \<open>options\<close>, which is a list individual updates of the
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   688
  form the \<open>name\<close>\<^verbatim>\<open>=\<close>\<open>value\<close> or \<open>name\<close> (the latter abbreviates
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   689
  \<open>name\<close>\<^verbatim>\<open>=true\<close>); see also command-line option \<^verbatim>\<open>-o\<close> for @{tool build}. The
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   690
  preferences are loaded from the file
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   691
  \<^path>\<open>$ISABELLE_HOME_USER/etc/preferences\<close> by default, but the client may
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   692
  provide alternative contents for it (as text, not a file-name). This could
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   693
  be relevant in situations where client and server run in different
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   694
  operating-system contexts.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   695
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   696
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   697
  The \<open>dirs\<close> field specifies additional directories for session ROOT and ROOTS
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   698
  files (\secref{sec:session-root}). This augments the name space of available
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   699
  sessions; see also option \<^verbatim>\<open>-d\<close> in @{tool build}.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   700
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   701
  \<^medskip>
67922
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   702
  The \<open>include_sessions\<close> field specifies sessions whose theories should be
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   703
  included in the overall name space of session-qualified theory names. This
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   704
  corresponds to a \<^bold>\<open>sessions\<close> specification in ROOT files
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   705
  (\secref{sec:session-root}). It enables the \<^verbatim>\<open>use_theories\<close> command
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   706
  (\secref{sec:command-use-theories}) to refer to sources from other sessions
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
   707
  in a robust manner, instead of relying on directory locations.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   708
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   709
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   710
  The \<open>system_mode\<close> field set to \<^verbatim>\<open>true\<close> stores resulting session images and
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   711
  log files in @{path "$ISABELLE_HOME/heaps"} instead of the default location
68219
c0341c0080e2 clarified store directories;
wenzelm
parents: 68152
diff changeset
   712
  @{path "$ISABELLE_HOME_USER/heaps"}. See also option \<^verbatim>\<open>-s\<close> in @{tool build}.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   713
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   714
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   715
  The \<open>verbose\<close> field set to \<^verbatim>\<open>true\<close> yields extra verbosity. The effect is
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   716
  similar to option \<^verbatim>\<open>-v\<close> in @{tool build}.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   717
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   718
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   719
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   720
subsubsection \<open>Intermediate output\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   721
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   722
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   723
  The asynchronous notifications of command \<^verbatim>\<open>session_build\<close> mainly serve as
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   724
  progress indicator: the output resembles that of the session build window of
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   725
  Isabelle/jEdit after startup @{cite "isabelle-jedit"}.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   726
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   727
  For the client it is usually sufficient to print the messages in plain text,
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   728
  but note that \<open>theory_progress\<close> also reveals formal \<open>theory\<close> and
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   729
  \<open>session\<close> names directly.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   730
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   731
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   732
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   733
subsubsection \<open>Results\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   734
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   735
text \<open>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   736
  The overall \<open>session_build_results\<close> contain both a summary and an entry
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   737
  \<open>session_build_result\<close> for each session in the build hierarchy. The result
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   738
  is always provided, independently of overall success (\<^verbatim>\<open>FINISHED\<close> task) or
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   739
  failure (\<^verbatim>\<open>FAILED\<close> task).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   740
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   741
  The \<open>ok\<close> field tells abstractly, whether all required session builds came
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   742
  out as \<open>ok\<close>, i.e.\ with zero \<open>return_code\<close>. A non-zero \<open>return_code\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   743
  indicates an error according to usual POSIX conventions for process exit.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   744
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   745
  The individual \<open>session_build_result\<close> entries provide extra fields:
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   746
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   747
  \<^item> \<open>timeout\<close> tells if the build process was aborted after running too long,
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   748
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   749
  \<^item> \<open>timing\<close> gives the overall process timing in the usual Isabelle format
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   750
  with elapsed, CPU, GC time.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   751
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   752
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   753
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   754
subsubsection \<open>Examples\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   755
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   756
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   757
  Build of a session image from the Isabelle distribution:
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   758
  @{verbatim [display] \<open>session_build {"session": "HOL-Word"}\<close>}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   759
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   760
  Build a session image from the Archive of Formal Proofs:
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   761
  @{verbatim [display] \<open>session_build {"session": "Coinductive", "dirs": ["$AFP_BASE/thys"]}\<close>}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   762
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   763
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   764
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   765
subsection \<open>Command \<^verbatim>\<open>session_start\<close> \label{sec:command-session-start}\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   766
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   767
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   768
  \begin{tabular}{lll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   769
  argument: & \<open>session_build_args \<oplus> {print_mode?: [string]}\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   770
  immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   771
  notifications: & \<^verbatim>\<open>NOTE\<close> \<open>task \<oplus> (theory_progress | message)\<close> \\
67925
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   772
  regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>task \<oplus> session_id \<oplus> {tmp_dir: string}\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   773
  error result: & \<^verbatim>\<open>FAILED\<close> \<open>task \<oplus> error_message\<close> \\[2ex]
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   774
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   775
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   776
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   777
  The \<^verbatim>\<open>session_start\<close> command starts a new Isabelle/PIDE session with
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   778
  underlying Isabelle/ML process, based on a session image that it produces on
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   779
  demand using \<^verbatim>\<open>session_build\<close>. Thus it accepts all \<open>session_build_args\<close> and
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   780
  produces similar notifications, but the detailed \<open>session_build_results\<close> are
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   781
  omitted.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   782
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   783
  The session build and startup process is asynchronous: when the task is
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   784
  finished, the session remains active for commands, until a \<^verbatim>\<open>session_stop\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   785
  or \<^verbatim>\<open>shutdown\<close> command is sent to the server.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   786
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   787
  Sessions are independent of client connections: it is possible to start a
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   788
  session and later apply \<^verbatim>\<open>use_theories\<close> on different connections, as long as
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   789
  the internal session identifier is known: shared theory imports will be used
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   790
  only once (and persist until purged explicitly).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   791
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   792
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   793
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   794
subsubsection \<open>Arguments\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   795
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   796
text \<open>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   797
  Most arguments are shared with \<^verbatim>\<open>session_build\<close>
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   798
  (\secref{sec:command-session-build}).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   799
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   800
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   801
  The \<open>print_mode\<close> field adds identifiers of print modes to be made active for
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   802
  this session. For example, \<^verbatim>\<open>"print_mode": ["ASCII"]\<close> prefers ASCII
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   803
  replacement syntax over mathematical Isabelle symbols. See also option \<^verbatim>\<open>-m\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   804
  in @{tool process} (\secref{sec:tool-process}).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   805
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   806
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   807
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   808
subsubsection \<open>Results\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   809
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   810
text \<open>
67921
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   811
  The \<open>session_id\<close> provides the internal identification of the session object
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   812
  within the sever process. It can remain active as long as the server is
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   813
  running, independently of the current client connection.
67925
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   814
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   815
  \<^medskip>
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   816
  The \<open>tmp_dir\<close> field refers to a temporary directory that is specifically
67925
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   817
  created for this session and deleted after it has been stopped. This may
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   818
  serve as auxiliary file-space for the \<^verbatim>\<open>use_theories\<close> command, but
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   819
  concurrent use requires some care in naming temporary files, e.g.\ by
74dce5658d4c provide tmp_dir for server session;
wenzelm
parents: 67923
diff changeset
   820
  using sub-directories with globally unique names.
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   821
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   822
  As \<open>tmp_dir\<close> is the default \<open>master_dir\<close> for commands \<^verbatim>\<open>use_theories\<close> and
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   823
  \<^verbatim>\<open>purge_theories\<close>, theory files copied there may be used without further
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   824
  path specification.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   825
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   826
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   827
68145
edacd2a050be proper heading;
wenzelm
parents: 68106
diff changeset
   828
subsubsection \<open>Examples\<close>
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   829
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   830
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   831
  Start a default Isabelle/HOL session:
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   832
  @{verbatim [display] \<open>session_start {"session": "HOL"}\<close>}
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   833
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   834
  Start a session from the Archive of Formal Proofs:
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   835
  @{verbatim [display] \<open>session_start {"session": "Coinductive", "dirs": ["$AFP_BASE/thys"]}\<close>}
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   836
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   837
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   838
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   839
subsection \<open>Command \<^verbatim>\<open>session_stop\<close>\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   840
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   841
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   842
  \begin{tabular}{ll}
67921
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   843
  argument: & \<open>session_id\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   844
  immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   845
  regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>task \<oplus> session_stop_result\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   846
  error result: & \<^verbatim>\<open>FAILED\<close> \<open>task \<oplus> error_message \<oplus> session_stop_result\<close> \\[2ex]
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   847
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   848
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   849
  \begin{tabular}{l}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   850
  \<^bold>\<open>type\<close> \<open>session_stop_result = {ok: bool, return_code: int}\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   851
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   852
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   853
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   854
  The \<^verbatim>\<open>session_stop\<close> command forces a shutdown of the identified PIDE
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   855
  session. This asynchronous tasks usually finishes quickly. Failure only
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   856
  happens in unusual situations, according to the return code of the
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   857
  underlying Isabelle/ML process.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   858
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   859
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   860
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   861
subsubsection \<open>Arguments\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   862
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   863
text \<open>
67921
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   864
  The \<open>session_id\<close> provides the UUID originally created by the server for this
1722384ffd4a clarified signature: more uniform session_id;
wenzelm
parents: 67920
diff changeset
   865
  session.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   866
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   867
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   868
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   869
subsubsection \<open>Results\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   870
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   871
text \<open>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   872
  The \<open>ok\<close> field tells abstractly, whether the Isabelle/ML process has
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   873
  terminated properly.
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   874
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   875
  The \<open>return_code\<close> field expresses this information according to usual POSIX
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   876
  conventions for process exit.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   877
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   878
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   879
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   880
subsection \<open>Command \<^verbatim>\<open>use_theories\<close> \label{sec:command-use-theories}\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   881
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   882
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   883
  \begin{tabular}{ll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   884
  argument: & \<open>use_theories_arguments\<close> \\
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   885
  immediate result: & \<^verbatim>\<open>OK\<close> \<open>task\<close> \\
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   886
  regular result: & \<^verbatim>\<open>FINISHED\<close> \<open>use_theories_results\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   887
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   888
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   889
  \begin{tabular}{ll}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   890
  \<^bold>\<open>type\<close> \<open>use_theories_arguments =\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   891
  \quad\<open>{session_id: uuid,\<close> \\
67940
b4e80f062fbf clarified signature -- eliminated somewhat pointless positions;
wenzelm
parents: 67938
diff changeset
   892
  \quad~~\<open>theories: [string],\<close> \\
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   893
  \quad~~\<open>master_dir?: string,\<close> & \<^bold>\<open>default:\<close> session \<open>tmp_dir\<close> \\
68152
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   894
  \quad~~\<open>pretty_margin?: double,\<close> & \<^bold>\<open>default:\<close> \<^verbatim>\<open>76\<close> \\
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   895
  \quad~~\<open>unicode_symbols?: bool,\<close> \\
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   896
  \quad~~\<open>export_pattern?: string}\<close> \\[2ex]
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   897
  \end{tabular}
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   898
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   899
  \begin{tabular}{ll}
68106
a514e29db980 return exports as result for Isabelle server;
wenzelm
parents: 67946
diff changeset
   900
  \<^bold>\<open>type\<close> \<open>export =\<close> \\
a514e29db980 return exports as result for Isabelle server;
wenzelm
parents: 67946
diff changeset
   901
  \quad~~\<open>{name: string, base64: bool, body: string}\<close> \\
a514e29db980 return exports as result for Isabelle server;
wenzelm
parents: 67946
diff changeset
   902
  \<^bold>\<open>type\<close> \<open>node_results =\<close> \\
a514e29db980 return exports as result for Isabelle server;
wenzelm
parents: 67946
diff changeset
   903
  \quad~~\<open>{status: node_status, messages: [message], exports: [export]}\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   904
  \<^bold>\<open>type\<close> \<open>use_theories_results =\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   905
  \quad\<open>{ok: bool,\<close> \\
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   906
  \quad~~\<open>errors: [message],\<close> \\
68106
a514e29db980 return exports as result for Isabelle server;
wenzelm
parents: 67946
diff changeset
   907
  \quad~~\<open>nodes: [node \<oplus> node_results]}\<close> \\
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   908
  \end{tabular}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   909
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   910
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   911
  The \<^verbatim>\<open>use_theories\<close> command updates the identified session by adding the
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   912
  current version of theory files to it, while dependencies are resolved
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   913
  implicitly. The command succeeds eventually, when all theories have been
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   914
  \<^emph>\<open>consolidated\<close> in the sense the formal \<open>node_status\<close>
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   915
  (\secref{sec:json-types}): the outermost command structure has finished (or
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   916
  failed) and the final \<^theory_text>\<open>end\<close> command of each theory has been checked.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   917
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   918
  Already used theories persist in the session until purged explicitly
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   919
  (\secref{sec:command-purge-theories}). This also means that repeated
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   920
  invocations of \<^verbatim>\<open>use_theories\<close> are idempotent: it could make sense to do
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   921
  that with different values for \<open>pretty_margin\<close> or \<open>unicode_symbols\<close> to get
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   922
  different formatting for \<open>errors\<close> or \<open>messages\<close>.
68106
a514e29db980 return exports as result for Isabelle server;
wenzelm
parents: 67946
diff changeset
   923
68152
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   924
  \<^medskip> A non-empty \<open>export_pattern\<close> means that theory \<open>exports\<close> are retrieved
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   925
  (see \secref{sec:tool-export}). An \<open>export\<close> \<open>name\<close> roughly follows
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   926
  file-system standards: ``\<^verbatim>\<open>/\<close>'' separated list of base names (excluding
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   927
  special names like ``\<^verbatim>\<open>.\<close>'' or ``\<^verbatim>\<open>..\<close>''). The \<open>base64\<close> field specifies the
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   928
  format of the \<open>body\<close> string: it is true for a byte vector that cannot be
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   929
  represented as plain text in UTF-8 encoding, which means the string needs to
619de043389f guard result exports via export_pattern -- avoid bombing client via huge blobs;
wenzelm
parents: 68145
diff changeset
   930
  be decoded as in \<^verbatim>\<open>java.util.Base64.getDecoder.decode(String)\<close>.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   931
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   932
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   933
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   934
subsubsection \<open>Arguments\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   935
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   936
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   937
  The \<open>session_id\<close> is the identifier provided by the server, when the session
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   938
  was created (possibly on a different client connection).
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   939
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   940
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   941
  The \<open>theories\<close> field specifies theory names as in theory \<^theory_text>\<open>imports\<close> or in
67940
b4e80f062fbf clarified signature -- eliminated somewhat pointless positions;
wenzelm
parents: 67938
diff changeset
   942
  ROOT \<^bold>\<open>theories\<close>.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   943
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   944
  \<^medskip>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   945
  The \<open>master_dir\<close> field specifies the master directory of imported theories:
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
   946
  it acts like the ``current working directory'' for locating theory files.
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   947
  This is irrelevant for \<open>theories\<close> with an absolute path name (e.g.\
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
   948
  \<^verbatim>\<open>"~~/src/HOL/ex/Seq.thy"\<close>) or session-qualified theory name (e.g.\
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   949
  \<^verbatim>\<open>"HOL-ex/Seq"\<close>).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   950
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   951
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   952
  The \<open>pretty_margin\<close> field specifies the line width for pretty-printing. The
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   953
  default is suitable for classic console output. Formatting happens at the
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   954
  end of \<^verbatim>\<open>use_theories\<close>, when all prover messages are exported to the client.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   955
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   956
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   957
  The \<open>unicode_symbols\<close> field set to \<^verbatim>\<open>true\<close> renders message output for direct
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   958
  output on a Unicode capable channel, ideally with the Isabelle fonts as in
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   959
  Isabelle/jEdit. The default is to keep the symbolic representation of
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   960
  Isabelle text, e.g.\ \<^verbatim>\<open>\<forall>\<close> instead of its rendering as \<open>\<forall>\<close>. This means the
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   961
  client needs to perform its own rendering before presenting it to the
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   962
  end-user.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   963
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   964
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   965
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   966
subsubsection \<open>Results\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   967
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   968
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   969
  The \<open>ok\<close> field indicates overall success of processing the specified
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   970
  theories with all their dependencies.
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   971
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   972
  When \<open>ok\<close> is \<^verbatim>\<open>false\<close>, the \<open>errors\<close> field lists all errors cumulatively
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   973
  (including imported theories). The messages contain position information for
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   974
  the original theory nodes.
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   975
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   976
  \<^medskip>
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   977
  The \<open>nodes\<close> field provides detailed information about each imported theory
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   978
  node. The individual fields are as follows:
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   979
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   980
  \<^item> \<open>node_name\<close>: the canonical name for the theory node, based on its
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   981
  file-system location;
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   982
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
   983
  \<^item> \<open>theory_name\<close>: the logical theory name;
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   984
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   985
  \<^item> \<open>status\<close>: the overall node status, e.g.\ see the visualization in the
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   986
  \<open>Theories\<close> panel of Isabelle/jEdit @{cite "isabelle-jedit"};
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   987
67918
7dc204623770 misc tuning and clarification;
wenzelm
parents: 67917
diff changeset
   988
  \<^item> \<open>messages\<close>: the main bulk of prover messages produced in this theory
67931
f7917c15b566 field "kind" is always present, with default "writeln";
wenzelm
parents: 67927
diff changeset
   989
  (with kind \<^verbatim>\<open>writeln\<close>, \<^verbatim>\<open>warning\<close>, \<^verbatim>\<open>error\<close>).
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   990
\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   991
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   992
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   993
subsubsection \<open>Examples\<close>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   994
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   995
text \<open>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   996
  Process some example theory from the Isabelle distribution, within the
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   997
  context of an already started session for Isabelle/HOL (see also
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
   998
  \secref{sec:command-session-start}):
67927
wenzelm
parents: 67925
diff changeset
   999
  @{verbatim [display] \<open>use_theories {"session_id": ..., "theories": ["~~/src/HOL/ex/Seq"]}\<close>}
67917
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1000
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1001
  \<^medskip>
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1002
  Process some example theories in the context of their (single) parent
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1003
  session:
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1004
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1005
  @{verbatim [display] \<open>session_start {"session": "HOL-Library"}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1006
use_theories {"session_id": ..., "theories": ["~~/src/HOL/Unix/Unix"]}
d13b2dd20f5e more documentation;
wenzelm
parents: 67904
diff changeset
  1007
session_stop {"session_id": ...}\<close>}
67922
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1008
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1009
  \<^medskip>
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1010
  Process some example theories that import other theories via
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1011
  session-qualified theory names:
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1012
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1013
  @{verbatim [display] \<open>session_start {"session": "HOL", "include_sessions": ["HOL-Unix"]}
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1014
use_theories {"session_id": ..., "theories": ["HOL-Unix.Unix"]}
9e668ae81f97 clarified signature: prefer selective include_sessions;
wenzelm
parents: 67921
diff changeset
  1015
session_stop {"session_id": ...}\<close>}
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
  1016
\<close>
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
  1017
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1018
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1019
subsection \<open>Command \<^verbatim>\<open>purge_theories\<close> \label{sec:command-purge-theories}\<close>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1020
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1021
text \<open>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1022
  \begin{tabular}{ll}
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1023
  argument: & \<open>purge_theories_arguments\<close> \\
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1024
  regular result: & \<^verbatim>\<open>OK\<close> \<open>purge_theories_result\<close> \\
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1025
  \end{tabular}
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1026
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
  1027
  \begin{tabular}{lll}
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1028
  \<^bold>\<open>type\<close> \<open>purge_theories_arguments =\<close> \\
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1029
  \quad\<open>{session_id: uuid,\<close> \\
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1030
  \quad~~\<open>theories: [string],\<close> \\
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
  1031
  \quad~~\<open>master_dir?: string,\<close> & \<^bold>\<open>default:\<close> session \<open>tmp_dir\<close> \\
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1032
  \quad~~\<open>all?: bool}\<close> \\[2ex]
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1033
  \end{tabular}
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1034
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1035
  \begin{tabular}{ll}
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1036
  \<^bold>\<open>type\<close> \<open>purge_theories_result = {purged: [string]}\<close> \\
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1037
  \end{tabular}
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1038
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1039
  \<^medskip>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1040
  The \<^verbatim>\<open>purge_theories\<close> command updates the identified session by removing
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1041
  theories that are no longer required: theories that are used in pending
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1042
  \<^verbatim>\<open>use_theories\<close> tasks or imported by other theories are retained.
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1043
\<close>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1044
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1045
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1046
subsubsection \<open>Arguments\<close>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1047
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1048
text \<open>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1049
  The \<open>session_id\<close> is the identifier provided by the server, when the session
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1050
  was created (possibly on a different client connection).
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1051
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1052
  \<^medskip>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1053
  The \<open>theories\<close> field specifies theory names to be purged: imported
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1054
  dependencies are \<^emph>\<open>not\<close> completed. Instead it is possible to provide the
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1055
  already completed import graph returned by \<^verbatim>\<open>use_theories\<close> as \<open>nodes\<close> /
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1056
  \<open>node_name\<close>.
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1057
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1058
  \<^medskip>
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1059
  The \<open>master_dir\<close> field specifies the master directory as in \<^verbatim>\<open>use_theories\<close>.
67946
e1e57c288e45 session tmp_dir is default master_dir;
wenzelm
parents: 67944
diff changeset
  1060
  This is irrelevant, when passing fully-qualified theory node names (e.g.\
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1061
  \<open>node_name\<close> from \<open>nodes\<close> in \<open>use_theories_results\<close>).
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1062
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1063
  \<^medskip>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1064
  The \<open>all\<close> field set to \<^verbatim>\<open>true\<close> attempts to purge all presently loaded
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1065
  theories.
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1066
\<close>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1067
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1068
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1069
subsubsection \<open>Results\<close>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1070
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1071
text \<open>
67943
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1072
  The \<open>purged\<close> field gives the theory nodes that were actually removed.
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1073
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1074
  \<^medskip>
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1075
  The \<open>retained\<close> field gives the remaining theory nodes, i.e.\ the complement
b45f0c0ea14f clarified theory node name;
wenzelm
parents: 67941
diff changeset
  1076
  of \<open>purged\<close>.
67941
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1077
\<close>
49a34b2fa788 added command "purge_theories";
wenzelm
parents: 67940
diff changeset
  1078
67904
465f43a9f780 documentation for the Isabelle server;
wenzelm
parents:
diff changeset
  1079
end