Dumb harness for working with wrapping
It's pretty manual but I want to see how bad it is.
This commit is contained in:
parent
8845bcfdab
commit
46770419e6
1 changed files with 31 additions and 0 deletions
31
wrap.py
Normal file
31
wrap.py
Normal 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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue