mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2024-11-20 21:56:29 -05:00
Added line number in error messages
This commit is contained in:
parent
a6ca7ff7a3
commit
c9a4f6ce36
1 changed files with 21 additions and 10 deletions
|
@ -15,7 +15,18 @@ from logic import (
|
||||||
)
|
)
|
||||||
from vsp import has_vsp
|
from vsp import has_vsp
|
||||||
|
|
||||||
def parse_matrices(infile: TextIO) -> List[Tuple[Model, Dict]]:
|
class SourceFile:
|
||||||
|
def __init__(self, fileobj: TextIO):
|
||||||
|
self.fileobj = fileobj
|
||||||
|
self.current_line = 0
|
||||||
|
|
||||||
|
def __next__(self):
|
||||||
|
contents = next(self.fileobj)
|
||||||
|
self.current_line += 1
|
||||||
|
return contents
|
||||||
|
|
||||||
|
|
||||||
|
def parse_matrices(infile: SourceFile) -> List[Tuple[Model, Dict]]:
|
||||||
next(infile) # Skip header line
|
next(infile) # Skip header line
|
||||||
|
|
||||||
solutions: List[Tuple[Model, Dict]] = []
|
solutions: List[Tuple[Model, Dict]] = []
|
||||||
|
@ -86,17 +97,17 @@ def carrier_set_from_size(size: int):
|
||||||
mvalue_from_index(i) for i in range(size + 1)
|
mvalue_from_index(i) for i in range(size + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
def parse_size(infile: TextIO) -> Optional[int]:
|
def parse_size(infile: SourceFile) -> Optional[int]:
|
||||||
"""
|
"""
|
||||||
Parse the line representing the matrix size.
|
Parse the line representing the matrix size.
|
||||||
"""
|
"""
|
||||||
size = int(next(infile))
|
size = int(next(infile))
|
||||||
if size == -1:
|
if size == -1:
|
||||||
return None
|
return None
|
||||||
assert size > 0, "Unexpected size"
|
assert size > 0, f"Unexpected size at line {infile.current_line}"
|
||||||
return size
|
return size
|
||||||
|
|
||||||
def parse_negation(infile: TextIO, size: int) -> Optional[ModelFunction]:
|
def parse_negation(infile: SourceFile, size: int) -> Optional[ModelFunction]:
|
||||||
"""
|
"""
|
||||||
Parse the line representing the negation table.
|
Parse the line representing the negation table.
|
||||||
"""
|
"""
|
||||||
|
@ -105,7 +116,7 @@ def parse_negation(infile: TextIO, size: int) -> Optional[ModelFunction]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
row = line.split(" ")
|
row = line.split(" ")
|
||||||
assert len(row) == size + 1, "Negation table doesn't match size"
|
assert len(row) == size + 1, f"Negation table doesn't match size at line {infile.current_line}"
|
||||||
mapping = {}
|
mapping = {}
|
||||||
|
|
||||||
for i, j in zip(range(size + 1), row):
|
for i, j in zip(range(size + 1), row):
|
||||||
|
@ -187,7 +198,7 @@ def parse_order(infile: TextIO, size: int) -> Optional[Tuple[ModelFunction, Mode
|
||||||
|
|
||||||
table = line.split(" ")
|
table = line.split(" ")
|
||||||
|
|
||||||
assert len(table) == (size + 1)**2
|
assert len(table) == (size + 1)**2, f"Order table doesn't match expected size at line {infile.current_line}"
|
||||||
|
|
||||||
omapping = {}
|
omapping = {}
|
||||||
table_i = 0
|
table_i = 0
|
||||||
|
@ -237,7 +248,7 @@ def parse_designated(infile: TextIO, size: int) -> Optional[Set[ModelValue]]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
row = line.split(" ")
|
row = line.split(" ")
|
||||||
assert len(row) == size + 1, "Designated table doesn't match size"
|
assert len(row) == size + 1, f"Designated table doesn't match expected size at line {infile.current_line}"
|
||||||
|
|
||||||
designated_values = set()
|
designated_values = set()
|
||||||
|
|
||||||
|
@ -261,7 +272,7 @@ def parse_implication(infile: TextIO, size: int) -> Optional[List[ModelFunction]
|
||||||
# Split and remove the last '-1' character
|
# Split and remove the last '-1' character
|
||||||
table = line.split(" ")[:-1]
|
table = line.split(" ")[:-1]
|
||||||
|
|
||||||
assert len(table) % (size + 1)**2 == 0
|
assert len(table) % (size + 1)**2 == 0, f"Implication table does not match expected size at line {infile.current_line}"
|
||||||
|
|
||||||
table_i = 0
|
table_i = 0
|
||||||
mimplications: List[ModelFunction] = []
|
mimplications: List[ModelFunction] = []
|
||||||
|
@ -286,7 +297,7 @@ def parse_implication(infile: TextIO, size: int) -> Optional[List[ModelFunction]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
solutions: List[Model] = parse_matrices(sys.stdin)
|
solutions: List[Model] = parse_matrices(SourceFile(sys.stdin))
|
||||||
print(f"Parsed {len(solutions)} matrices")
|
print(f"Parsed {len(solutions)} matrices")
|
||||||
for i, (model, interpretation) in enumerate(solutions):
|
for i, (model, interpretation) in enumerate(solutions):
|
||||||
print(model)
|
print(model)
|
||||||
|
|
Loading…
Reference in a new issue