nushell/crates/nu-cmd-lang/src
mike 5bfec20244
add match guards (#9621)
## description

this pr adds [match
guards](https://doc.rust-lang.org/reference/expressions/match-expr.html#match-guards)
to match patterns
```nushell
match $x {
   _ if $x starts-with 'nu' => {},
   $x => {}
}
```

these work pretty much like rust's match guards, with few limitations:

1. multiple matches using the `|` are not (yet?) supported
 
```nushell
match $num {
    0 | _ if (is-odd $num) => {},
    _ => {}
}
```

2. blocks cannot be used as guards, (yet?)

```nushell
match $num {
    $x if { $x ** $x == inf } => {},
     _ => {}
}
```

## checklist
- [x] syntax
- [x] syntax highlighting[^1]
- [x] semantics
- [x] tests
- [x] clean up

[^1]: defered for another pr
2023-07-16 12:25:12 +12:00
..
core_commands add match guards (#9621) 2023-07-16 12:25:12 +12:00
default_context.rs Custom command input/output types (#9690) 2023-07-15 09:51:28 +12:00
example_support.rs Apply nightly clippy lints (#9654) 2023-07-12 00:00:31 +02:00
example_test.rs Test examples of use (#9032) 2023-06-25 07:43:48 -05:00
lib.rs cratification: Example support (#8231) 2023-02-27 13:58:56 -08:00