Add a main! Now it works!

This commit is contained in:
Emi Simpson 2023-03-06 13:39:37 -05:00
parent 6f0d15ee3f
commit d39a78fae7
Signed by: Emi
GPG Key ID: A12F2C2FFDC3D847
1 changed files with 36 additions and 0 deletions

36
main.py Normal file
View File

@ -0,0 +1,36 @@
from emis_funky_funktions import *
from typing import Sequence
from grammar import lex_and_parse
from lex import Lexeme
from resolution import derives_false
def main(args: Sequence[str]) -> Tuple[str, int]:
match args[1:]:
case [file]:
with open(file) as input:
match lex_and_parse(input.read()):
case Ok(Ok(ir_kb)):
return (
'no'
if derives_false(ir_kb) else
'yes',
0
)
case Ok(Err(gen_ir_err)):
return (str(gen_ir_err), 102)
case Err((Lexeme(token, text, line, col_start, col_end), expected)):
return (
f'Parse error! Line {line}:{col_start}-{col_end}\n\nGot: {repr(text)}\nExpected: {expected}',
101
)
case _:
return (f'Usage: python {args[0]} some_file.cnf', 100)
raise Exception('Unreachable')
if __name__ == '__main__':
from sys import argv
out, code = main(argv)
print(out)
exit(code)