fix: Versioning in the examples, tactic invocation

This commit is contained in:
Leni Aniva 2024-09-09 19:04:56 -07:00
parent d85cff5264
commit f2de062d11
Signed by: aniva
GPG Key ID: 4D9B1C8D10EA4C50
6 changed files with 30 additions and 21 deletions

View File

@ -1,11 +1,12 @@
{"version": 7,
{"version": "1.1.0",
"packagesDir": ".lake/packages",
"packages":
[{"url": "https://github.com/leanprover/std4",
[{"url": "https://github.com/leanprover-community/batteries",
"type": "git",
"subDir": null,
"rev": "3025cb124492b423070f20cf0a70636f757d117f",
"name": "std",
"scope": "",
"rev": "2ead90d24b4fac3a05c9c4294daa39bd8686fb98",
"name": "batteries",
"manifestFile": "lake-manifest.json",
"inputRev": "main",
"inherited": true,
@ -13,11 +14,12 @@
{"url": "https://github.com/leanprover-community/aesop.git",
"type": "git",
"subDir": null,
"rev": "0a21a48c286c4a4703c0be6ad2045f601f31b1d0",
"scope": "",
"rev": "a64fe24aa94e21404940e9217363a9a1ed9a33a6",
"name": "aesop",
"manifestFile": "lake-manifest.json",
"inputRev": "v4.8.0-rc1",
"inputRev": "v4.10.0-rc1",
"inherited": false,
"configFile": "lakefile.lean"}],
"configFile": "lakefile.toml"}],
"name": "Example",
"lakeDir": ".lake"}

View File

@ -2,7 +2,7 @@ import Lake
open Lake DSL
require aesop from git
"https://github.com/leanprover-community/aesop.git" @ "v4.8.0-rc1"
"https://github.com/leanprover-community/aesop.git" @ "v4.10.0-rc1"
package Example

View File

@ -1 +1 @@
leanprover/lean4:v4.8.0-rc1
leanprover/lean4:v4.10.0-rc1

View File

@ -19,5 +19,8 @@ poetry run examples/aesop.py
poetry run examples/data.py
```
Warning: If you make modifications to any Lean files, you must re-run `lake build`!
Warning: If you make modifications to any Lean files, you must re-run `lake
build`! Moreover, the version of the Lean used in the example folder (including
dependencies in `lakefile.lean` and `lean-toolchain`) **must match exactly**
with the version in `src/`!

View File

@ -14,7 +14,7 @@ if __name__ == '__main__':
print(f"$PWD: {project_path}")
print(f"$LEAN_PATH: {lean_path}")
server = Server(imports=['Example'], project_path=project_path, lean_path=lean_path)
units, invocations = server.compile_unit("Example")
units, invocations = server.tactic_invocations(project_path / "Example.lean")
for i, u in enumerate(units):
print(f"==== #{i} ====")
print(u)

View File

@ -2,13 +2,15 @@
Class which manages a Pantograph instance. All calls to the kernel uses this
interface.
"""
import json, pexpect, pathlib, unittest, os
import json, pexpect, unittest, os
from typing import Union
from pathlib import Path
from pantograph.expr import parse_expr, Expr, Variable, Goal, GoalState, \
Tactic, TacticHave, TacticCalc
from pantograph.compiler import TacticInvocation
def _get_proc_cwd():
return pathlib.Path(__file__).parent
return Path(__file__).parent
def _get_proc_path():
return _get_proc_cwd() / "pantograph-repl"
@ -64,7 +66,7 @@ class Server:
)
self.proc.setecho(False) # Do not send any command before this.
ready = self.proc.readline() # Reads the "ready."
assert ready == "ready.\r\n"
assert ready == "ready.\r\n", f"Server failed to emit ready signal: {ready}; Maybe the project needs to be rebuilt"
if self.options:
self.run("options.set", self.options)
@ -146,17 +148,19 @@ class Server:
raise ServerError(result["parseError"])
return GoalState.parse(result, self.to_remove_goal_states)
def compile_unit(self, module: str) -> tuple[list[str], list[TacticInvocation]]:
file_path = self.project_path / (module.replace('.', '/') + '.lean')
result = self.run('compile.unit', {
'module': module,
'compilationUnits': True,
'invocations': True
def tactic_invocations(self, file_name: Union[str, Path]) -> tuple[list[str], list[TacticInvocation]]:
"""
Collect tactic invocation points in file, and return them.
"""
result = self.run('frontend.process', {
'fileName': str(file_name),
'invocations': True,
"sorrys": False,
})
if "error" in result:
raise ServerError(result["desc"])
with open(file_path, 'rb') as f:
with open(file_name, 'rb') as f:
content = f.read()
units = [content[begin:end].decode('utf-8') for begin,end in result['units']]