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 { invalid proc(tree @Tree, id NodeId) InvalidView {
node :: get_node(&tree.storage, id) node :: get_node(&tree.storage, id)
debug.assert( debug.assert(
node.kind == .invalid_expr or node.kind == .invalid_expr
node.kind == .invalid_stmt or or node.kind == .invalid_stmt
node.kind == .invalid_decl or node.kind == .invalid_decl
) )
return InvalidView{ return InvalidView{
span = get_span(&tree.storage, id), span = get_span(&tree.storage, id),
+10 -5
View File
@@ -246,11 +246,16 @@ ScanIdentResult :: struct {
@hide:file @hide:file
scan_ident proc(start usize, program []u8) ScanIdentResult { scan_ident proc(start usize, program []u8) ScanIdentResult {
cursor := start + 1 cursor := start + 1
while (cursor < program.len and ( while (
is_alpha(program[cursor]) or cursor < program.len
is_digit(program[cursor]) or and (
program[cursor] == '_' is_alpha(program[cursor])
)) cursor += 1 or is_digit(program[cursor])
or program[cursor] == '_'
)
) {
cursor += 1
}
# don't intern keywords (already O(1) lookup via token kind) # don't intern keywords (already O(1) lookup via token kind)
kind :: strmap.get(&keywords, program[start..cursor]) orelse .ident 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 @hide:file
parse_statement proc(state @mut State) ast.NodeId ! ParseError { parse_statement proc(state @mut State) ast.NodeId ! ParseError {
if (next_is(state, .ident) and ( if (
next_n_is(state, 1, .ident) or next_is(state, .ident)
next_n_is(state, 1, .double_colon) or and (
next_n_is(state, 1, .colon_equal) next_n_is(state, 1, .ident)
)) return try parse_statement_decl(state) 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 { match current(state).kind {
.ident, .int, .float, .string, .minus, .open_paren: { .ident, .int, .float, .string, .minus, .open_paren: {
expression :: try parse_expr(state) 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) arguments arraylist.ArrayList(ast.NodeId) := arraylist.init(state.allocator)
defer arraylist.deinit(&arguments) defer arraylist.deinit(&arguments)
while !next_is(state, .close_paren) and !next_is(state, .newline) and while (
!next_is(state, .close_curly) and !next_is(state, .eof) { !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) argument :: try parse_expr(state)
try arraylist.append(&arguments, argument) try arraylist.append(&arguments, argument)
if (!next_is(state, .comma)) break if (!next_is(state, .comma)) break
@@ -328,9 +337,15 @@ parse_primary proc(state @mut State) ast.NodeId ! ParseError {
else else
try diagnostics.add(state.diagnostics, .unexpected_token, token.span) try diagnostics.add(state.diagnostics, .unexpected_token, token.span)
if (token.kind != .newline and token.kind != .comma and if (
token.kind != .close_paren and token.kind != .close_curly and token.kind != .newline
token.kind != .eof) state.next_token += 1 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) 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( try testing.expect(
binding(&resolution, first_outer).data.diagnostic != binding(&resolution, first_outer).data.diagnostic != binding(&resolution, second_outer).data.diagnostic,
binding(&resolution, second_outer).data.diagnostic,
) )
try testing.expect( try testing.expect(
binding(&resolution, outer_param).data.diagnostic != binding(&resolution, outer_param).data.diagnostic != binding(&resolution, first_outer).data.diagnostic,
binding(&resolution, first_outer).data.diagnostic,
) )
try testing.expect( try testing.expect(
binding(&resolution, duplicate_p).data.diagnostic != binding(&resolution, duplicate_p).data.diagnostic != binding(&resolution, local_p).data.diagnostic,
binding(&resolution, local_p).data.diagnostic,
) )
outer_ref :: ast.statement_expr(&tree, ast.block_statement(&tree, view.body, 5)) outer_ref :: ast.statement_expr(&tree, ast.block_statement(&tree, view.body, 5))
try testing.expect_equal(BindingKind.invalid, binding(&resolution, outer_ref).kind) 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( try testing.expect(
binding(&resolution, bad.left).data.diagnostic != binding(&resolution, bad.left).data.diagnostic != binding(&resolution, bad.right).data.diagnostic,
binding(&resolution, bad.right).data.diagnostic,
) )
valid :: ast.block_statement(&tree, view.body, 2) valid :: ast.block_statement(&tree, view.body, 2)
later :: ast.block_statement(&tree, view.body, 3) later :: ast.block_statement(&tree, view.body, 3)