feat: Typing of an expression
This commit is contained in:
parent
7c3b64562b
commit
553d4fb0e0
|
@ -3,7 +3,7 @@ Class which manages a Pantograph instance. All calls to the kernel uses this
|
||||||
interface.
|
interface.
|
||||||
"""
|
"""
|
||||||
import json, pexpect, pathlib, unittest
|
import json, pexpect, pathlib, unittest
|
||||||
from pantograph.expr import Variable, Goal, GoalState, \
|
from pantograph.expr import parse_expr, Expr, Variable, Goal, GoalState, \
|
||||||
Tactic, TacticHave, TacticCalc
|
Tactic, TacticHave, TacticCalc
|
||||||
|
|
||||||
def _get_proc_cwd():
|
def _get_proc_cwd():
|
||||||
|
@ -75,6 +75,16 @@ class Server:
|
||||||
def reset(self):
|
def reset(self):
|
||||||
return self.run("reset", {})
|
return self.run("reset", {})
|
||||||
|
|
||||||
|
def expr_type(self, expr: str) -> Expr:
|
||||||
|
"""
|
||||||
|
Evaluate the type of a given expression. This gives an error if the
|
||||||
|
input `expr` is ill-formed.
|
||||||
|
"""
|
||||||
|
result = self.run('expr.echo', {"expr": expr})
|
||||||
|
if "error" in result:
|
||||||
|
raise ServerError(result["desc"])
|
||||||
|
return parse_expr(result["type"])
|
||||||
|
|
||||||
def goal_start(self, expr: str) -> GoalState:
|
def goal_start(self, expr: str) -> GoalState:
|
||||||
result = self.run('goal.start', {"expr": str(expr)})
|
result = self.run('goal.start', {"expr": str(expr)})
|
||||||
if "error" in result:
|
if "error" in result:
|
||||||
|
@ -134,6 +144,11 @@ class TestServer(unittest.TestCase):
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
self.assertEqual(get_version(), "0.2.14")
|
self.assertEqual(get_version(), "0.2.14")
|
||||||
|
|
||||||
|
def test_expr_type(self):
|
||||||
|
server = Server()
|
||||||
|
t = server.expr_type("forall (n m: Nat), n + m = m + n")
|
||||||
|
self.assertEqual(t, "Prop")
|
||||||
|
|
||||||
def test_goal_start(self):
|
def test_goal_start(self):
|
||||||
server = Server()
|
server = Server()
|
||||||
state0 = server.goal_start("forall (p q: Prop), Or p q -> Or q p")
|
state0 = server.goal_start("forall (p q: Prop), Or p q -> Or q p")
|
||||||
|
|
Loading…
Reference in New Issue