mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Formatter: Improve indent handling
This commit is contained in:
parent
fcba91def2
commit
1f999c3405
1 changed files with 4 additions and 6 deletions
|
@ -32,15 +32,13 @@ class Format:
|
||||||
tokenized_str = ""
|
tokenized_str = ""
|
||||||
for index, item in enumerate(tokens):
|
for index, item in enumerate(tokens):
|
||||||
if item.type != tokenizer.TokenType.WHITESPACE:
|
if item.type != tokenizer.TokenType.WHITESPACE:
|
||||||
tokenized_str += str(item)
|
|
||||||
if str(item) in opening_tokens:
|
if str(item) in opening_tokens:
|
||||||
indent_levels += 1
|
indent_levels += 1
|
||||||
|
elif str(item) in closing_tokens:
|
||||||
|
tokenized_str = tokenized_str[:-2]
|
||||||
|
indent_levels -= 1
|
||||||
|
|
||||||
try:
|
tokenized_str += str(item)
|
||||||
if str(tokens[index + 1]) in closing_tokens:
|
|
||||||
indent_levels -= 1
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if str(item) in newline_after + closing_tokens + opening_tokens:
|
if str(item) in newline_after + closing_tokens + opening_tokens:
|
||||||
tokenized_str += "\n"
|
tokenized_str += "\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue