diff --git a/blueprintcompiler/formatter.py b/blueprintcompiler/formatter.py index 2514b28..68e4107 100644 --- a/blueprintcompiler/formatter.py +++ b/blueprintcompiler/formatter.py @@ -83,10 +83,12 @@ class Formatter: whitespace_required = ( str_item in WHITESPACE_BEFORE or str(last_not_whitespace) in WHITESPACE_AFTER + or (str_item == "(" and end_str.endswith(": bind")) ) whitespace_blockers = ( 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 = ( @@ -94,11 +96,12 @@ class Formatter: or last_not_whitespace.type == TokenType.IDENT ) current_line_is_empty = len(current_line) == 0 - just_one_word_on_line = re.match(r"^([A-Za-z_\-])+$", current_line) - is_short_object_def = str_item == "(" and not just_one_word_on_line + is_function = str_item == "(" and not re.match( + r"^([A-Za-z_\-])+(: bind)?$", current_line + ) 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: diff --git a/tests/formatting/correct1.blp b/tests/formatting/correct1.blp index 42d55fa..c1370d0 100644 --- a/tests/formatting/correct1.blp +++ b/tests/formatting/correct1.blp @@ -31,9 +31,10 @@ template $MyTemplate: Label { * Multiline comment. */ // Single line comment. - value: bind 1.0 as ; + value: bind (1.0) as ; as: 1; signal => $on_signal() after; + type_value: typeof<$MyTemplate>; } Dialog {