Add stream.er

This commit is contained in:
Shunsuke Shibayama 2022-11-16 08:27:33 +09:00
parent 48f8ef3788
commit f3a5d31ec4
4 changed files with 24 additions and 10 deletions

View file

@ -1081,8 +1081,13 @@ pub struct Call {
impl NestedDisplay for Call { impl NestedDisplay for Call {
fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, level: usize) -> std::fmt::Result { fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, level: usize) -> std::fmt::Result {
writeln!(f, "({}){}:", self.obj, fmt_option!(self.attr_name),)?; writeln!(f, "({}){}", self.obj, fmt_option!(self.attr_name),)?;
self.args.fmt_nest(f, level + 1) if self.args.is_empty() {
write!(f, "()")
} else {
writeln!(f, ":")?;
self.args.fmt_nest(f, level + 1)
}
} }
} }

View file

@ -1017,8 +1017,12 @@ impl NestedDisplay for Call {
if let Some(attr_name) = self.attr_name.as_ref() { if let Some(attr_name) = self.attr_name.as_ref() {
write!(f, "{}", attr_name)?; write!(f, "{}", attr_name)?;
} }
writeln!(f, ":")?; if self.args.is_empty() {
self.args.fmt_nest(f, level + 1) write!(f, "()")
} else {
writeln!(f, ":")?;
self.args.fmt_nest(f, level + 1)
}
} }
} }

View file

@ -2170,14 +2170,17 @@ impl Parser {
/// x |> f() => f(x) /// x |> f() => f(x)
fn try_reduce_stream_operator(&mut self, stack: &mut Vec<ExprOrOp>) -> ParseResult<()> { fn try_reduce_stream_operator(&mut self, stack: &mut Vec<ExprOrOp>) -> ParseResult<()> {
debug_call_info!(self); debug_call_info!(self);
self.skip(); // |> self.skip(); // |>
fn get_stream_op_syntax_error(loc: Location) -> ParseError { fn get_stream_op_syntax_error(loc: Location) -> ParseError {
ParseError::syntax_error(0, loc, switch_lang!( ParseError::syntax_error(
"japanese" => "パイプ演算子の後には関数・メソッド・サブルーチン呼び出しのみが使用できます。", 0,
"english" => "Only a call of function, method or subroutine is available after stream operator.", loc,
), switch_lang!(
None "japanese" => "パイプ演算子の後には関数・メソッド・サブルーチン呼び出しのみが使用できます。",
"english" => "Only a call of function, method or subroutine is available after stream operator.",
),
None,
) )
} }

View file

@ -0,0 +1,2 @@
print!(1 + 1 |> f())
print!(1 + 1 |> .abs())