Dumb harness for working with wrapping

It's pretty manual but I want to see how bad it is.
This commit is contained in:
John Doty 2024-09-13 15:29:18 -07:00
parent 8845bcfdab
commit 46770419e6

31
wrap.py Normal file
View file

@ -0,0 +1,31 @@
import grammar
import parser.runtime as runtime
import parser.wadler as wadler
def main():
g = grammar.FineGrammar()
parser = runtime.Parser(g.build_table())
lexer = g.compile_lexer()
with open("test.fine", "r", encoding="utf-8") as f:
text = f.read()
tree, errors = parser.parse(runtime.GenericTokenStream(text, lexer))
if tree is None or len(errors) > 0:
print(f"{len(errors)} ERRORS")
for error in errors:
print(f"{error}")
return
WIDTH = 40
printer = wadler.Printer(g)
result = printer.format_tree(tree, WIDTH).apply_to_source(text)
for line in result.splitlines():
print(f"{line:<{WIDTH}}|")
if __name__ == "__main__":
main()