Skip to content

fmt: hug final lists, break operator chains - #121

Merged
alii merged 1 commit into
masterfrom
fmt-hug
Sep 24, 2026
Merged

alii merged 1 commit into
masterfrom
fmt-hug

Conversation

@alii

@alii alii commented Sep 23, 2026

Copy link
Copy Markdown
Member

Two formatter fixes, both from reading the stdlib.

A final list hugs its call. When a call doesn't fit on one line but everything up to its last argument's [ does, the list breaks and its brackets stay against the parens:

Object([
	('resource', Str(resource_uri)),
	('scopes_supported', texts(scopes)),
])

This used to be Object(\n\t[\n …\n\t],\n). It works for tuples too.

  • It doesn't hug when an earlier argument is also a list, since f([…], [\n…\n]) reads lopsided.
  • It doesn't hug when the head doesn't fit either. Then it falls back to one argument per line, as before.

How it works: delimited_hug_list marks the list as a willing Hug. The width probe of the hugging call ends its line at the list's first break. A group around the call probes the list at its full width instead: fits now tracks whether an entry belongs to the probed group itself. So Ok(Object([…])) breaks Ok( the same way it does around a hugged lambda.

An operator chain breaks at every operator. a || b || c is one group per precedence level, and the parser's own PRECEDENCE table decides the levels. It stays on one line, or every operand gets its own line, indented under the first:

unreserved = { c >= 48 && c <= 57 } ||
	{ c >= 65 && c <= 90 } ||
	c == 45 ||
	c == 126

It used to keep the first few operands together and put the rest one per line, with no indent. The operator still ends its line, since a line starting with - would parse as a new statement.

What changes in the repo: I formatted all 103 committed .scrl files with master's formatter and with this one. 10 come out different, and all 10 differences are these two layouts. No file is reformatted in this PR. The stdlib tidy comes next, as its own PR.

All seven CI gates pass locally. hawk ran for the host target, and nothing here is gated on a cfg.

@alii
alii merged commit b9f3ba1 into master Sep 24, 2026
4 checks passed
@alii
alii deleted the fmt-hug branch September 24, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant