mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
formatter: Tweak whitespace in special cases
This commit is contained in:
parent
d39257cabf
commit
80aaee374d
2 changed files with 9 additions and 5 deletions
|
@ -83,10 +83,12 @@ class Formatter:
|
||||||
whitespace_required = (
|
whitespace_required = (
|
||||||
str_item in WHITESPACE_BEFORE
|
str_item in WHITESPACE_BEFORE
|
||||||
or str(last_not_whitespace) in WHITESPACE_AFTER
|
or str(last_not_whitespace) in WHITESPACE_AFTER
|
||||||
|
or (str_item == "(" and end_str.endswith(": bind"))
|
||||||
)
|
)
|
||||||
whitespace_blockers = (
|
whitespace_blockers = (
|
||||||
str_item in NO_WHITESPACE_BEFORE
|
str_item in NO_WHITESPACE_BEFORE
|
||||||
or str(last_not_whitespace) in NO_WHITESPACE_AFTER
|
or (str(last_not_whitespace) in NO_WHITESPACE_AFTER)
|
||||||
|
or (str_item == "<" and str(last_not_whitespace) == "typeof")
|
||||||
)
|
)
|
||||||
|
|
||||||
this_or_last_is_ident = (
|
this_or_last_is_ident = (
|
||||||
|
@ -94,11 +96,12 @@ class Formatter:
|
||||||
or last_not_whitespace.type == TokenType.IDENT
|
or last_not_whitespace.type == TokenType.IDENT
|
||||||
)
|
)
|
||||||
current_line_is_empty = len(current_line) == 0
|
current_line_is_empty = len(current_line) == 0
|
||||||
just_one_word_on_line = re.match(r"^([A-Za-z_\-])+$", current_line)
|
is_function = str_item == "(" and not re.match(
|
||||||
is_short_object_def = str_item == "(" and not just_one_word_on_line
|
r"^([A-Za-z_\-])+(: bind)?$", current_line
|
||||||
|
)
|
||||||
|
|
||||||
any_blockers = (
|
any_blockers = (
|
||||||
whitespace_blockers or current_line_is_empty or is_short_object_def
|
whitespace_blockers or current_line_is_empty or is_function
|
||||||
)
|
)
|
||||||
|
|
||||||
if (whitespace_required or this_or_last_is_ident) and not any_blockers:
|
if (whitespace_required or this_or_last_is_ident) and not any_blockers:
|
||||||
|
|
|
@ -31,9 +31,10 @@ template $MyTemplate: Label {
|
||||||
* Multiline comment.
|
* Multiline comment.
|
||||||
*/
|
*/
|
||||||
// Single line comment.
|
// Single line comment.
|
||||||
value: bind 1.0 as <double>;
|
value: bind (1.0) as <double>;
|
||||||
as: 1;
|
as: 1;
|
||||||
signal => $on_signal() after;
|
signal => $on_signal() after;
|
||||||
|
type_value: typeof<$MyTemplate>;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog {
|
Dialog {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue