IsabelleClient (isabelle_elixir v0.3.0)

View Source

Default stateful Isabelle client.

Use %IsabelleClient{} for scripts and LiveBooks that benefit from a session stack in a struct. The active session is the top of client.sessions. It is not meant to be shared by multiple concurrent processes; use IsabelleClient.Shared for that. Use IsabelleClient.Raw for protocol-level socket control.

Summary

Types

t()

Stateful client with one socket and a local stack of Isabelle sessions.

Functions

Returns the active session from the top of the client's session stack.

Builds an Isabelle session image and waits for the async task result.

Closes the client's TCP socket.

Runs a synchronous Isabelle command, normalizing Elixir keyword arguments to JSON keys.

Connects to an Isabelle server and returns a stateful client struct.

Returns diagnostic messages from a task, result map, or task notes.

Round-trips a JSON value through Isabelle's echo command.

Returns error messages from a task or result map, with optional position filters.

Returns typed exports from all theory nodes in a use_theories result.

Extracts the session_id from a session struct, session-start task, or result map.

Removes a session from the local client stack without contacting Isabelle.

Returns the server command names supported by Isabelle.

Returns user-facing message strings from a task, result map, or task notes.

Finds a typed theory node by node_name or theory_name.

Returns typed theory nodes from a use_theories result.

Decodes a session_build result or task into a %IsabelleClient.Result.SessionBuildResult{}.

Returns the client's session stack, newest session first.

Asks the connected Isabelle server process to shut down.

Starts a local resident Isabelle server.

Starts an Isabelle session and pushes it onto client.sessions.

Returns typed top-level error messages from a use_theories result.

Checks theories and waits for the task result.

Decodes a use_theories result or task into a %IsabelleClient.Result.UseTheoriesResult{}.

Returns warning messages from a task or result map, with optional position filters.

Types

t()

@type t() :: %IsabelleClient{
  server_name: String.t() | nil,
  sessions: [IsabelleClient.Session.t()],
  socket: port()
}

Stateful client with one socket and a local stack of Isabelle sessions.

Functions

active_session(client)

Returns the active session from the top of the client's session stack.

build_session(isabelle_client, args, timeout \\ :infinity)

Builds an Isabelle session image and waits for the async task result.

args is forwarded to Isabelle's session_build command after key normalization. Typical keys are :session, :dirs, :options, :include_sessions, :preferences, and :verbose.

check_file(client, path, args \\ [], timeout \\ :infinity)

Checks an existing .thy file.

By default this uses the active client session. Pass "session_id" or :session_id in the arguments to use another server session explicitly. master_dir and theories are derived from path unless supplied.

check_text(client, theory, text, opts \\ [], timeout \\ :infinity)

Writes and checks a theory.

If text is not a complete theory, it is written as:

theory <name> imports Main begin
<text>
end

Use opts[:imports] to replace Main. The provided text starts on line 2 of the written file, so Isabelle diagnostics line up as text_line + 1. By default this uses the active client session. Isabelle offsets remain whole-file symbol offsets: with default Main, the snippet starts after 27 + String.length(theory) symbols from the generated header and newline. Pass "session_id" or :session_id in the options to use another server session explicitly.

close(isabelle_client)

Closes the client's TCP socket.

command(isabelle_client, name, arg \\ nil, timeout \\ 30000)

Runs a synchronous Isabelle command, normalizing Elixir keyword arguments to JSON keys.

connect(server_or_password, opts \\ [])

Connects to an Isabelle server and returns a stateful client struct.

Pass a %IsabelleClient.Server.Info{} returned by start_server/1, or pass the server password with explicit :host and :port options for an already running local or remote server.

diagnostics(result)

Returns diagnostic messages from a task, result map, or task notes.

diagnostics(result, opts)

See IsabelleClient.Result.diagnostics/2.

echo(client, value)

Round-trips a JSON value through Isabelle's echo command.

errors(result)

Returns error messages from a task or result map, with optional position filters.

errors(result, opts)

See IsabelleClient.Result.errors/2.

exports(result)

Returns typed exports from all theory nodes in a use_theories result.

extract_session(result)

Extracts the session_id from a session struct, session-start task, or result map.

forget_session(client, session_or_id)

Removes a session from the local client stack without contacting Isabelle.

Use this when a session was stopped elsewhere, or when Isabelle reports No session ... for an id still remembered by this client.

help(client)

Returns the server command names supported by Isabelle.

messages(result)

Returns user-facing message strings from a task, result map, or task notes.

messages(result, opts)

See IsabelleClient.Result.messages/2.

node(result, name)

Finds a typed theory node by node_name or theory_name.

nodes(result)

Returns typed theory nodes from a use_theories result.

purge_theories(client, args \\ nil, timeout \\ 30000)

Purges theories from a session.

By default this uses the active client session. Pass "session_id" or :session_id in the arguments to purge theories from another server session. This is a synchronous Isabelle command.

session_build_result(result)

Decodes a session_build result or task into a %IsabelleClient.Result.SessionBuildResult{}.

sessions(isabelle_client)

Returns the client's session stack, newest session first.

shutdown_server(client)

Asks the connected Isabelle server process to shut down.

start_server(opts \\ [])

Starts a local resident Isabelle server.

Options:

  • :server_name - resident server name, defaults to a unique name
  • :server_port - resident server port, defaults to 0

start_session(client, args, timeout \\ :infinity)

Starts an Isabelle session and pushes it onto client.sessions.

The argument list or map is forwarded to Isabelle's session_start command, which accepts session_build arguments (:session, :preferences, :options, :dirs, :include_sessions, :verbose) plus :print_mode.

Pass :label to store a local label in the resulting session struct. Labels are not sent to Isabelle. Returns {:ok, client, task}.

stop_session(client, session_or_timeout \\ :active, timeout \\ :infinity)

Stops a session.

With the default arguments, this stops the active session and pops it from the client's session stack. Pass a %IsabelleClient.Session{} or session id to stop another server session explicitly.

top_level_errors(result)

Returns typed top-level error messages from a use_theories result.

top_level_errors(result, opts)

See IsabelleClient.Result.top_level_errors/2.

use_theories(client, args \\ nil, timeout \\ :infinity)

Checks theories and waits for the task result.

By default this uses the active client session. Pass "session_id" or :session_id in the arguments to use another server session explicitly. Isabelle use_theories arguments are forwarded after key normalization: :session_id, :theories, :master_dir, :pretty_margin, :unicode_symbols, :export_pattern, :check_delay, :check_limit, :watchdog_timeout, and :nodes_status_delay.

Returns {:ok, task} for a finished Isabelle task, or {:error, task} when Isabelle reports task failure.

use_theories_result(result)

Decodes a use_theories result or task into a %IsabelleClient.Result.UseTheoriesResult{}.

warnings(result)

Returns warning messages from a task or result map, with optional position filters.

warnings(result, opts)

See IsabelleClient.Result.warnings/2.