feat: Add the pipeline operator |> for chained method calls.#1061
feat: Add the pipeline operator |> for chained method calls.#1061yonas wants to merge 1 commit intorhaiscript:mainfrom
Conversation
0d47614 to
2f5c842
Compare
2f5c842 to
3dd6cc5
Compare
| } | ||
|
|
||
| // Range iterator with step | ||
| #[derive(Clone, Hash, Eq, PartialEq)] |
There was a problem hiding this comment.
Why remove the derive attributes?
| #[cfg(not(feature = "no_module"))] | ||
| let (_index, name, namespace, _hash) = x; | ||
| #[cfg(feature = "no_module")] | ||
| let (index, name) = x; |
There was a problem hiding this comment.
CI seems to complain about index being unused here...
|
|
||
| Expr::FnCall(fn_call.into(), pos) | ||
| } | ||
| _ => op_base.into_fn_call_expr(pos), |
There was a problem hiding this comment.
We'd need parsing errors if the stuff following the operator is not a proper function call, instead of allowing it to go through.
|
|
||
| Precedence::new(match self { | ||
| Or | XOr | Pipe => 30, | ||
| Or | XOr | Pipe | PipeArrow => 30, |
There was a problem hiding this comment.
Do we need a lower precedence for |>?
| } | ||
| ('|', '>') => { | ||
| stream.eat_next_and_advance(pos); | ||
| return (Token::Reserved(Box::new("|>".into())), start_pos); |
There was a problem hiding this comment.
We have to be careful here... some users may depend on the fact that |> is a reserved symbol and define it as a custom operator. This may break code, but I see that you're checking this after checking for custom operators...
| name: self.get_interned_string(&op), | ||
| hashes: FnCallHashes::from_native_only(hash), | ||
| args: IntoIterator::into_iter([root, rhs]).collect(), | ||
| args: IntoIterator::into_iter([root.clone(), rhs.clone()]).collect(), |
There was a problem hiding this comment.
Also is it necessary to clone the arguments?
Fixes #1062