From a4c18c37dc1abb1228251741edc37cfd9735f3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=AA=E3=82=AD=E8=90=8C?= Date: Wed, 3 Sep 2025 16:57:10 +0200 Subject: [PATCH] h1: make `|` operator work with anything other than syntactic calls (in which case it just calls the value) in case you call a function to get a function, parenthesise it 1 | getFunction () -- getFunction 1 () 1 | (getFunction ()) -- (getFunction ()) 1 --- crates/haku/src/compiler.rs | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/haku/src/compiler.rs b/crates/haku/src/compiler.rs index c60fb11..f3f8f3d 100644 --- a/crates/haku/src/compiler.rs +++ b/crates/haku/src/compiler.rs @@ -460,36 +460,36 @@ fn compile_pipe_call<'a>( left: NodeId, call: NodeId, ) -> CompileResult { - if src.ast.kind(call) != NodeKind::Call { - c.emit(Diagnostic::error( - src.ast.span(call), - "the right side of a pipe `|` must be a function call", - )); - return Ok(()); + match src.ast.kind(call) { + NodeKind::Call => { + let mut walk = src.ast.walk(call); + let Some(func) = walk.node() else { + return Ok(()); + }; + + compile_expr(c, src, left)?; + let mut argument_count = 1; + while let Some(arg) = walk.node() { + compile_expr(c, src, arg)?; + argument_count += 1; + } + + let argument_count = u8::try_from(argument_count).unwrap_or_else(|_| { + c.emit(Diagnostic::error( + src.ast.span(call), + "function call has too many arguments", + )); + 0 + }); + + emit_nary_call(c, src, func, argument_count)?; + } + _ => { + compile_expr(c, src, left)?; + emit_nary_call(c, src, call, 1)?; + } } - let mut walk = src.ast.walk(call); - let Some(func) = walk.node() else { - return Ok(()); - }; - - compile_expr(c, src, left)?; - let mut argument_count = 1; - while let Some(arg) = walk.node() { - compile_expr(c, src, arg)?; - argument_count += 1; - } - - let argument_count = u8::try_from(argument_count).unwrap_or_else(|_| { - c.emit(Diagnostic::error( - src.ast.span(call), - "function call has too many arguments", - )); - 0 - }); - - emit_nary_call(c, src, func, argument_count)?; - Ok(()) }