feat: Error messages in frontend.process
This commit is contained in:
parent
104d2451b1
commit
568b81235c
|
@ -180,12 +180,22 @@ class Server:
|
||||||
|
|
||||||
with open(file_name, 'rb') as f:
|
with open(file_name, 'rb') as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
units = [content[begin:end].decode('utf-8') for begin,end in result['units']]
|
units = [
|
||||||
|
content[unit["bounary"][0]:unit["boundary"][1]].decode('utf-8')
|
||||||
invocations = [TacticInvocation.parse(i) for i in result['invocations']]
|
for unit in result['units']
|
||||||
|
]
|
||||||
|
invocations = [
|
||||||
|
invocation
|
||||||
|
for unit in result['units']
|
||||||
|
for invocation in [TacticInvocation.parse(i) for i in unit['invocations']]
|
||||||
|
]
|
||||||
return units, invocations
|
return units, invocations
|
||||||
|
|
||||||
def load_sorry(self, command: str) -> list[GoalState]:
|
def load_sorry(self, command: str) -> list[GoalState | list[str]]:
|
||||||
|
"""
|
||||||
|
Executes the compiler on a Lean file. For each compilation unit, either
|
||||||
|
return the gathered `sorry`s, or a list of messages indicating error.
|
||||||
|
"""
|
||||||
result = self.run('frontend.process', {
|
result = self.run('frontend.process', {
|
||||||
'file': command,
|
'file': command,
|
||||||
'invocations': False,
|
'invocations': False,
|
||||||
|
@ -193,9 +203,17 @@ class Server:
|
||||||
})
|
})
|
||||||
if "error" in result:
|
if "error" in result:
|
||||||
raise ServerError(result["desc"])
|
raise ServerError(result["desc"])
|
||||||
|
|
||||||
|
def parse_unit(unit: dict):
|
||||||
|
state_id = unit.get("goalStateId")
|
||||||
|
if state_id is None:
|
||||||
|
# NOTE: `state_id` maybe 0.
|
||||||
|
# Maybe error has occurred
|
||||||
|
return unit["messages"]
|
||||||
|
state = GoalState.parse_inner(state_id, unit["goals"], self.to_remove_goal_states)
|
||||||
|
return state
|
||||||
states = [
|
states = [
|
||||||
GoalState.parse_inner(state_id, goals, self.to_remove_goal_states)
|
parse_unit(unit) for unit in result['units']
|
||||||
for (state_id, goals) in result['goalStates']
|
|
||||||
]
|
]
|
||||||
return states
|
return states
|
||||||
|
|
||||||
|
@ -346,6 +364,8 @@ class TestServer(unittest.TestCase):
|
||||||
def test_load_sorry(self):
|
def test_load_sorry(self):
|
||||||
server = Server()
|
server = Server()
|
||||||
state0, = server.load_sorry("example (p: Prop): p → p := sorry")
|
state0, = server.load_sorry("example (p: Prop): p → p := sorry")
|
||||||
|
if isinstance(state0, list):
|
||||||
|
print(state0)
|
||||||
self.assertEqual(state0.goals, [
|
self.assertEqual(state0.goals, [
|
||||||
Goal(
|
Goal(
|
||||||
[Variable(name="p", t="Prop")],
|
[Variable(name="p", t="Prop")],
|
||||||
|
|
2
src
2
src
|
@ -1 +1 @@
|
||||||
Subproject commit 10cb32e03f43e9306203d1c4a3852573ec55c4f2
|
Subproject commit d0321e72ddb477a5eea1ebee346c5ee00512d22e
|
Loading…
Reference in New Issue