mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Formatter: Improve inserting whitespace
This commit is contained in:
parent
23d1f77b25
commit
f539aeb93d
1 changed files with 12 additions and 13 deletions
|
@ -45,7 +45,7 @@ class Format:
|
||||||
indent_levels = 0
|
indent_levels = 0
|
||||||
tokens = tokenizer.tokenize(data)
|
tokens = tokenizer.tokenize(data)
|
||||||
tokenized_str = ""
|
tokenized_str = ""
|
||||||
last_not_whitespace = None # To make line 56 not fail
|
last_not_whitespace = tokens[0] # To make line 56 not fail
|
||||||
current_line = ""
|
current_line = ""
|
||||||
prev_line_type = None
|
prev_line_type = None
|
||||||
|
|
||||||
|
@ -53,13 +53,18 @@ class Format:
|
||||||
if item.type != tokenizer.TokenType.WHITESPACE:
|
if item.type != tokenizer.TokenType.WHITESPACE:
|
||||||
item_as_string = str(item)
|
item_as_string = str(item)
|
||||||
|
|
||||||
if item_as_string in WHITESPACE_BEFORE:
|
if (
|
||||||
current_line = current_line.strip() + " "
|
item_as_string in WHITESPACE_BEFORE
|
||||||
elif (
|
and str(last_not_whitespace) not in NO_WHITESPACE_AFTER
|
||||||
item_as_string in NO_WHITESPACE_BEFORE
|
) or (
|
||||||
or str(last_not_whitespace) in NO_WHITESPACE_AFTER
|
(
|
||||||
|
str(last_not_whitespace) in WHITESPACE_AFTER
|
||||||
|
or last_not_whitespace.type == tokenizer.TokenType.IDENT
|
||||||
|
)
|
||||||
|
and str(last_not_whitespace) not in NO_WHITESPACE_AFTER
|
||||||
|
and item_as_string not in NO_WHITESPACE_BEFORE
|
||||||
):
|
):
|
||||||
current_line = current_line.strip()
|
current_line = current_line + " "
|
||||||
|
|
||||||
current_line += item_as_string
|
current_line += item_as_string
|
||||||
|
|
||||||
|
@ -100,12 +105,6 @@ class Format:
|
||||||
tokenized_str += current_line
|
tokenized_str += current_line
|
||||||
current_line = ""
|
current_line = ""
|
||||||
|
|
||||||
elif (
|
|
||||||
item_as_string in WHITESPACE_AFTER
|
|
||||||
or item.type == tokenizer.TokenType.IDENT
|
|
||||||
):
|
|
||||||
current_line += " "
|
|
||||||
|
|
||||||
last_not_whitespace = item
|
last_not_whitespace = item
|
||||||
|
|
||||||
# else:
|
# else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue