mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 05:10:18 +02:00
Relax the closure syntax, highlight differently (#8846)
# Description This relaxes the closure syntax so that `||` is no longer required. This allows for `ls | each { $in.name }` for example. I've gone ahead and changed the syntax highlighting so that blocks and closures are distinct for now. # User-Facing Changes Removes `||` requirement for closures. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@@ -1589,10 +1589,8 @@ pub fn parse_brace_expr(
|
||||
|
||||
if matches!(second_token, None) {
|
||||
// If we're empty, that means an empty record or closure
|
||||
if matches!(shape, SyntaxShape::Closure(None)) {
|
||||
parse_closure_expression(working_set, shape, span, false)
|
||||
} else if matches!(shape, SyntaxShape::Closure(Some(_))) {
|
||||
parse_closure_expression(working_set, shape, span, true)
|
||||
if matches!(shape, SyntaxShape::Closure(_)) {
|
||||
parse_closure_expression(working_set, shape, span)
|
||||
} else if matches!(shape, SyntaxShape::Block) {
|
||||
parse_block_expression(working_set, span)
|
||||
} else if matches!(shape, SyntaxShape::MatchBlock) {
|
||||
@@ -1603,13 +1601,11 @@ pub fn parse_brace_expr(
|
||||
} else if matches!(second_token_contents, Some(TokenContents::Pipe))
|
||||
|| matches!(second_token_contents, Some(TokenContents::PipePipe))
|
||||
{
|
||||
parse_closure_expression(working_set, shape, span, true)
|
||||
parse_closure_expression(working_set, shape, span)
|
||||
} else if matches!(third_token, Some(b":")) {
|
||||
parse_full_cell_path(working_set, None, span)
|
||||
} else if matches!(shape, SyntaxShape::Closure(None)) {
|
||||
parse_closure_expression(working_set, shape, span, false)
|
||||
} else if matches!(shape, SyntaxShape::Closure(Some(_))) || matches!(shape, SyntaxShape::Any) {
|
||||
parse_closure_expression(working_set, shape, span, true)
|
||||
} else if matches!(shape, SyntaxShape::Closure(_)) || matches!(shape, SyntaxShape::Any) {
|
||||
parse_closure_expression(working_set, shape, span)
|
||||
} else if matches!(shape, SyntaxShape::Block) {
|
||||
parse_block_expression(working_set, span)
|
||||
} else if matches!(shape, SyntaxShape::MatchBlock) {
|
||||
@@ -4201,7 +4197,6 @@ pub fn parse_closure_expression(
|
||||
working_set: &mut StateWorkingSet,
|
||||
shape: &SyntaxShape,
|
||||
span: Span,
|
||||
require_pipe: bool,
|
||||
) -> Expression {
|
||||
trace!("parsing: closure expression");
|
||||
|
||||
@@ -4275,15 +4270,7 @@ pub fn parse_closure_expression(
|
||||
Some((Box::new(Signature::new("closure".to_string())), *span)),
|
||||
1,
|
||||
),
|
||||
_ => {
|
||||
if require_pipe {
|
||||
working_set.error(ParseError::ClosureMissingPipe(span));
|
||||
working_set.exit_scope();
|
||||
return garbage(span);
|
||||
} else {
|
||||
(None, 0)
|
||||
}
|
||||
}
|
||||
_ => (None, 0),
|
||||
};
|
||||
|
||||
// TODO: Finish this
|
||||
|
Reference in New Issue
Block a user