Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Proof State #18

Merged
merged 35 commits into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
803a57f
Implement negative signs in exec
Nfsaavedra Oct 5, 2023
eb8fba1
Implement delete step
Nfsaavedra Oct 5, 2023
8c51a60
Implement add step
Nfsaavedra Oct 5, 2023
49bef16
Raise exception when adding or deleting steps outside of proof
Nfsaavedra Oct 5, 2023
6b0346c
Add comments
Nfsaavedra Oct 6, 2023
6b9b3e6
Change ProofState to ProofFile
Nfsaavedra Oct 6, 2023
344cdd9
Change ProofFile to use prev_step of CoqFile
Nfsaavedra Oct 7, 2023
b8e8f05
Delete step in ProofFile
Nfsaavedra Oct 7, 2023
d211c18
Fix add_step and delete_step
Nfsaavedra Oct 7, 2023
28b3e18
Fix add_step and delete_step
Nfsaavedra Oct 7, 2023
36afe9d
Fix delete_step from proof file
Nfsaavedra Oct 7, 2023
f8a92b9
Fix add_step for ProofFile
Nfsaavedra Oct 8, 2023
27d61d0
Improve performance of add_step and delete_step
Nfsaavedra Oct 8, 2023
50b7e20
Handle adding invalid steps
Nfsaavedra Oct 11, 2023
1faff79
Fix getting context in add step
Nfsaavedra Oct 11, 2023
220d34a
Improve performance ProofFile
Nfsaavedra Oct 13, 2023
62b6991
Fix delete_step and add_step for first and last step
Nfsaavedra Oct 13, 2023
7294173
Handle exceptions when creating proof file
Nfsaavedra Oct 13, 2023
fd1c0c1
Fix changing empty proof
Nfsaavedra Oct 13, 2023
b6aa575
black
Nfsaavedra Oct 16, 2023
9f17b36
Fix Range __lt__
Nfsaavedra Oct 25, 2023
c6f856b
Simplify property goals
Nfsaavedra Oct 25, 2023
e5d5235
Small fix
Nfsaavedra Oct 25, 2023
d5e7538
Small fixes
Nfsaavedra Oct 25, 2023
96cb426
Refactor add_step and delete_step to implement change_steps
Nfsaavedra Oct 25, 2023
3d5c227
change_steps in CoqFile
Nfsaavedra Oct 25, 2023
906e5b8
refactor add_step and delete_step
Nfsaavedra Oct 25, 2023
545a131
change_steps in ProofFile
Nfsaavedra Oct 25, 2023
abfff2a
Add Qed and Proof back
Nfsaavedra Oct 26, 2023
f0dbcd8
change_steps WIP
Nfsaavedra Oct 26, 2023
1995442
change_steps fixed
Nfsaavedra Oct 27, 2023
1c543eb
Refactor where notation. Add short_text to Steps. Fix __find_prev
Nfsaavedra Oct 27, 2023
3145a21
black
Nfsaavedra Oct 27, 2023
793ad5c
Improve code
Nfsaavedra Oct 28, 2023
e7ba9d7
black
Nfsaavedra Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ python -m pip install -e .
```python
import os
from coqlspclient.coq_file import CoqFile
from coqlspclient.proof_state import ProofState
from coqlspclient.proof_file import ProofFile
from coqlspclient.coq_structs import TermType

# Open Coq file
Expand Down Expand Up @@ -55,33 +55,32 @@ with CoqFile(os.path.join(os.getcwd(), "examples/example.v")) as coq_file:
# Get all terms defined until now
print("Number of terms:", len(coq_file.context.terms))

with CoqFile(os.path.join(os.getcwd(), "examples/example.v")) as coq_file:
with ProofState(coq_file) as proof_state:
# Number of proofs in the file
print("Number of proofs:", len(proof_state.proofs))
print("Proof:", proof_state.proofs[0].text)

# Print steps of proof
for step in proof_state.proofs[0].steps:
print(step.text, end="")
print()

# Get the context used in the third step
print(proof_state.proofs[0].steps[2].context)
# Print the goals in the third step
print(proof_state.proofs[0].steps[2].goals)

# Print number of terms in context
print("Number of terms:", len(proof_state.context.terms))
# Filter for Notations only
print("Number of notations:",
len(
list(filter(
lambda term: term.type == TermType.NOTATION,
proof_state.context.terms.values(),
))
)
with ProofFile(os.path.join(os.getcwd(), "examples/example.v")) as proof_file:
# Number of proofs in the file
print("Number of proofs:", len(proof_file.proofs))
print("Proof:", proof_file.proofs[0].text)

# Print steps of proof
for step in proof_file.proofs[0].steps:
print(step.text, end="")
print()

# Get the context used in the third step
print(proof_file.proofs[0].steps[2].context)
# Print the goals in the third step
print(proof_file.proofs[0].steps[2].goals)

# Print number of terms in context
print("Number of terms:", len(proof_file.context.terms))
# Filter for Notations only
print("Number of notations:",
len(
list(filter(
lambda term: term.type == TermType.NOTATION,
proof_file.context.terms.values(),
))
)
)
```

### Run tests
Expand Down
16 changes: 16 additions & 0 deletions coqlspclient/coq_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from dataclasses import dataclass


class CoqChange:
pass


@dataclass
class CoqAddStep(CoqChange):
step_text: str
previous_step_index: int


@dataclass
class CoqDeleteStep(CoqChange):
step_index: int
26 changes: 26 additions & 0 deletions coqlspclient/coq_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class InvalidChangeException(Exception):
pass


class InvalidStepException(InvalidChangeException):
def __init__(self, step: str):
self.step: str = step

def __str__(self):
return "The step {} is not valid.".format(self.step)


class InvalidDeleteException(InvalidChangeException):
def __init__(self, step_to_delete: str):
self.step_to_delete: str = step_to_delete

def __str__(self):
return "Deleting the step {} is not valid.".format(self.delete)


class InvalidFileException(Exception):
def __init__(self, file: str):
self.file: str = file

def __str__(self):
return "The file {} is not valid.".format(self.file)
Loading