check-templates: Rewrite pretty_print (again).

It now does everything based on the tokens, rather
than walking the lines and trying to match up tokens
to lines.
This commit is contained in:
Steve Howell
2021-12-02 16:10:42 +00:00
committed by Tim Abbott
parent 7e7b628054
commit fb574431cb
9 changed files with 135 additions and 197 deletions

View File

@@ -39,6 +39,14 @@ class Token:
self.start_token: Optional[Token] = None
self.end_token: Optional[Token] = None
# These get set during the pretty-print phase.
self.new_s = ""
self.indent: Optional[str] = None
self.orig_indent: Optional[str] = None
self.child_indent: Optional[str] = None
self.indent_is_final = False
self.parent_token: Optional[Token] = None
def tokenize(text: str) -> List[Token]:
in_code_block = False