nushell/crates/nu-parser/src
Devyn Cairns 8e2917b9ae
Make assignment and const consistent with let/mut (#13385)
# Description

This makes assignment operations and `const` behave the same way `let`
and `mut` do, absorbing the rest of the pipeline.

Changes the lexer to be able to recognize assignment operators as a
separate token, and then makes the lite parser continue to push spans
into the same command regardless of any redirections or pipes if an
assignment operator is encountered. Because the pipeline is no longer
split up by the lite parser at this point, it's trivial to just parse
the right hand side as if it were a subexpression not contained within
parentheses.

# User-Facing Changes
Big breaking change. These are all now possible:

```nushell
const path = 'a' | path join 'b'

mut x = 2
$x = random int
$x = [1 2 3] | math sum

$env.FOO = random chars
```

In the past, these would have led to (an attempt at) bare word string
parsing. So while `$env.FOO = bar` would have previously set the
environment variable `FOO` to the string `"bar"`, it now tries to run
the command named `bar`, hence the major breaking change.

However, this is desirable because it is very consistent - if you see
the `=`, you can just assume it absorbs everything else to the right of
it.

# Tests + Formatting
Added tests for the new behaviour. Adjusted some existing tests that
depended on the right hand side of assignments being parsed as
barewords.

# After Submitting
- [ ] release notes (breaking change!)
2024-07-30 18:55:22 -05:00
..
deparse.rs update deps calamine and quick-xml (#11582) 2024-01-19 12:23:51 -06:00
exportable.rs Restructure nu-protocol in more meaningful units (#11917) 2024-03-10 18:45:45 +01:00
flatten.rs Make parsing for unknown args in known externals like normal external calls (#13414) 2024-07-21 01:32:36 -07:00
known_external.rs Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
lex.rs Make assignment and const consistent with let/mut (#13385) 2024-07-30 18:55:22 -05:00
lib.rs Add top-level crate documentation/READMEs (#12907) 2024-07-14 10:10:41 +02:00
lite_parser.rs Make assignment and const consistent with let/mut (#13385) 2024-07-30 18:55:22 -05:00
parse_keywords.rs Make assignment and const consistent with let/mut (#13385) 2024-07-30 18:55:22 -05:00
parse_patterns.rs Internal representation (IR) compiler and evaluator (#13330) 2024-07-10 17:33:59 -07:00
parse_shape_specs.rs Add command_prelude module (#12291) 2024-03-26 21:17:30 +00:00
parser.rs Make assignment and const consistent with let/mut (#13385) 2024-07-30 18:55:22 -05:00
type_check.rs Mention the actual output type on an OutputMismatch error (#13355) 2024-07-12 11:45:53 +02:00