nushell/src
Yash Thakur 0303d709e6
Spread operator in record literals (#11144)
Goes towards implementing #10598, which asks for a spread operator in
lists, in records, and when calling commands (continuation of #11006,
which only implements it in lists)

# Description
This PR is for adding a spread operator that can be used when building
records. Additional functionality can be added later.

Changes:

- Previously, the `Expr::Record` variant held `(Expression, Expression)`
pairs. It now holds instances of an enum `RecordItem` (the name isn't
amazing) that allows either a key-value mapping or a spread operator.
- `...` will be treated as the spread operator when it appears before
`$`, `{`, or `(` inside records (no whitespace allowed in between) (not
implemented yet)
- The error message for duplicate columns now includes the column name
itself, because if two spread records are involved in such an error, you
can't tell which field was duplicated from the spans alone

`...` will still be treated as a normal string outside records, and even
in records, it is not treated as a spread operator when not followed
immediately by a `$`, `{`, or `(`.

# User-Facing Changes
Users will be able to use `...` when building records.

```
> let rec = { x: 1, ...{ a: 2 } }
> $rec
╭───┬───╮
│ x │ 1 │
│ a │ 2 │
╰───┴───╯
> { foo: bar, ...$rec, baz: blah }
╭─────┬──────╮
│ foo │ bar  │
│ x   │ 1    │
│ a   │ 2    │
│ baz │ blah │
╰─────┴──────╯
```
If you want to update a field of a record, you'll have to use `merge`
instead:
```
> { ...$rec, x: 5 }
Error: nu:🐚:column_defined_twice

  × Record field or table column used twice: x
   ╭─[entry #2:1:1]
 1 │  { ...$rec, x: 5 }
   ·       ──┬─  ┬
   ·         │   ╰── field redefined here
   ·         ╰── field first defined here
   ╰────
> $rec | merge { x: 5 }
╭───┬───╮
│ x │ 5 │
│ a │ 2 │
╰───┴───╯
```

# Tests + Formatting

# After Submitting
2023-11-29 18:31:31 +01:00
..
tests Spread operator in record literals (#11144) 2023-11-29 18:31:31 +01:00
command.rs Apply nightly clippy fixes (#11083) 2023-11-17 09:15:55 -06:00
config_files.rs Improve case insensitivity consistency (#10884) 2023-11-08 23:58:54 +01:00
ide.rs Convert FileNotFoundCustom to named fields (#11123) 2023-11-21 17:30:21 -06:00
logger.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
main.rs Add stor family of commands (#11170) 2023-11-29 08:02:46 -08:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
run.rs allow --login to be used with nu's --commands parameter (#10253) 2023-09-06 13:27:16 -05:00
signals.rs Cleanup of src/main.rs (#7801) 2023-01-20 10:44:49 -08:00
terminal.rs Fix rm on macOS (#10282) 2023-09-08 19:03:30 -05:00
test_bins.rs add echo_env_mixed testbin to reduce windows only tests (#11172) 2023-11-28 06:42:35 -06:00
tests.rs Spread operator for list literals (#11006) 2023-11-22 23:10:08 +02:00

Nushell REPL

This directory contains the main Nushell REPL (read eval print loop) as part of the CLI portion of Nushell, which creates the nu binary itself.

Current versions of the nu binary will use the Nu argument parsing logic to parse the commandline arguments passed to nu, leaving the logic here to be a thin layer around what the core libraries.