From aee36ca48bde505ddccb6f812ff5e6d395557662 Mon Sep 17 00:00:00 2001 From: gregorni Date: Wed, 23 Aug 2023 00:01:02 +0200 Subject: [PATCH] Revert "formatter.py: bundle adding to end string into function" This reverts commit d53e0276104bff8b5e6c74577c43a52cf7ca8989. --- blueprintcompiler/formatter.py | 55 ++++++++++++++-------------------- 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/blueprintcompiler/formatter.py b/blueprintcompiler/formatter.py index f1b96ca..94740af 100644 --- a/blueprintcompiler/formatter.py +++ b/blueprintcompiler/formatter.py @@ -75,7 +75,7 @@ class Format: and str(last_not_whitespace) not in NO_WHITESPACE_AFTER and item_as_string not in NO_WHITESPACE_BEFORE ): - current_line += " " + current_line = current_line + " " current_line += item_as_string @@ -84,52 +84,43 @@ class Format: or item.type == tokenizer.TokenType.COMMENT ): if item_as_string in OPENING_TOKENS: - # num_newlines = 1 if prev_line_type == LineType.CHILD_TYPE else 2 - # prev_line_type = LineType.BLOCK_OPEN - # tokenized_str = ( - # tokenized_str.strip() - # + (num_newlines * "\n") - # + (indent_levels * " ") + # tokenized_str += ( + # ("\n" * num_newlines) + (indent_levels * " ") + current_line # ) - # current_line += "\n" + (indent_levels * " ") - # tokenized_str += current_line # current_line = "" - commit_current_line( - 0 if prev_line_type == LineType.CHILD_TYPE else 1, - LineType.BLOCK_OPEN, - indent_levels + 1, + num_newlines = 1 if prev_line_type == LineType.CHILD_TYPE else 2 + prev_line_type = LineType.BLOCK_OPEN + tokenized_str = ( + tokenized_str.strip() + + (num_newlines * "\n") + + (indent_levels * " ") ) indent_levels += 1 elif item_as_string in CLOSING_TOKENS: - # tokenized_str = ( - # tokenized_str.strip() + "\n" + (indent_levels * " ") - # ) - # current_line += "\n" + (indent_levels * " ") + indent_levels -= 1 + tokenized_str = ( + tokenized_str.strip() + "\n" + (indent_levels * " ") + ) + # tokenized_str += current_line # current_line = "" - indent_levels -= 1 - commit_current_line( - 0, - # LineType.CHILD_TYPE - # if current_line.strip().startswith("[") - # else LineType.BLOCK_CLOSE, - LineType.BLOCK_CLOSE, - indent_levels - 1, - ) - # indent_levels -= 1 # prev_line_type = ( - # LineType.CHILD_TYPE - # if current_line.strip().startswith("[") - # else LineType.BLOCK_CLOSE + # LineType.CHILD_TYPE + # if current_line.strip().startswith("[") + # else LineType.BLOCK_CLOSE # ) - else: - commit_current_line(0, prev_line_type, indent_levels) + current_line += "\n" + (indent_levels * " ") + tokenized_str += current_line + current_line = "" last_not_whitespace = item + # else: + # current_line = current_line.strip() + " " + print(tokenized_str) # TODO: Remove this when the MR is ready to be merged return tokenized_str