style: align multiline expressions and guards

This commit is contained in:
2026-10-07 23:28:26 +02:00
parent 313947acd8
commit 8352cc1ab0
4 changed files with 42 additions and 26 deletions
+3 -3
View File
@@ -530,9 +530,9 @@ node_span proc(tree @Tree, id NodeId) Span {
invalid proc(tree @Tree, id NodeId) InvalidView {
node :: get_node(&tree.storage, id)
debug.assert(
node.kind == .invalid_expr or
node.kind == .invalid_stmt or
node.kind == .invalid_decl
node.kind == .invalid_expr
or node.kind == .invalid_stmt
or node.kind == .invalid_decl
)
return InvalidView{
span = get_span(&tree.storage, id),
+10 -5
View File
@@ -246,11 +246,16 @@ ScanIdentResult :: struct {
@hide:file
scan_ident proc(start usize, program []u8) ScanIdentResult {
cursor := start + 1
while (cursor < program.len and (
is_alpha(program[cursor]) or
is_digit(program[cursor]) or
program[cursor] == '_'
)) cursor += 1
while (
cursor < program.len
and (
is_alpha(program[cursor])
or is_digit(program[cursor])
or program[cursor] == '_'
)
) {
cursor += 1
}
# don't intern keywords (already O(1) lookup via token kind)
kind :: strmap.get(&keywords, program[start..cursor]) orelse .ident
+25 -10
View File
@@ -168,11 +168,16 @@ parse_block proc(state @mut State) ast.NodeId ! ParseError {
@hide:file
parse_statement proc(state @mut State) ast.NodeId ! ParseError {
if (next_is(state, .ident) and (
next_n_is(state, 1, .ident) or
next_n_is(state, 1, .double_colon) or
next_n_is(state, 1, .colon_equal)
)) return try parse_statement_decl(state)
if (
next_is(state, .ident)
and (
next_n_is(state, 1, .ident)
or next_n_is(state, 1, .double_colon)
or next_n_is(state, 1, .colon_equal)
)
) {
return try parse_statement_decl(state)
}
match current(state).kind {
.ident, .int, .float, .string, .minus, .open_paren: {
expression :: try parse_expr(state)
@@ -266,8 +271,12 @@ parse_call proc(state @mut State, callee ast.NodeId) ast.NodeId ! ParseError {
arguments arraylist.ArrayList(ast.NodeId) := arraylist.init(state.allocator)
defer arraylist.deinit(&arguments)
while !next_is(state, .close_paren) and !next_is(state, .newline) and
!next_is(state, .close_curly) and !next_is(state, .eof) {
while (
!next_is(state, .close_paren)
and !next_is(state, .newline)
and !next_is(state, .close_curly)
and !next_is(state, .eof)
) {
argument :: try parse_expr(state)
try arraylist.append(&arguments, argument)
if (!next_is(state, .comma)) break
@@ -328,9 +337,15 @@ parse_primary proc(state @mut State) ast.NodeId ! ParseError {
else
try diagnostics.add(state.diagnostics, .unexpected_token, token.span)
if (token.kind != .newline and token.kind != .comma and
token.kind != .close_paren and token.kind != .close_curly and
token.kind != .eof) state.next_token += 1
if (
token.kind != .newline
and token.kind != .comma
and token.kind != .close_paren
and token.kind != .close_curly
and token.kind != .eof
) {
state.next_token += 1
}
return try ast.add_invalid_expr(&state.builder, token.span, diagnostic)
}
+4 -8
View File
@@ -178,16 +178,13 @@ rejects_shadowing_and_duplicates_without_cascades test {
}
}
try testing.expect(
binding(&resolution, first_outer).data.diagnostic !=
binding(&resolution, second_outer).data.diagnostic,
binding(&resolution, first_outer).data.diagnostic != binding(&resolution, second_outer).data.diagnostic,
)
try testing.expect(
binding(&resolution, outer_param).data.diagnostic !=
binding(&resolution, first_outer).data.diagnostic,
binding(&resolution, outer_param).data.diagnostic != binding(&resolution, first_outer).data.diagnostic,
)
try testing.expect(
binding(&resolution, duplicate_p).data.diagnostic !=
binding(&resolution, local_p).data.diagnostic,
binding(&resolution, duplicate_p).data.diagnostic != binding(&resolution, local_p).data.diagnostic,
)
outer_ref :: ast.statement_expr(&tree, ast.block_statement(&tree, view.body, 5))
try testing.expect_equal(BindingKind.invalid, binding(&resolution, outer_ref).kind)
@@ -292,8 +289,7 @@ preserves_syntax_diagnostics_and_resolves_shared_unknown_types_once test {
}
}
try testing.expect(
binding(&resolution, bad.left).data.diagnostic !=
binding(&resolution, bad.right).data.diagnostic,
binding(&resolution, bad.left).data.diagnostic != binding(&resolution, bad.right).data.diagnostic,
)
valid :: ast.block_statement(&tree, view.body, 2)
later :: ast.block_statement(&tree, view.body, 3)