From 8352cc1ab07365d3872fcbaf2f427aab946b4d86 Mon Sep 17 00:00:00 2001 From: hl-valdemar Date: Wed, 7 Oct 2026 23:28:26 +0200 Subject: [PATCH] style: align multiline expressions and guards --- source/ast/ast.hon | 6 +++--- source/lexer/scan.hon | 15 ++++++++++----- source/parser/parse.hon | 35 +++++++++++++++++++++++++---------- source/sema/resolve.test.hon | 12 ++++-------- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/source/ast/ast.hon b/source/ast/ast.hon index 5153de9..1d84c7a 100644 --- a/source/ast/ast.hon +++ b/source/ast/ast.hon @@ -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), diff --git a/source/lexer/scan.hon b/source/lexer/scan.hon index a711dca..a43dfc7 100644 --- a/source/lexer/scan.hon +++ b/source/lexer/scan.hon @@ -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 diff --git a/source/parser/parse.hon b/source/parser/parse.hon index 3b79f52..390df87 100644 --- a/source/parser/parse.hon +++ b/source/parser/parse.hon @@ -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) } diff --git a/source/sema/resolve.test.hon b/source/sema/resolve.test.hon index 63ebc18..448ee72 100644 --- a/source/sema/resolve.test.hon +++ b/source/sema/resolve.test.hon @@ -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)