diff --git a/compiler/erg_compiler/hir.rs b/compiler/erg_compiler/hir.rs index 16575ffd..67450e76 100644 --- a/compiler/erg_compiler/hir.rs +++ b/compiler/erg_compiler/hir.rs @@ -1081,8 +1081,13 @@ pub struct Call { impl NestedDisplay for Call { fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, level: usize) -> std::fmt::Result { - writeln!(f, "({}){}:", self.obj, fmt_option!(self.attr_name),)?; - self.args.fmt_nest(f, level + 1) + writeln!(f, "({}){}", self.obj, fmt_option!(self.attr_name),)?; + if self.args.is_empty() { + write!(f, "()") + } else { + writeln!(f, ":")?; + self.args.fmt_nest(f, level + 1) + } } } diff --git a/compiler/erg_parser/ast.rs b/compiler/erg_parser/ast.rs index e8b43328..39ffb638 100644 --- a/compiler/erg_parser/ast.rs +++ b/compiler/erg_parser/ast.rs @@ -1017,8 +1017,12 @@ impl NestedDisplay for Call { if let Some(attr_name) = self.attr_name.as_ref() { write!(f, "{}", attr_name)?; } - writeln!(f, ":")?; - self.args.fmt_nest(f, level + 1) + if self.args.is_empty() { + write!(f, "()") + } else { + writeln!(f, ":")?; + self.args.fmt_nest(f, level + 1) + } } } diff --git a/compiler/erg_parser/parse.rs b/compiler/erg_parser/parse.rs index a4c698bb..7cad07c1 100644 --- a/compiler/erg_parser/parse.rs +++ b/compiler/erg_parser/parse.rs @@ -2170,14 +2170,17 @@ impl Parser { /// x |> f() => f(x) fn try_reduce_stream_operator(&mut self, stack: &mut Vec) -> ParseResult<()> { debug_call_info!(self); - self.skip(); // |> + self.skip(); // |> fn get_stream_op_syntax_error(loc: Location) -> ParseError { - ParseError::syntax_error(0, loc, switch_lang!( - "japanese" => "パイプ演算子の後には関数・メソッド・サブルーチン呼び出しのみが使用できます。", - "english" => "Only a call of function, method or subroutine is available after stream operator.", - ), - None + ParseError::syntax_error( + 0, + loc, + switch_lang!( + "japanese" => "パイプ演算子の後には関数・メソッド・サブルーチン呼び出しのみが使用できます。", + "english" => "Only a call of function, method or subroutine is available after stream operator.", + ), + None, ) } diff --git a/compiler/erg_parser/tests/stream.er b/compiler/erg_parser/tests/stream.er new file mode 100644 index 00000000..861f9ad7 --- /dev/null +++ b/compiler/erg_parser/tests/stream.er @@ -0,0 +1,2 @@ +print!(1 + 1 |> f()) +print!(1 + 1 |> .abs())