Physlib

Physlib.Meta.TransverseTactics

4 declarations

definition

`processCommands` returns pre-command environments and info states

#processCommands

Operating within the Lean frontend monad `Frontend.FrontendM`, this function processes the commands of a source file to produce a list of pairs (E,I)(E, I). Each pair consists of the `Environment` EE and the `InfoState` II representing the state of the system immediately before each command is processed.

definition

Accumulate IO actions for tactic info nodes

#visitInfo

The function `transverseTactics.visitInfo` processes a node `info` from a Lean information tree. Given a file path ff, a Lean environment E\mathcal{E}, a callback function vv (which operates on tactic information), context information cc, and an accumulator list of IO actions AA, the function checks if `info` corresponds to tactic information tt. If it does, the function prepends a new IO action to AA. This action, when executed, sets the environment to E\mathcal{E} and invokes v(f,c,t)v(f, c, t), while catching and reporting any metadata errors. If `info` is not a tactic node, the function returns the original list AA unchanged.

definition

Flattened IO actions from info trees in SS

#traverseForest

Given a file path ff, a callback function vv for processing tactic information, and a list of steps S=[(E1,I1),(E2,I2),]S = [(\mathcal{E}_1, \mathcal{I}_1), (\mathcal{E}_2, \mathcal{I}_2), \dots] where each E\mathcal{E} is an environment and each I\mathcal{I} is an information state, the function `traverseForest` iterates through each pair in SS. For every information tree within an information state I\mathcal{I}, it performs a fold operation using the function `visitInfo` with the corresponding environment E\mathcal{E} and callback vv. This process collects and flattens the resulting IO actions into a single list of type List(IO Unit)\text{List}(\text{IO Unit}).

definition

Apply a callback vv to every tactic in a Lean file ff

#transverseTactics

The function `transverseTactics` processes a Lean source file located at path ff and applies a user-provided callback function vv to every tactic execution node within that file. Specifically, it performs the following steps: 1. **Environment Setup:** It initializes the Lean search path, reads the content of ff, and processes the file header to establish the required environment E\mathcal{E} and module dependencies. 2. **Command Processing:** It elaborates the entire file within the `FrontendM` monad to generate a sequence of pairs (Ei,Ii)(\mathcal{E}_i, \mathcal{I}_i), where each Ei\mathcal{E}_i is the environment and Ii\mathcal{I}_i is the information state (containing information trees) after each command. 3. **Tactic Traversal:** It utilizes `traverseForest` to iterate through the information trees. For every tactic information node tt with associated context cc found in these trees, it executes the callback v(f,c,t)v(f, c, t) within the `MetaM` monad. The function ensures that all IO actions resulting from the tactics are executed and handles any errors that arise during the import or traversal phases.