From 9996e4a1f8767ec74e821cab07a11947b8ed8983 Mon Sep 17 00:00:00 2001 From: Ian Manske Date: Wed, 24 Apr 2024 15:46:35 +0000 Subject: [PATCH] Shrink the size of `Expr` (#12610) # Description Continuing from #12568, this PR further reduces the size of `Expr` from 64 to 40 bytes. It also reduces `Expression` from 128 to 96 bytes and `Type` from 32 to 24 bytes. This was accomplished by: - for `Expr` with multiple fields (e.g., `Expr::Thing(A, B, C)`), merging the fields into new AST struct types and then boxing this struct (e.g. `Expr::Thing(Box)`). - replacing `Vec` with `Box<[T]>` in multiple places. `Expr`s and `Expression`s should rarely be mutated, if at all, so this optimization makes sense. By reducing the size of these types, I didn't notice a large performance improvement (at least compared to #12568). But this PR does reduce the memory usage of nushell. My config is somewhat light so I only noticed a difference of 1.4MiB (38.9MiB vs 37.5MiB). --------- Co-authored-by: Stefan Holderbach --- .../src/commands/keybindings_default.rs | 2 +- .../nu-cli/src/commands/keybindings_list.rs | 2 +- crates/nu-cli/src/syntax_highlight.rs | 8 +- .../src/dataframe/eager/to_nu.rs | 2 +- crates/nu-cmd-extra/src/extra/bits/into.rs | 4 +- .../nu-cmd-extra/src/extra/conversions/fmt.rs | 2 +- .../src/extra/filters/roll/roll_down.rs | 2 +- .../src/extra/filters/roll/roll_left.rs | 4 +- .../src/extra/filters/roll/roll_right.rs | 4 +- .../src/extra/filters/roll/roll_up.rs | 2 +- .../nu-cmd-extra/src/extra/filters/rotate.rs | 4 +- .../src/extra/filters/update_cells.rs | 2 +- .../src/extra/formats/from/url.rs | 2 +- .../src/extra/platform/ansi/gradient.rs | 4 +- .../extra/strings/encode_decode/decode_hex.rs | 4 +- .../extra/strings/encode_decode/encode_hex.rs | 4 +- .../src/extra/strings/format/command.rs | 4 +- .../src/extra/strings/str_/case/camel_case.rs | 4 +- .../src/extra/strings/str_/case/kebab_case.rs | 4 +- .../extra/strings/str_/case/pascal_case.rs | 4 +- .../strings/str_/case/screaming_snake_case.rs | 4 +- .../src/extra/strings/str_/case/snake_case.rs | 4 +- .../src/extra/strings/str_/case/title_case.rs | 4 +- .../src/core_commands/lazy_make.rs | 2 +- .../nu-cmd-lang/src/core_commands/version.rs | 2 +- .../nu-cmd-plugin/src/commands/plugin/list.rs | 19 +- crates/nu-command/src/bytes/add.rs | 4 +- crates/nu-command/src/bytes/at.rs | 4 +- crates/nu-command/src/bytes/ends_with.rs | 4 +- crates/nu-command/src/bytes/index_of.rs | 4 +- crates/nu-command/src/bytes/length.rs | 4 +- crates/nu-command/src/bytes/remove.rs | 4 +- crates/nu-command/src/bytes/replace.rs | 4 +- crates/nu-command/src/bytes/reverse.rs | 4 +- crates/nu-command/src/bytes/starts_with.rs | 4 +- crates/nu-command/src/charting/histogram.rs | 2 +- .../nu-command/src/conversions/into/binary.rs | 4 +- .../nu-command/src/conversions/into/bool.rs | 6 +- .../src/conversions/into/cell_path.rs | 7 +- .../src/conversions/into/datetime.rs | 4 +- .../src/conversions/into/duration.rs | 10 +- .../src/conversions/into/filesize.rs | 4 +- .../nu-command/src/conversions/into/float.rs | 4 +- .../nu-command/src/conversions/into/glob.rs | 4 +- crates/nu-command/src/conversions/into/int.rs | 4 +- .../nu-command/src/conversions/into/record.rs | 10 +- .../nu-command/src/conversions/into/string.rs | 4 +- .../nu-command/src/conversions/into/value.rs | 2 +- .../src/database/commands/into_sqlite.rs | 4 +- crates/nu-command/src/date/list_timezone.rs | 2 +- crates/nu-command/src/date/to_record.rs | 4 +- crates/nu-command/src/date/to_table.rs | 4 +- crates/nu-command/src/debug/ast.rs | 2 +- crates/nu-command/src/debug/info.rs | 2 +- crates/nu-command/src/debug/metadata.rs | 2 +- crates/nu-command/src/debug/profile.rs | 2 +- crates/nu-command/src/debug/view_files.rs | 15 +- crates/nu-command/src/env/load_env.rs | 2 +- crates/nu-command/src/filesystem/du.rs | 2 +- crates/nu-command/src/filesystem/ls.rs | 2 +- crates/nu-command/src/filesystem/watch.rs | 2 +- crates/nu-command/src/filters/columns.rs | 4 +- crates/nu-command/src/filters/drop/column.rs | 4 +- crates/nu-command/src/filters/drop/drop_.rs | 2 +- crates/nu-command/src/filters/each.rs | 2 +- crates/nu-command/src/filters/enumerate.rs | 2 +- crates/nu-command/src/filters/flatten.rs | 2 +- crates/nu-command/src/filters/get.rs | 4 +- crates/nu-command/src/filters/headers.rs | 4 +- crates/nu-command/src/filters/insert.rs | 4 +- crates/nu-command/src/filters/items.rs | 2 +- crates/nu-command/src/filters/join.rs | 2 +- crates/nu-command/src/filters/merge.rs | 4 +- crates/nu-command/src/filters/move_.rs | 4 +- crates/nu-command/src/filters/par_each.rs | 2 +- crates/nu-command/src/filters/reduce.rs | 2 +- crates/nu-command/src/filters/reject.rs | 4 +- crates/nu-command/src/filters/rename.rs | 4 +- crates/nu-command/src/filters/select.rs | 4 +- crates/nu-command/src/filters/skip/skip_.rs | 2 +- .../nu-command/src/filters/skip/skip_until.rs | 2 +- .../nu-command/src/filters/skip/skip_while.rs | 2 +- crates/nu-command/src/filters/sort.rs | 2 +- crates/nu-command/src/filters/sort_by.rs | 4 +- crates/nu-command/src/filters/split_by.rs | 2 +- crates/nu-command/src/filters/take/take_.rs | 2 +- .../nu-command/src/filters/take/take_until.rs | 2 +- .../nu-command/src/filters/take/take_while.rs | 2 +- crates/nu-command/src/filters/transpose.rs | 4 +- crates/nu-command/src/filters/uniq_by.rs | 2 +- crates/nu-command/src/filters/update.rs | 4 +- crates/nu-command/src/filters/upsert.rs | 4 +- crates/nu-command/src/filters/values.rs | 4 +- crates/nu-command/src/filters/where_.rs | 2 +- crates/nu-command/src/filters/wrap.rs | 6 +- crates/nu-command/src/formats/from/csv.rs | 2 +- crates/nu-command/src/formats/from/ods.rs | 2 +- crates/nu-command/src/formats/from/ssv.rs | 2 +- crates/nu-command/src/formats/from/toml.rs | 2 +- crates/nu-command/src/formats/from/tsv.rs | 2 +- crates/nu-command/src/formats/from/xlsx.rs | 2 +- crates/nu-command/src/formats/from/xml.rs | 2 +- crates/nu-command/src/formats/to/csv.rs | 4 +- crates/nu-command/src/formats/to/toml.rs | 2 +- crates/nu-command/src/formats/to/tsv.rs | 4 +- crates/nu-command/src/formats/to/xml.rs | 18 +- crates/nu-command/src/generators/cal.rs | 2 +- crates/nu-command/src/hash/generic_digest.rs | 4 +- crates/nu-command/src/help/help_aliases.rs | 2 +- crates/nu-command/src/help/help_commands.rs | 2 +- crates/nu-command/src/help/help_escapes.rs | 2 +- crates/nu-command/src/help/help_externs.rs | 2 +- crates/nu-command/src/help/help_modules.rs | 2 +- crates/nu-command/src/help/help_operators.rs | 2 +- crates/nu-command/src/math/avg.rs | 4 +- crates/nu-command/src/math/max.rs | 4 +- crates/nu-command/src/math/median.rs | 4 +- crates/nu-command/src/math/min.rs | 4 +- crates/nu-command/src/math/mode.rs | 2 +- crates/nu-command/src/math/product.rs | 4 +- crates/nu-command/src/math/stddev.rs | 4 +- crates/nu-command/src/math/sum.rs | 4 +- crates/nu-command/src/math/variance.rs | 4 +- crates/nu-command/src/misc/panic.rs | 2 +- .../nu-command/src/network/url/build_query.rs | 4 +- crates/nu-command/src/network/url/decode.rs | 4 +- crates/nu-command/src/network/url/encode.rs | 4 +- crates/nu-command/src/network/url/join.rs | 2 +- crates/nu-command/src/network/url/parse.rs | 6 +- crates/nu-command/src/path/join.rs | 4 +- crates/nu-command/src/path/parse.rs | 4 +- crates/nu-command/src/platform/ansi/link.rs | 4 +- crates/nu-command/src/platform/ansi/strip.rs | 4 +- .../src/platform/input/input_listen.rs | 4 +- crates/nu-command/src/platform/term_size.rs | 5 +- crates/nu-command/src/stor/create.rs | 2 +- crates/nu-command/src/stor/delete.rs | 2 +- crates/nu-command/src/stor/export.rs | 2 +- crates/nu-command/src/stor/import.rs | 2 +- crates/nu-command/src/stor/insert.rs | 2 +- crates/nu-command/src/stor/reset.rs | 2 +- crates/nu-command/src/stor/update.rs | 2 +- .../nu-command/src/strings/detect_columns.rs | 2 +- .../strings/encode_decode/decode_base64.rs | 4 +- .../strings/encode_decode/encode_base64.rs | 4 +- crates/nu-command/src/strings/format/date.rs | 2 +- .../nu-command/src/strings/format/duration.rs | 2 +- .../nu-command/src/strings/format/filesize.rs | 4 +- crates/nu-command/src/strings/parse.rs | 4 +- crates/nu-command/src/strings/split/column.rs | 4 +- .../src/strings/str_/case/capitalize.rs | 4 +- .../src/strings/str_/case/downcase.rs | 4 +- .../src/strings/str_/case/upcase.rs | 4 +- .../nu-command/src/strings/str_/contains.rs | 4 +- .../nu-command/src/strings/str_/distance.rs | 4 +- .../nu-command/src/strings/str_/ends_with.rs | 4 +- .../nu-command/src/strings/str_/index_of.rs | 4 +- crates/nu-command/src/strings/str_/length.rs | 4 +- crates/nu-command/src/strings/str_/replace.rs | 4 +- crates/nu-command/src/strings/str_/reverse.rs | 4 +- .../src/strings/str_/starts_with.rs | 4 +- crates/nu-command/src/strings/str_/stats.rs | 2 +- .../nu-command/src/strings/str_/substring.rs | 4 +- .../nu-command/src/strings/str_/trim/trim_.rs | 4 +- crates/nu-command/src/system/complete.rs | 2 +- crates/nu-command/src/system/ps.rs | 2 +- crates/nu-command/src/system/sys.rs | 2 +- crates/nu-command/src/system/uname.rs | 2 +- crates/nu-command/src/system/which_.rs | 2 +- crates/nu-command/src/viewers/griddle.rs | 2 +- crates/nu-engine/src/documentation.rs | 11 +- crates/nu-parser/src/flatten.rs | 34 ++-- crates/nu-parser/src/parse_keywords.rs | 4 +- crates/nu-parser/src/parser.rs | 146 +++++++-------- crates/nu-parser/src/type_check.rs | 74 ++++---- crates/nu-parser/tests/test_parser.rs | 171 ++++++++++-------- crates/nu-protocol/src/ast/expr.rs | 37 ++-- crates/nu-protocol/src/ast/expression.rs | 46 ++--- crates/nu-protocol/src/ast/keyword.rs | 10 + crates/nu-protocol/src/ast/mod.rs | 8 + crates/nu-protocol/src/ast/range.rs | 10 + crates/nu-protocol/src/ast/table.rs | 8 + crates/nu-protocol/src/ast/value_with_unit.rs | 9 + crates/nu-protocol/src/debugger/profiler.rs | 8 +- .../nu-protocol/src/engine/pattern_match.rs | 18 +- crates/nu-protocol/src/eval_base.rs | 28 +-- crates/nu-protocol/src/ty.rs | 14 +- crates/nu-protocol/src/value/mod.rs | 2 +- .../nu_plugin_example/src/commands/config.rs | 2 +- crates/nu_plugin_formats/src/from/eml.rs | 2 +- crates/nu_plugin_formats/src/from/ics.rs | 2 +- crates/nu_plugin_formats/src/from/ini.rs | 2 +- crates/nu_plugin_formats/src/from/vcf.rs | 2 +- .../src/dataframe/eager/to_nu.rs | 2 +- crates/nuon/src/from.rs | 41 +++-- 195 files changed, 688 insertions(+), 601 deletions(-) create mode 100644 crates/nu-protocol/src/ast/keyword.rs create mode 100644 crates/nu-protocol/src/ast/range.rs create mode 100644 crates/nu-protocol/src/ast/table.rs create mode 100644 crates/nu-protocol/src/ast/value_with_unit.rs diff --git a/crates/nu-cli/src/commands/keybindings_default.rs b/crates/nu-cli/src/commands/keybindings_default.rs index 1fbd614085..1a62942b15 100644 --- a/crates/nu-cli/src/commands/keybindings_default.rs +++ b/crates/nu-cli/src/commands/keybindings_default.rs @@ -12,7 +12,7 @@ impl Command for KeybindingsDefault { fn signature(&self) -> Signature { Signature::build(self.name()) .category(Category::Platform) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) } fn usage(&self) -> &str { diff --git a/crates/nu-cli/src/commands/keybindings_list.rs b/crates/nu-cli/src/commands/keybindings_list.rs index 72399c773a..f4450c0c23 100644 --- a/crates/nu-cli/src/commands/keybindings_list.rs +++ b/crates/nu-cli/src/commands/keybindings_list.rs @@ -14,7 +14,7 @@ impl Command for KeybindingsList { fn signature(&self) -> Signature { Signature::build(self.name()) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .switch("modifiers", "list of modifiers", Some('m')) .switch("keycodes", "list of keycodes", Some('k')) .switch("modes", "list of edit modes", Some('o')) diff --git a/crates/nu-cli/src/syntax_highlight.rs b/crates/nu-cli/src/syntax_highlight.rs index 7bb6abd7ca..8d0c582bd1 100644 --- a/crates/nu-cli/src/syntax_highlight.rs +++ b/crates/nu-cli/src/syntax_highlight.rs @@ -361,7 +361,7 @@ fn find_matching_block_end_in_expr( Expr::Nothing => None, Expr::Garbage => None, - Expr::Table(hdr, rows) => { + Expr::Table(table) => { if expr_last == global_cursor_offset { // cursor is at table end Some(expr_first) @@ -370,11 +370,11 @@ fn find_matching_block_end_in_expr( Some(expr_last) } else { // cursor is inside table - for inner_expr in hdr { + for inner_expr in table.columns.as_ref() { find_in_expr_or_continue!(inner_expr); } - for row in rows { - for inner_expr in row { + for row in table.rows.as_ref() { + for inner_expr in row.as_ref() { find_in_expr_or_continue!(inner_expr); } } diff --git a/crates/nu-cmd-dataframe/src/dataframe/eager/to_nu.rs b/crates/nu-cmd-dataframe/src/dataframe/eager/to_nu.rs index e032269b09..73dadacb2b 100644 --- a/crates/nu-cmd-dataframe/src/dataframe/eager/to_nu.rs +++ b/crates/nu-cmd-dataframe/src/dataframe/eager/to_nu.rs @@ -24,7 +24,7 @@ impl Command for ToNu { .switch("tail", "shows tail rows", Some('t')) .input_output_types(vec![ (Type::Custom("expression".into()), Type::Any), - (Type::Custom("dataframe".into()), Type::Table(vec![])), + (Type::Custom("dataframe".into()), Type::table()), ]) //.input_output_type(Type::Any, Type::Any) .category(Category::Custom("dataframe".into())) diff --git a/crates/nu-cmd-extra/src/extra/bits/into.rs b/crates/nu-cmd-extra/src/extra/bits/into.rs index 1ba64d5478..bcf82b9178 100644 --- a/crates/nu-cmd-extra/src/extra/bits/into.rs +++ b/crates/nu-cmd-extra/src/extra/bits/into.rs @@ -30,8 +30,8 @@ impl Command for BitsInto { (Type::Duration, Type::String), (Type::String, Type::String), (Type::Bool, Type::String), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) // TODO: supply exhaustive examples .rest( diff --git a/crates/nu-cmd-extra/src/extra/conversions/fmt.rs b/crates/nu-cmd-extra/src/extra/conversions/fmt.rs index 54897fd413..fec0745dac 100644 --- a/crates/nu-cmd-extra/src/extra/conversions/fmt.rs +++ b/crates/nu-cmd-extra/src/extra/conversions/fmt.rs @@ -15,7 +15,7 @@ impl Command for Fmt { fn signature(&self) -> nu_protocol::Signature { Signature::build("fmt") - .input_output_types(vec![(Type::Number, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Number, Type::record())]) .category(Category::Conversions) } diff --git a/crates/nu-cmd-extra/src/extra/filters/roll/roll_down.rs b/crates/nu-cmd-extra/src/extra/filters/roll/roll_down.rs index 03c1a0c83f..465b9f1f4c 100644 --- a/crates/nu-cmd-extra/src/extra/filters/roll/roll_down.rs +++ b/crates/nu-cmd-extra/src/extra/filters/roll/roll_down.rs @@ -16,7 +16,7 @@ impl Command for RollDown { fn signature(&self) -> Signature { Signature::build(self.name()) // TODO: It also operates on List - .input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))]) + .input_output_types(vec![(Type::table(), Type::table())]) .named("by", SyntaxShape::Int, "Number of rows to roll", Some('b')) .category(Category::Filters) } diff --git a/crates/nu-cmd-extra/src/extra/filters/roll/roll_left.rs b/crates/nu-cmd-extra/src/extra/filters/roll/roll_left.rs index 1162400abe..ff69f23268 100644 --- a/crates/nu-cmd-extra/src/extra/filters/roll/roll_left.rs +++ b/crates/nu-cmd-extra/src/extra/filters/roll/roll_left.rs @@ -16,8 +16,8 @@ impl Command for RollLeft { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ]) .named( "by", diff --git a/crates/nu-cmd-extra/src/extra/filters/roll/roll_right.rs b/crates/nu-cmd-extra/src/extra/filters/roll/roll_right.rs index ae06d3529a..d190960581 100644 --- a/crates/nu-cmd-extra/src/extra/filters/roll/roll_right.rs +++ b/crates/nu-cmd-extra/src/extra/filters/roll/roll_right.rs @@ -16,8 +16,8 @@ impl Command for RollRight { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ]) .named( "by", diff --git a/crates/nu-cmd-extra/src/extra/filters/roll/roll_up.rs b/crates/nu-cmd-extra/src/extra/filters/roll/roll_up.rs index 233e2f0899..1cd74fe247 100644 --- a/crates/nu-cmd-extra/src/extra/filters/roll/roll_up.rs +++ b/crates/nu-cmd-extra/src/extra/filters/roll/roll_up.rs @@ -16,7 +16,7 @@ impl Command for RollUp { fn signature(&self) -> Signature { Signature::build(self.name()) // TODO: It also operates on List - .input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))]) + .input_output_types(vec![(Type::table(), Type::table())]) .named("by", SyntaxShape::Int, "Number of rows to roll", Some('b')) .category(Category::Filters) } diff --git a/crates/nu-cmd-extra/src/extra/filters/rotate.rs b/crates/nu-cmd-extra/src/extra/filters/rotate.rs index ba393f45ef..1d93109604 100644 --- a/crates/nu-cmd-extra/src/extra/filters/rotate.rs +++ b/crates/nu-cmd-extra/src/extra/filters/rotate.rs @@ -11,8 +11,8 @@ impl Command for Rotate { fn signature(&self) -> Signature { Signature::build("rotate") .input_output_types(vec![ - (Type::Record(vec![]), Type::Table(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::table()), + (Type::table(), Type::table()), ]) .switch("ccw", "rotate counter clockwise", None) .rest( diff --git a/crates/nu-cmd-extra/src/extra/filters/update_cells.rs b/crates/nu-cmd-extra/src/extra/filters/update_cells.rs index 7cc43678ce..d117d7fad2 100644 --- a/crates/nu-cmd-extra/src/extra/filters/update_cells.rs +++ b/crates/nu-cmd-extra/src/extra/filters/update_cells.rs @@ -12,7 +12,7 @@ impl Command for UpdateCells { fn signature(&self) -> Signature { Signature::build("update cells") - .input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))]) + .input_output_types(vec![(Type::table(), Type::table())]) .required( "closure", SyntaxShape::Closure(Some(vec![SyntaxShape::Any])), diff --git a/crates/nu-cmd-extra/src/extra/formats/from/url.rs b/crates/nu-cmd-extra/src/extra/formats/from/url.rs index 1258bb2df6..c8e21aa703 100644 --- a/crates/nu-cmd-extra/src/extra/formats/from/url.rs +++ b/crates/nu-cmd-extra/src/extra/formats/from/url.rs @@ -10,7 +10,7 @@ impl Command for FromUrl { fn signature(&self) -> Signature { Signature::build("from url") - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) .category(Category::Formats) } diff --git a/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs b/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs index 78ed09c2cb..21c7e42a61 100644 --- a/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs +++ b/crates/nu-cmd-extra/src/extra/platform/ansi/gradient.rs @@ -46,8 +46,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Platform) diff --git a/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs b/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs index 9dd07b286e..7be007d1c7 100644 --- a/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs +++ b/crates/nu-cmd-extra/src/extra/strings/encode_decode/decode_hex.rs @@ -17,8 +17,8 @@ impl Command for DecodeHex { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Binary)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs b/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs index e68d556187..d261f7fe1f 100644 --- a/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs +++ b/crates/nu-cmd-extra/src/extra/strings/encode_decode/encode_hex.rs @@ -17,8 +17,8 @@ impl Command for EncodeHex { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-extra/src/extra/strings/format/command.rs b/crates/nu-cmd-extra/src/extra/strings/format/command.rs index 5b63d29ae5..437bbc14c9 100644 --- a/crates/nu-cmd-extra/src/extra/strings/format/command.rs +++ b/crates/nu-cmd-extra/src/extra/strings/format/command.rs @@ -13,8 +13,8 @@ impl Command for FormatPattern { fn signature(&self) -> Signature { Signature::build("format pattern") .input_output_types(vec![ - (Type::Table(vec![]), Type::List(Box::new(Type::String))), - (Type::Record(vec![]), Type::Any), + (Type::table(), Type::List(Box::new(Type::String))), + (Type::record(), Type::Any), ]) .required( "pattern", diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/camel_case.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/camel_case.rs index e92126932a..e48bc10e1e 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/camel_case.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/camel_case.rs @@ -18,8 +18,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/kebab_case.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/kebab_case.rs index e0869e7718..7e1accffaf 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/kebab_case.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/kebab_case.rs @@ -14,8 +14,8 @@ impl Command for SubCommand { Signature::build("str kebab-case") .input_output_types(vec![ (Type::String, Type::String), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/pascal_case.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/pascal_case.rs index c99b8de225..a38c3715c9 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/pascal_case.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/pascal_case.rs @@ -14,8 +14,8 @@ impl Command for SubCommand { Signature::build("str pascal-case") .input_output_types(vec![ (Type::String, Type::String), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/screaming_snake_case.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/screaming_snake_case.rs index 498e0a8d96..d67b72f1b7 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/screaming_snake_case.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/screaming_snake_case.rs @@ -18,8 +18,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/snake_case.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/snake_case.rs index 7af2f9bd43..84338295c3 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/snake_case.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/snake_case.rs @@ -18,8 +18,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-extra/src/extra/strings/str_/case/title_case.rs b/crates/nu-cmd-extra/src/extra/strings/str_/case/title_case.rs index 524ca76556..ffcfd8d8d4 100644 --- a/crates/nu-cmd-extra/src/extra/strings/str_/case/title_case.rs +++ b/crates/nu-cmd-extra/src/extra/strings/str_/case/title_case.rs @@ -18,8 +18,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-cmd-lang/src/core_commands/lazy_make.rs b/crates/nu-cmd-lang/src/core_commands/lazy_make.rs index a9c4355678..20e7308397 100644 --- a/crates/nu-cmd-lang/src/core_commands/lazy_make.rs +++ b/crates/nu-cmd-lang/src/core_commands/lazy_make.rs @@ -15,7 +15,7 @@ impl Command for LazyMake { fn signature(&self) -> Signature { Signature::build("lazy make") - .input_output_types(vec![(Type::Nothing, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::record())]) .required_named( "columns", SyntaxShape::List(Box::new(SyntaxShape::String)), diff --git a/crates/nu-cmd-lang/src/core_commands/version.rs b/crates/nu-cmd-lang/src/core_commands/version.rs index 6af44035d5..3455b9c699 100644 --- a/crates/nu-cmd-lang/src/core_commands/version.rs +++ b/crates/nu-cmd-lang/src/core_commands/version.rs @@ -16,7 +16,7 @@ impl Command for Version { fn signature(&self) -> Signature { Signature::build("version") - .input_output_types(vec![(Type::Nothing, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::record())]) .allow_variants_without_examples(true) .category(Category::Core) } diff --git a/crates/nu-cmd-plugin/src/commands/plugin/list.rs b/crates/nu-cmd-plugin/src/commands/plugin/list.rs index 94b53ef6d4..1d630b67c0 100644 --- a/crates/nu-cmd-plugin/src/commands/plugin/list.rs +++ b/crates/nu-cmd-plugin/src/commands/plugin/list.rs @@ -13,14 +13,17 @@ impl Command for PluginList { Signature::build("plugin list") .input_output_type( Type::Nothing, - Type::Table(vec![ - ("name".into(), Type::String), - ("is_running".into(), Type::Bool), - ("pid".into(), Type::Int), - ("filename".into(), Type::String), - ("shell".into(), Type::String), - ("commands".into(), Type::List(Type::String.into())), - ]), + Type::Table( + [ + ("name".into(), Type::String), + ("is_running".into(), Type::Bool), + ("pid".into(), Type::Int), + ("filename".into(), Type::String), + ("shell".into(), Type::String), + ("commands".into(), Type::List(Type::String.into())), + ] + .into(), + ), ) .category(Category::Plugin) } diff --git a/crates/nu-command/src/bytes/add.rs b/crates/nu-command/src/bytes/add.rs index dca8707b49..8514718cfd 100644 --- a/crates/nu-command/src/bytes/add.rs +++ b/crates/nu-command/src/bytes/add.rs @@ -31,8 +31,8 @@ impl Command for BytesAdd { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::Binary)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("data", SyntaxShape::Binary, "The binary to add.") diff --git a/crates/nu-command/src/bytes/at.rs b/crates/nu-command/src/bytes/at.rs index 6823b01403..55b2998ec4 100644 --- a/crates/nu-command/src/bytes/at.rs +++ b/crates/nu-command/src/bytes/at.rs @@ -41,8 +41,8 @@ impl Command for BytesAt { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::Binary)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .required("range", SyntaxShape::Range, "The range to get bytes.") .rest( diff --git a/crates/nu-command/src/bytes/ends_with.rs b/crates/nu-command/src/bytes/ends_with.rs index 5f421d5216..ef0389db0c 100644 --- a/crates/nu-command/src/bytes/ends_with.rs +++ b/crates/nu-command/src/bytes/ends_with.rs @@ -24,8 +24,8 @@ impl Command for BytesEndsWith { fn signature(&self) -> Signature { Signature::build("bytes ends-with") .input_output_types(vec![(Type::Binary, Type::Bool), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("pattern", SyntaxShape::Binary, "The pattern to match.") diff --git a/crates/nu-command/src/bytes/index_of.rs b/crates/nu-command/src/bytes/index_of.rs index 332a541add..bdf51b24d9 100644 --- a/crates/nu-command/src/bytes/index_of.rs +++ b/crates/nu-command/src/bytes/index_of.rs @@ -28,8 +28,8 @@ impl Command for BytesIndexOf { (Type::Binary, Type::Any), // FIXME: this shouldn't be needed, cell paths should work with the two // above - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required( diff --git a/crates/nu-command/src/bytes/length.rs b/crates/nu-command/src/bytes/length.rs index 7af3876113..aaaf23e0a5 100644 --- a/crates/nu-command/src/bytes/length.rs +++ b/crates/nu-command/src/bytes/length.rs @@ -17,8 +17,8 @@ impl Command for BytesLen { Type::List(Box::new(Type::Binary)), Type::List(Box::new(Type::Int)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/bytes/remove.rs b/crates/nu-command/src/bytes/remove.rs index 6a95c050f4..9afef07e8b 100644 --- a/crates/nu-command/src/bytes/remove.rs +++ b/crates/nu-command/src/bytes/remove.rs @@ -26,8 +26,8 @@ impl Command for BytesRemove { Signature::build("bytes remove") .input_output_types(vec![ (Type::Binary, Type::Binary), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .required("pattern", SyntaxShape::Binary, "The pattern to find.") .rest( diff --git a/crates/nu-command/src/bytes/replace.rs b/crates/nu-command/src/bytes/replace.rs index 5b7e75777b..ab7ede7588 100644 --- a/crates/nu-command/src/bytes/replace.rs +++ b/crates/nu-command/src/bytes/replace.rs @@ -26,8 +26,8 @@ impl Command for BytesReplace { Signature::build("bytes replace") .input_output_types(vec![ (Type::Binary, Type::Binary), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("find", SyntaxShape::Binary, "The pattern to find.") diff --git a/crates/nu-command/src/bytes/reverse.rs b/crates/nu-command/src/bytes/reverse.rs index f1dfb22b41..171add213d 100644 --- a/crates/nu-command/src/bytes/reverse.rs +++ b/crates/nu-command/src/bytes/reverse.rs @@ -13,8 +13,8 @@ impl Command for BytesReverse { Signature::build("bytes reverse") .input_output_types(vec![ (Type::Binary, Type::Binary), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/bytes/starts_with.rs b/crates/nu-command/src/bytes/starts_with.rs index 07b1b42547..69187894b4 100644 --- a/crates/nu-command/src/bytes/starts_with.rs +++ b/crates/nu-command/src/bytes/starts_with.rs @@ -25,8 +25,8 @@ impl Command for BytesStartsWith { Signature::build("bytes starts-with") .input_output_types(vec![ (Type::Binary, Type::Bool), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("pattern", SyntaxShape::Binary, "The pattern to match.") diff --git a/crates/nu-command/src/charting/histogram.rs b/crates/nu-command/src/charting/histogram.rs index acf10e2c01..35a9d82a3d 100755 --- a/crates/nu-command/src/charting/histogram.rs +++ b/crates/nu-command/src/charting/histogram.rs @@ -19,7 +19,7 @@ impl Command for Histogram { fn signature(&self) -> Signature { Signature::build("histogram") - .input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::Table(vec![])),]) + .input_output_types(vec![(Type::List(Box::new(Type::Any)), Type::table()),]) .optional("column-name", SyntaxShape::String, "Column name to calc frequency, no need to provide if input is a list.") .optional("frequency-column-name", SyntaxShape::String, "Histogram's frequency column, default to be frequency column output.") .named("percentage-type", SyntaxShape::String, "percentage calculate method, can be 'normalize' or 'relative', in 'normalize', defaults to be 'normalize'", Some('t')) diff --git a/crates/nu-command/src/conversions/into/binary.rs b/crates/nu-command/src/conversions/into/binary.rs index 36f6316a6d..6fb997a590 100644 --- a/crates/nu-command/src/conversions/into/binary.rs +++ b/crates/nu-command/src/conversions/into/binary.rs @@ -30,8 +30,8 @@ impl Command for SubCommand { (Type::Bool, Type::Binary), (Type::Filesize, Type::Binary), (Type::Date, Type::Binary), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) // TODO: supply exhaustive examples .switch("compact", "output without padding zeros", Some('c')) diff --git a/crates/nu-command/src/conversions/into/bool.rs b/crates/nu-command/src/conversions/into/bool.rs index e8ac87ed79..b1d433cb93 100644 --- a/crates/nu-command/src/conversions/into/bool.rs +++ b/crates/nu-command/src/conversions/into/bool.rs @@ -16,9 +16,9 @@ impl Command for SubCommand { (Type::Number, Type::Bool), (Type::String, Type::Bool), (Type::Bool, Type::Bool), - (Type::List(Box::new(Type::Any)), Type::Table(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::List(Box::new(Type::Any)), Type::table()), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/conversions/into/cell_path.rs b/crates/nu-command/src/conversions/into/cell_path.rs index 2ece230680..039656e9d6 100644 --- a/crates/nu-command/src/conversions/into/cell_path.rs +++ b/crates/nu-command/src/conversions/into/cell_path.rs @@ -15,10 +15,9 @@ impl Command for IntoCellPath { (Type::Int, Type::CellPath), (Type::List(Box::new(Type::Any)), Type::CellPath), ( - Type::List(Box::new(Type::Record(vec![ - ("value".into(), Type::Any), - ("optional".into(), Type::Bool), - ]))), + Type::List(Box::new(Type::Record( + [("value".into(), Type::Any), ("optional".into(), Type::Bool)].into(), + ))), Type::CellPath, ), ]) diff --git a/crates/nu-command/src/conversions/into/datetime.rs b/crates/nu-command/src/conversions/into/datetime.rs index abb0442229..157ae95079 100644 --- a/crates/nu-command/src/conversions/into/datetime.rs +++ b/crates/nu-command/src/conversions/into/datetime.rs @@ -62,8 +62,8 @@ impl Command for SubCommand { (Type::Int, Type::Date), (Type::String, Type::Date), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Date))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .named( diff --git a/crates/nu-command/src/conversions/into/duration.rs b/crates/nu-command/src/conversions/into/duration.rs index befca16983..21494f3bcc 100644 --- a/crates/nu-command/src/conversions/into/duration.rs +++ b/crates/nu-command/src/conversions/into/duration.rs @@ -17,9 +17,9 @@ impl Command for SubCommand { (Type::Int, Type::Duration), (Type::String, Type::Duration), (Type::Duration, Type::Duration), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), //todo: record | into duration -> Duration - //(Type::Record(vec![]), Type::Record(vec![])), + //(Type::record(), Type::record()), ]) //.allow_variants_without_examples(true) .named( @@ -203,9 +203,9 @@ fn string_to_duration(s: &str, span: Span) -> Result { Type::Duration, |x| x, ) { - if let Expr::ValueWithUnit(value, unit) = expression.expr { - if let Expr::Int(x) = value.expr { - match unit.item { + if let Expr::ValueWithUnit(value) = expression.expr { + if let Expr::Int(x) = value.expr.expr { + match value.unit.item { Unit::Nanosecond => return Ok(x), Unit::Microsecond => return Ok(x * 1000), Unit::Millisecond => return Ok(x * 1000 * 1000), diff --git a/crates/nu-command/src/conversions/into/filesize.rs b/crates/nu-command/src/conversions/into/filesize.rs index 706dc5c2c4..b3c1e65a3b 100644 --- a/crates/nu-command/src/conversions/into/filesize.rs +++ b/crates/nu-command/src/conversions/into/filesize.rs @@ -18,8 +18,8 @@ impl Command for SubCommand { (Type::Number, Type::Filesize), (Type::String, Type::Filesize), (Type::Filesize, Type::Filesize), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ( Type::List(Box::new(Type::Int)), Type::List(Box::new(Type::Filesize)), diff --git a/crates/nu-command/src/conversions/into/float.rs b/crates/nu-command/src/conversions/into/float.rs index 7b877ead08..9ccd7ea03f 100644 --- a/crates/nu-command/src/conversions/into/float.rs +++ b/crates/nu-command/src/conversions/into/float.rs @@ -16,8 +16,8 @@ impl Command for SubCommand { (Type::String, Type::Float), (Type::Bool, Type::Float), (Type::Float, Type::Float), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Float)), diff --git a/crates/nu-command/src/conversions/into/glob.rs b/crates/nu-command/src/conversions/into/glob.rs index 80cc1587cf..8c167b0dc0 100644 --- a/crates/nu-command/src/conversions/into/glob.rs +++ b/crates/nu-command/src/conversions/into/glob.rs @@ -27,8 +27,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Glob)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 .rest( diff --git a/crates/nu-command/src/conversions/into/int.rs b/crates/nu-command/src/conversions/into/int.rs index 955ccf3c65..a3f1c92a4f 100644 --- a/crates/nu-command/src/conversions/into/int.rs +++ b/crates/nu-command/src/conversions/into/int.rs @@ -36,8 +36,8 @@ impl Command for SubCommand { (Type::Duration, Type::Int), (Type::Filesize, Type::Int), (Type::Binary, Type::Int), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int)), diff --git a/crates/nu-command/src/conversions/into/record.rs b/crates/nu-command/src/conversions/into/record.rs index a4aebe7a1a..c9342e8e39 100644 --- a/crates/nu-command/src/conversions/into/record.rs +++ b/crates/nu-command/src/conversions/into/record.rs @@ -13,11 +13,11 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("into record") .input_output_types(vec![ - (Type::Date, Type::Record(vec![])), - (Type::Duration, Type::Record(vec![])), - (Type::List(Box::new(Type::Any)), Type::Record(vec![])), - (Type::Range, Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::Date, Type::record()), + (Type::Duration, Type::record()), + (Type::List(Box::new(Type::Any)), Type::record()), + (Type::Range, Type::record()), + (Type::record(), Type::record()), ]) .category(Category::Conversions) } diff --git a/crates/nu-command/src/conversions/into/string.rs b/crates/nu-command/src/conversions/into/string.rs index 84812b7dd2..bc791a37b2 100644 --- a/crates/nu-command/src/conversions/into/string.rs +++ b/crates/nu-command/src/conversions/into/string.rs @@ -40,8 +40,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 .rest( diff --git a/crates/nu-command/src/conversions/into/value.rs b/crates/nu-command/src/conversions/into/value.rs index e19ecf3c0c..6021a4980a 100644 --- a/crates/nu-command/src/conversions/into/value.rs +++ b/crates/nu-command/src/conversions/into/value.rs @@ -15,7 +15,7 @@ impl Command for IntoValue { fn signature(&self) -> Signature { Signature::build("into value") - .input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))]) + .input_output_types(vec![(Type::table(), Type::table())]) .named( "columns", SyntaxShape::Table(vec![]), diff --git a/crates/nu-command/src/database/commands/into_sqlite.rs b/crates/nu-command/src/database/commands/into_sqlite.rs index 876d763696..1b4d0b8073 100644 --- a/crates/nu-command/src/database/commands/into_sqlite.rs +++ b/crates/nu-command/src/database/commands/into_sqlite.rs @@ -24,8 +24,8 @@ impl Command for IntoSqliteDb { Signature::build("into sqlite") .category(Category::Conversions) .input_output_types(vec![ - (Type::Table(vec![]), Type::Nothing), - (Type::Record(vec![]), Type::Nothing), + (Type::table(), Type::Nothing), + (Type::record(), Type::Nothing), ]) .allow_variants_without_examples(true) .required( diff --git a/crates/nu-command/src/date/list_timezone.rs b/crates/nu-command/src/date/list_timezone.rs index 0bd37a4d41..bb56cb995d 100644 --- a/crates/nu-command/src/date/list_timezone.rs +++ b/crates/nu-command/src/date/list_timezone.rs @@ -11,7 +11,7 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("date list-timezone") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .category(Category::Date) } diff --git a/crates/nu-command/src/date/to_record.rs b/crates/nu-command/src/date/to_record.rs index e22e475aa3..f9c0ceff1b 100644 --- a/crates/nu-command/src/date/to_record.rs +++ b/crates/nu-command/src/date/to_record.rs @@ -13,8 +13,8 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("date to-record") .input_output_types(vec![ - (Type::Date, Type::Record(vec![])), - (Type::String, Type::Record(vec![])), + (Type::Date, Type::record()), + (Type::String, Type::record()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 .category(Category::Date) diff --git a/crates/nu-command/src/date/to_table.rs b/crates/nu-command/src/date/to_table.rs index 5455c21e4b..36c3f4a94a 100644 --- a/crates/nu-command/src/date/to_table.rs +++ b/crates/nu-command/src/date/to_table.rs @@ -13,8 +13,8 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("date to-table") .input_output_types(vec![ - (Type::Date, Type::Table(vec![])), - (Type::String, Type::Table(vec![])), + (Type::Date, Type::table()), + (Type::String, Type::table()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 .category(Category::Date) diff --git a/crates/nu-command/src/debug/ast.rs b/crates/nu-command/src/debug/ast.rs index d097dce5f6..ef28d5a205 100644 --- a/crates/nu-command/src/debug/ast.rs +++ b/crates/nu-command/src/debug/ast.rs @@ -16,7 +16,7 @@ impl Command for Ast { fn signature(&self) -> Signature { Signature::build("ast") - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) .required( "pipeline", SyntaxShape::String, diff --git a/crates/nu-command/src/debug/info.rs b/crates/nu-command/src/debug/info.rs index 287bcdb5ec..711fd58c16 100644 --- a/crates/nu-command/src/debug/info.rs +++ b/crates/nu-command/src/debug/info.rs @@ -31,7 +31,7 @@ impl Command for DebugInfo { fn signature(&self) -> nu_protocol::Signature { Signature::build("debug info") - .input_output_types(vec![(Type::Nothing, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::record())]) .category(Category::Debug) } diff --git a/crates/nu-command/src/debug/metadata.rs b/crates/nu-command/src/debug/metadata.rs index d8856605e5..135047a3d9 100644 --- a/crates/nu-command/src/debug/metadata.rs +++ b/crates/nu-command/src/debug/metadata.rs @@ -18,7 +18,7 @@ impl Command for Metadata { fn signature(&self) -> nu_protocol::Signature { Signature::build("metadata") - .input_output_types(vec![(Type::Any, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Any, Type::record())]) .allow_variants_without_examples(true) .optional( "expression", diff --git a/crates/nu-command/src/debug/profile.rs b/crates/nu-command/src/debug/profile.rs index 28a331be41..bd5de6041a 100644 --- a/crates/nu-command/src/debug/profile.rs +++ b/crates/nu-command/src/debug/profile.rs @@ -34,7 +34,7 @@ impl Command for DebugProfile { "How many blocks/closures deep to step into (default 2)", Some('m'), ) - .input_output_types(vec![(Type::Any, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Any, Type::table())]) .category(Category::Debug) } diff --git a/crates/nu-command/src/debug/view_files.rs b/crates/nu-command/src/debug/view_files.rs index 4ddacb2237..4f4effc6f2 100644 --- a/crates/nu-command/src/debug/view_files.rs +++ b/crates/nu-command/src/debug/view_files.rs @@ -20,12 +20,15 @@ impl Command for ViewFiles { Signature::build("view files") .input_output_types(vec![( Type::Nothing, - Type::Table(vec![ - ("filename".into(), Type::String), - ("start".into(), Type::Int), - ("end".into(), Type::Int), - ("size".into(), Type::Int), - ]), + Type::Table( + [ + ("filename".into(), Type::String), + ("start".into(), Type::Int), + ("end".into(), Type::Int), + ("size".into(), Type::Int), + ] + .into(), + ), )]) .category(Category::Debug) } diff --git a/crates/nu-command/src/env/load_env.rs b/crates/nu-command/src/env/load_env.rs index a8a4fe1c47..38311430ef 100644 --- a/crates/nu-command/src/env/load_env.rs +++ b/crates/nu-command/src/env/load_env.rs @@ -15,7 +15,7 @@ impl Command for LoadEnv { fn signature(&self) -> nu_protocol::Signature { Signature::build("load-env") .input_output_types(vec![ - (Type::Record(vec![]), Type::Nothing), + (Type::record(), Type::Nothing), (Type::Nothing, Type::Nothing), ]) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/filesystem/du.rs b/crates/nu-command/src/filesystem/du.rs index 5035c75b7b..410f57bd2a 100644 --- a/crates/nu-command/src/filesystem/du.rs +++ b/crates/nu-command/src/filesystem/du.rs @@ -33,7 +33,7 @@ impl Command for Du { fn signature(&self) -> Signature { Signature::build("du") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) .rest( "path", diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index a8cddee37a..8985cd2649 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -45,7 +45,7 @@ impl Command for Ls { fn signature(&self) -> nu_protocol::Signature { Signature::build("ls") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) // LsGlobPattern is similar to string, it won't auto-expand // and we use it to track if the user input is quoted. .rest("pattern", SyntaxShape::OneOf(vec![SyntaxShape::GlobPattern, SyntaxShape::String]), "The glob pattern to use.") diff --git a/crates/nu-command/src/filesystem/watch.rs b/crates/nu-command/src/filesystem/watch.rs index 9566d71294..91837ad5cb 100644 --- a/crates/nu-command/src/filesystem/watch.rs +++ b/crates/nu-command/src/filesystem/watch.rs @@ -38,7 +38,7 @@ impl Command for Watch { fn signature(&self) -> nu_protocol::Signature { Signature::build("watch") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required("path", SyntaxShape::Filepath, "The path to watch. Can be a file or directory.") .required("closure", SyntaxShape::Closure(Some(vec![SyntaxShape::String, SyntaxShape::String, SyntaxShape::String])), diff --git a/crates/nu-command/src/filters/columns.rs b/crates/nu-command/src/filters/columns.rs index 394370a644..a5b0f2b9ea 100644 --- a/crates/nu-command/src/filters/columns.rs +++ b/crates/nu-command/src/filters/columns.rs @@ -11,8 +11,8 @@ impl Command for Columns { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::List(Box::new(Type::String))), - (Type::Record(vec![]), Type::List(Box::new(Type::String))), + (Type::table(), Type::List(Box::new(Type::String))), + (Type::record(), Type::List(Box::new(Type::String))), ]) .category(Category::Filters) } diff --git a/crates/nu-command/src/filters/drop/column.rs b/crates/nu-command/src/filters/drop/column.rs index a19190cbd6..3f527bcc14 100644 --- a/crates/nu-command/src/filters/drop/column.rs +++ b/crates/nu-command/src/filters/drop/column.rs @@ -13,8 +13,8 @@ impl Command for DropColumn { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .optional( "columns", diff --git a/crates/nu-command/src/filters/drop/drop_.rs b/crates/nu-command/src/filters/drop/drop_.rs index 9498cede71..ba78058261 100644 --- a/crates/nu-command/src/filters/drop/drop_.rs +++ b/crates/nu-command/src/filters/drop/drop_.rs @@ -11,7 +11,7 @@ impl Command for Drop { fn signature(&self) -> Signature { Signature::build("drop") .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/each.rs b/crates/nu-command/src/filters/each.rs index 5980ed28b3..cbf89c805c 100644 --- a/crates/nu-command/src/filters/each.rs +++ b/crates/nu-command/src/filters/each.rs @@ -35,7 +35,7 @@ with 'transpose' first."# Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), ), - (Type::Table(vec![]), Type::List(Box::new(Type::Any))), + (Type::table(), Type::List(Box::new(Type::Any))), (Type::Any, Type::Any), ]) .required( diff --git a/crates/nu-command/src/filters/enumerate.rs b/crates/nu-command/src/filters/enumerate.rs index e2e8d103eb..e46c873c4b 100644 --- a/crates/nu-command/src/filters/enumerate.rs +++ b/crates/nu-command/src/filters/enumerate.rs @@ -18,7 +18,7 @@ impl Command for Enumerate { fn signature(&self) -> nu_protocol::Signature { Signature::build("enumerate") - .input_output_types(vec![(Type::Any, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Any, Type::table())]) .category(Category::Filters) } diff --git a/crates/nu-command/src/filters/flatten.rs b/crates/nu-command/src/filters/flatten.rs index 073e84368d..ec86677af4 100644 --- a/crates/nu-command/src/filters/flatten.rs +++ b/crates/nu-command/src/filters/flatten.rs @@ -17,7 +17,7 @@ impl Command for Flatten { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), ), - (Type::Record(vec![]), Type::Table(vec![])), + (Type::record(), Type::table()), ]) .rest( "rest", diff --git a/crates/nu-command/src/filters/get.rs b/crates/nu-command/src/filters/get.rs index 14d5169d25..5772ec2f11 100644 --- a/crates/nu-command/src/filters/get.rs +++ b/crates/nu-command/src/filters/get.rs @@ -27,8 +27,8 @@ If multiple cell paths are given, this will produce a list of values."# Type::List(Box::new(Type::Any)), Type::Any, ), - (Type::Table(vec![]), Type::Any), - (Type::Record(vec![]), Type::Any), + (Type::table(), Type::Any), + (Type::record(), Type::Any), ]) .required( "cell_path", diff --git a/crates/nu-command/src/filters/headers.rs b/crates/nu-command/src/filters/headers.rs index f84f49b4be..d7492d0b76 100644 --- a/crates/nu-command/src/filters/headers.rs +++ b/crates/nu-command/src/filters/headers.rs @@ -12,11 +12,11 @@ impl Command for Headers { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( // Tables with missing values are List Type::List(Box::new(Type::Any)), - Type::Table(vec![]), + Type::table(), ), ]) .category(Category::Filters) diff --git a/crates/nu-command/src/filters/insert.rs b/crates/nu-command/src/filters/insert.rs index 6013a0377a..7814bcdb83 100644 --- a/crates/nu-command/src/filters/insert.rs +++ b/crates/nu-command/src/filters/insert.rs @@ -12,8 +12,8 @@ impl Command for Insert { fn signature(&self) -> Signature { Signature::build("insert") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/items.rs b/crates/nu-command/src/filters/items.rs index 38d8305a41..8dca421200 100644 --- a/crates/nu-command/src/filters/items.rs +++ b/crates/nu-command/src/filters/items.rs @@ -12,7 +12,7 @@ impl Command for Items { fn signature(&self) -> Signature { Signature::build(self.name()) - .input_output_types(vec![(Type::Record(vec![]), Type::Any)]) + .input_output_types(vec![(Type::record(), Type::Any)]) .required( "closure", SyntaxShape::Closure(Some(vec![SyntaxShape::Any, SyntaxShape::Any])), diff --git a/crates/nu-command/src/filters/join.rs b/crates/nu-command/src/filters/join.rs index c1e90e9023..343cc0eb19 100644 --- a/crates/nu-command/src/filters/join.rs +++ b/crates/nu-command/src/filters/join.rs @@ -46,7 +46,7 @@ impl Command for Join { .switch("left", "Left-outer join", Some('l')) .switch("right", "Right-outer join", Some('r')) .switch("outer", "Outer join", Some('o')) - .input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))]) + .input_output_types(vec![(Type::table(), Type::table())]) .category(Category::Filters) } diff --git a/crates/nu-command/src/filters/merge.rs b/crates/nu-command/src/filters/merge.rs index 157594b6e7..5af331bf0c 100644 --- a/crates/nu-command/src/filters/merge.rs +++ b/crates/nu-command/src/filters/merge.rs @@ -23,8 +23,8 @@ repeating this process with row 1, and so on."# fn signature(&self) -> nu_protocol::Signature { Signature::build("merge") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ]) .required( "value", diff --git a/crates/nu-command/src/filters/move_.rs b/crates/nu-command/src/filters/move_.rs index d4317e1c39..ab2f8c55cd 100644 --- a/crates/nu-command/src/filters/move_.rs +++ b/crates/nu-command/src/filters/move_.rs @@ -21,8 +21,8 @@ impl Command for Move { fn signature(&self) -> nu_protocol::Signature { Signature::build("move") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ]) .rest("columns", SyntaxShape::String, "The columns to move.") .named( diff --git a/crates/nu-command/src/filters/par_each.rs b/crates/nu-command/src/filters/par_each.rs index e556eb0923..4f0a07b300 100644 --- a/crates/nu-command/src/filters/par_each.rs +++ b/crates/nu-command/src/filters/par_each.rs @@ -22,7 +22,7 @@ impl Command for ParEach { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), ), - (Type::Table(vec![]), Type::List(Box::new(Type::Any))), + (Type::table(), Type::List(Box::new(Type::Any))), (Type::Any, Type::Any), ]) .named( diff --git a/crates/nu-command/src/filters/reduce.rs b/crates/nu-command/src/filters/reduce.rs index deb1e92bc6..756fe051a9 100644 --- a/crates/nu-command/src/filters/reduce.rs +++ b/crates/nu-command/src/filters/reduce.rs @@ -13,7 +13,7 @@ impl Command for Reduce { Signature::build("reduce") .input_output_types(vec![ (Type::List(Box::new(Type::Any)), Type::Any), - (Type::Table(vec![]), Type::Any), + (Type::table(), Type::Any), (Type::Range, Type::Any), ]) .named( diff --git a/crates/nu-command/src/filters/reject.rs b/crates/nu-command/src/filters/reject.rs index 23f36ec172..251e92c905 100644 --- a/crates/nu-command/src/filters/reject.rs +++ b/crates/nu-command/src/filters/reject.rs @@ -13,8 +13,8 @@ impl Command for Reject { fn signature(&self) -> Signature { Signature::build("reject") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ]) .switch( "ignore-errors", diff --git a/crates/nu-command/src/filters/rename.rs b/crates/nu-command/src/filters/rename.rs index 53920a95d0..b803bd8567 100644 --- a/crates/nu-command/src/filters/rename.rs +++ b/crates/nu-command/src/filters/rename.rs @@ -13,8 +13,8 @@ impl Command for Rename { fn signature(&self) -> Signature { Signature::build("rename") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ]) .named( "column", diff --git a/crates/nu-command/src/filters/select.rs b/crates/nu-command/src/filters/select.rs index 916a4e8e5e..5b8e9e0420 100644 --- a/crates/nu-command/src/filters/select.rs +++ b/crates/nu-command/src/filters/select.rs @@ -14,8 +14,8 @@ impl Command for Select { fn signature(&self) -> Signature { Signature::build("select") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), (Type::List(Box::new(Type::Any)), Type::Any), ]) .switch( diff --git a/crates/nu-command/src/filters/skip/skip_.rs b/crates/nu-command/src/filters/skip/skip_.rs index 4dc54096a0..a76e2b706d 100644 --- a/crates/nu-command/src/filters/skip/skip_.rs +++ b/crates/nu-command/src/filters/skip/skip_.rs @@ -11,7 +11,7 @@ impl Command for Skip { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/skip/skip_until.rs b/crates/nu-command/src/filters/skip/skip_until.rs index 98670e38fc..b0a4dd4cd9 100644 --- a/crates/nu-command/src/filters/skip/skip_until.rs +++ b/crates/nu-command/src/filters/skip/skip_until.rs @@ -12,7 +12,7 @@ impl Command for SkipUntil { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/skip/skip_while.rs b/crates/nu-command/src/filters/skip/skip_while.rs index cb1a940b1e..d72bbcd6fc 100644 --- a/crates/nu-command/src/filters/skip/skip_while.rs +++ b/crates/nu-command/src/filters/skip/skip_while.rs @@ -12,7 +12,7 @@ impl Command for SkipWhile { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/sort.rs b/crates/nu-command/src/filters/sort.rs index 451f4bdcef..cc9a72546d 100644 --- a/crates/nu-command/src/filters/sort.rs +++ b/crates/nu-command/src/filters/sort.rs @@ -17,7 +17,7 @@ impl Command for Sort { .input_output_types(vec![( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), - ), (Type::Record(vec![]), Type::Record(vec![])),]) + ), (Type::record(), Type::record()),]) .switch("reverse", "Sort in reverse order", Some('r')) .switch( "ignore-case", diff --git a/crates/nu-command/src/filters/sort_by.rs b/crates/nu-command/src/filters/sort_by.rs index 5c0d173945..66c1f2b03f 100644 --- a/crates/nu-command/src/filters/sort_by.rs +++ b/crates/nu-command/src/filters/sort_by.rs @@ -15,8 +15,8 @@ impl Command for SortBy { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), ), - (Type::Record(vec![]), Type::Table(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::table()), + (Type::table(), Type::table()), ]) .rest("columns", SyntaxShape::Any, "The column(s) to sort by.") .switch("reverse", "Sort in reverse order", Some('r')) diff --git a/crates/nu-command/src/filters/split_by.rs b/crates/nu-command/src/filters/split_by.rs index 349c7ec49b..0d3bf1cd30 100644 --- a/crates/nu-command/src/filters/split_by.rs +++ b/crates/nu-command/src/filters/split_by.rs @@ -11,7 +11,7 @@ impl Command for SplitBy { fn signature(&self) -> Signature { Signature::build("split-by") - .input_output_types(vec![(Type::Record(vec![]), Type::Record(vec![]))]) + .input_output_types(vec![(Type::record(), Type::record())]) .optional("splitter", SyntaxShape::Any, "The splitter value to use.") .category(Category::Filters) } diff --git a/crates/nu-command/src/filters/take/take_.rs b/crates/nu-command/src/filters/take/take_.rs index dc092c9779..a5ffe25301 100644 --- a/crates/nu-command/src/filters/take/take_.rs +++ b/crates/nu-command/src/filters/take/take_.rs @@ -11,7 +11,7 @@ impl Command for Take { fn signature(&self) -> Signature { Signature::build("take") .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/take/take_until.rs b/crates/nu-command/src/filters/take/take_until.rs index 035060091b..40d2eee019 100644 --- a/crates/nu-command/src/filters/take/take_until.rs +++ b/crates/nu-command/src/filters/take/take_until.rs @@ -12,7 +12,7 @@ impl Command for TakeUntil { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/take/take_while.rs b/crates/nu-command/src/filters/take/take_while.rs index 45a701073c..1d2a98ee51 100644 --- a/crates/nu-command/src/filters/take/take_while.rs +++ b/crates/nu-command/src/filters/take/take_while.rs @@ -12,7 +12,7 @@ impl Command for TakeWhile { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/transpose.rs b/crates/nu-command/src/filters/transpose.rs index b69f1d7240..9a41457a8f 100644 --- a/crates/nu-command/src/filters/transpose.rs +++ b/crates/nu-command/src/filters/transpose.rs @@ -20,8 +20,8 @@ impl Command for Transpose { fn signature(&self) -> Signature { Signature::build("transpose") .input_output_types(vec![ - (Type::Table(vec![]), Type::Any), - (Type::Record(vec![]), Type::Table(vec![])), + (Type::table(), Type::Any), + (Type::record(), Type::table()), ]) .switch( "header-row", diff --git a/crates/nu-command/src/filters/uniq_by.rs b/crates/nu-command/src/filters/uniq_by.rs index d6b87bd065..7bbeb0afe2 100644 --- a/crates/nu-command/src/filters/uniq_by.rs +++ b/crates/nu-command/src/filters/uniq_by.rs @@ -12,7 +12,7 @@ impl Command for UniqBy { fn signature(&self) -> Signature { Signature::build("uniq-by") .input_output_types(vec![ - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/update.rs b/crates/nu-command/src/filters/update.rs index b1740a978e..76e0674ad8 100644 --- a/crates/nu-command/src/filters/update.rs +++ b/crates/nu-command/src/filters/update.rs @@ -12,8 +12,8 @@ impl Command for Update { fn signature(&self) -> Signature { Signature::build("update") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/upsert.rs b/crates/nu-command/src/filters/upsert.rs index 12cf63ccf3..e62239f562 100644 --- a/crates/nu-command/src/filters/upsert.rs +++ b/crates/nu-command/src/filters/upsert.rs @@ -12,8 +12,8 @@ impl Command for Upsert { fn signature(&self) -> Signature { Signature::build("upsert") .input_output_types(vec![ - (Type::Record(vec![]), Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::record(), Type::record()), + (Type::table(), Type::table()), ( Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), diff --git a/crates/nu-command/src/filters/values.rs b/crates/nu-command/src/filters/values.rs index 691e260163..344ffc96c0 100644 --- a/crates/nu-command/src/filters/values.rs +++ b/crates/nu-command/src/filters/values.rs @@ -12,8 +12,8 @@ impl Command for Values { fn signature(&self) -> Signature { Signature::build(self.name()) .input_output_types(vec![ - (Type::Record(vec![]), Type::List(Box::new(Type::Any))), - (Type::Table(vec![]), Type::List(Box::new(Type::Any))), + (Type::record(), Type::List(Box::new(Type::Any))), + (Type::table(), Type::List(Box::new(Type::Any))), ]) .category(Category::Filters) } diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 2285de55d8..cb35bd8876 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -26,7 +26,7 @@ not supported."# Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::Any)), ), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), (Type::Range, Type::Any), ]) .required( diff --git a/crates/nu-command/src/filters/wrap.rs b/crates/nu-command/src/filters/wrap.rs index 0954751f71..a5ccf9eed2 100644 --- a/crates/nu-command/src/filters/wrap.rs +++ b/crates/nu-command/src/filters/wrap.rs @@ -15,9 +15,9 @@ impl Command for Wrap { fn signature(&self) -> nu_protocol::Signature { Signature::build("wrap") .input_output_types(vec![ - (Type::List(Box::new(Type::Any)), Type::Table(vec![])), - (Type::Range, Type::Table(vec![])), - (Type::Any, Type::Record(vec![])), + (Type::List(Box::new(Type::Any)), Type::table()), + (Type::Range, Type::table()), + (Type::Any, Type::record()), ]) .required("name", SyntaxShape::String, "The name of the column.") .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/formats/from/csv.rs b/crates/nu-command/src/formats/from/csv.rs index a05d3e43f6..b00dd5022b 100644 --- a/crates/nu-command/src/formats/from/csv.rs +++ b/crates/nu-command/src/formats/from/csv.rs @@ -11,7 +11,7 @@ impl Command for FromCsv { fn signature(&self) -> Signature { Signature::build("from csv") - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .named( "separator", SyntaxShape::String, diff --git a/crates/nu-command/src/formats/from/ods.rs b/crates/nu-command/src/formats/from/ods.rs index 7e716c4493..fff9e98be6 100644 --- a/crates/nu-command/src/formats/from/ods.rs +++ b/crates/nu-command/src/formats/from/ods.rs @@ -14,7 +14,7 @@ impl Command for FromOds { fn signature(&self) -> Signature { Signature::build("from ods") - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .allow_variants_without_examples(true) .named( "sheets", diff --git a/crates/nu-command/src/formats/from/ssv.rs b/crates/nu-command/src/formats/from/ssv.rs index 0380f66e2f..5efb2a6c3b 100644 --- a/crates/nu-command/src/formats/from/ssv.rs +++ b/crates/nu-command/src/formats/from/ssv.rs @@ -13,7 +13,7 @@ impl Command for FromSsv { fn signature(&self) -> Signature { Signature::build("from ssv") - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .switch( "noheaders", "don't treat the first row as column names", diff --git a/crates/nu-command/src/formats/from/toml.rs b/crates/nu-command/src/formats/from/toml.rs index 46877d1dac..e1ddca3164 100644 --- a/crates/nu-command/src/formats/from/toml.rs +++ b/crates/nu-command/src/formats/from/toml.rs @@ -11,7 +11,7 @@ impl Command for FromToml { fn signature(&self) -> Signature { Signature::build("from toml") - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) .category(Category::Formats) } diff --git a/crates/nu-command/src/formats/from/tsv.rs b/crates/nu-command/src/formats/from/tsv.rs index 5cbaeb9456..ea507ab1c7 100644 --- a/crates/nu-command/src/formats/from/tsv.rs +++ b/crates/nu-command/src/formats/from/tsv.rs @@ -11,7 +11,7 @@ impl Command for FromTsv { fn signature(&self) -> Signature { Signature::build("from tsv") - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .named( "comment", SyntaxShape::String, diff --git a/crates/nu-command/src/formats/from/xlsx.rs b/crates/nu-command/src/formats/from/xlsx.rs index d5fb0bfb68..b54cffe3aa 100644 --- a/crates/nu-command/src/formats/from/xlsx.rs +++ b/crates/nu-command/src/formats/from/xlsx.rs @@ -15,7 +15,7 @@ impl Command for FromXlsx { fn signature(&self) -> Signature { Signature::build("from xlsx") - .input_output_types(vec![(Type::Binary, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Binary, Type::table())]) .allow_variants_without_examples(true) .named( "sheets", diff --git a/crates/nu-command/src/formats/from/xml.rs b/crates/nu-command/src/formats/from/xml.rs index 3443bf0309..5ac94051f6 100644 --- a/crates/nu-command/src/formats/from/xml.rs +++ b/crates/nu-command/src/formats/from/xml.rs @@ -14,7 +14,7 @@ impl Command for FromXml { fn signature(&self) -> Signature { Signature::build("from xml") - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) .switch("keep-comments", "add comment nodes to result", None) .switch( "keep-pi", diff --git a/crates/nu-command/src/formats/to/csv.rs b/crates/nu-command/src/formats/to/csv.rs index a3528080df..173c6fbd6b 100644 --- a/crates/nu-command/src/formats/to/csv.rs +++ b/crates/nu-command/src/formats/to/csv.rs @@ -13,8 +13,8 @@ impl Command for ToCsv { fn signature(&self) -> Signature { Signature::build("to csv") .input_output_types(vec![ - (Type::Record(vec![]), Type::String), - (Type::Table(vec![]), Type::String), + (Type::record(), Type::String), + (Type::table(), Type::String), ]) .named( "separator", diff --git a/crates/nu-command/src/formats/to/toml.rs b/crates/nu-command/src/formats/to/toml.rs index 497297885d..adfdf7f39a 100644 --- a/crates/nu-command/src/formats/to/toml.rs +++ b/crates/nu-command/src/formats/to/toml.rs @@ -12,7 +12,7 @@ impl Command for ToToml { fn signature(&self) -> Signature { Signature::build("to toml") - .input_output_types(vec![(Type::Record(vec![]), Type::String)]) + .input_output_types(vec![(Type::record(), Type::String)]) .category(Category::Formats) } diff --git a/crates/nu-command/src/formats/to/tsv.rs b/crates/nu-command/src/formats/to/tsv.rs index 2bed2935d9..eeaeb6b401 100644 --- a/crates/nu-command/src/formats/to/tsv.rs +++ b/crates/nu-command/src/formats/to/tsv.rs @@ -13,8 +13,8 @@ impl Command for ToTsv { fn signature(&self) -> Signature { Signature::build("to tsv") .input_output_types(vec![ - (Type::Record(vec![]), Type::String), - (Type::Table(vec![]), Type::String), + (Type::record(), Type::String), + (Type::table(), Type::String), ]) .switch( "noheaders", diff --git a/crates/nu-command/src/formats/to/xml.rs b/crates/nu-command/src/formats/to/xml.rs index f93bc94d28..2cfec24470 100644 --- a/crates/nu-command/src/formats/to/xml.rs +++ b/crates/nu-command/src/formats/to/xml.rs @@ -18,7 +18,7 @@ impl Command for ToXml { fn signature(&self) -> Signature { Signature::build("to xml") - .input_output_types(vec![(Type::Record(vec![]), Type::String)]) + .input_output_types(vec![(Type::record(), Type::String)]) .named( "indent", SyntaxShape::Int, @@ -300,7 +300,7 @@ impl Job { if top_level { return Err(ShellError::CantConvert { to_type: "XML".into(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: entry_span, help: Some("PIs can not be a root element of document".into()), }); @@ -312,7 +312,7 @@ impl Job { _ => { return Err(ShellError::CantConvert { to_type: "XML".into(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: content.span(), help: Some("PI content expected to be a string".into()), }); @@ -369,7 +369,7 @@ impl Job { .write_event(Event::Comment(comment_content)) .map_err(|_| ShellError::CantConvert { to_type: "XML".to_string(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: entry_span, help: Some("Failure writing comment to xml".into()), }) @@ -393,7 +393,7 @@ impl Job { if !matches!(attrs, Value::Nothing { .. }) { return Err(ShellError::CantConvert { to_type: "XML".into(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: entry_span, help: Some("PIs do not have attributes".into()), }); @@ -408,7 +408,7 @@ impl Job { .write_event(Event::PI(pi_content)) .map_err(|_| ShellError::CantConvert { to_type: "XML".to_string(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: entry_span, help: Some("Failure writing PI to xml".into()), }) @@ -425,7 +425,7 @@ impl Job { if tag.starts_with('!') || tag.starts_with('?') { return Err(ShellError::CantConvert { to_type: "XML".to_string(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: tag_span, help: Some(format!( "Incorrect tag name {}, tag name can not start with ! or ?", @@ -448,7 +448,7 @@ impl Job { .write_event(open_tag_event) .map_err(|_| ShellError::CantConvert { to_type: "XML".to_string(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: entry_span, help: Some("Failure writing tag to xml".into()), })?; @@ -463,7 +463,7 @@ impl Job { .write_event(close_tag_event) .map_err(|_| ShellError::CantConvert { to_type: "XML".to_string(), - from_type: Type::Record(vec![]).to_string(), + from_type: Type::record().to_string(), span: entry_span, help: Some("Failure writing tag to xml".into()), })?; diff --git a/crates/nu-command/src/generators/cal.rs b/crates/nu-command/src/generators/cal.rs index cc7285ac48..e1ecc771de 100644 --- a/crates/nu-command/src/generators/cal.rs +++ b/crates/nu-command/src/generators/cal.rs @@ -43,7 +43,7 @@ impl Command for Cal { "Display the month names instead of integers", None, ) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) // TODO: supply exhaustive examples .category(Category::Generators) } diff --git a/crates/nu-command/src/hash/generic_digest.rs b/crates/nu-command/src/hash/generic_digest.rs index d262a4ca73..476915f07d 100644 --- a/crates/nu-command/src/hash/generic_digest.rs +++ b/crates/nu-command/src/hash/generic_digest.rs @@ -50,8 +50,8 @@ where .category(Category::Hash) .input_output_types(vec![ (Type::String, Type::Any), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .switch( diff --git a/crates/nu-command/src/help/help_aliases.rs b/crates/nu-command/src/help/help_aliases.rs index ccd1f9d7e2..f97084bb51 100644 --- a/crates/nu-command/src/help/help_aliases.rs +++ b/crates/nu-command/src/help/help_aliases.rs @@ -29,7 +29,7 @@ impl Command for HelpAliases { "string to find in alias names and usage", Some('f'), ) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) } diff --git a/crates/nu-command/src/help/help_commands.rs b/crates/nu-command/src/help/help_commands.rs index 79ae5ce49b..128c838efd 100644 --- a/crates/nu-command/src/help/help_commands.rs +++ b/crates/nu-command/src/help/help_commands.rs @@ -29,7 +29,7 @@ impl Command for HelpCommands { "string to find in command names, usage, and search terms", Some('f'), ) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) } diff --git a/crates/nu-command/src/help/help_escapes.rs b/crates/nu-command/src/help/help_escapes.rs index fe0792c4bc..73a83f1175 100644 --- a/crates/nu-command/src/help/help_escapes.rs +++ b/crates/nu-command/src/help/help_escapes.rs @@ -15,7 +15,7 @@ impl Command for HelpEscapes { fn signature(&self) -> Signature { Signature::build("help escapes") .category(Category::Core) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) } diff --git a/crates/nu-command/src/help/help_externs.rs b/crates/nu-command/src/help/help_externs.rs index 8f42d81948..3aad5b27fe 100644 --- a/crates/nu-command/src/help/help_externs.rs +++ b/crates/nu-command/src/help/help_externs.rs @@ -29,7 +29,7 @@ impl Command for HelpExterns { "string to find in extern names and usage", Some('f'), ) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) } diff --git a/crates/nu-command/src/help/help_modules.rs b/crates/nu-command/src/help/help_modules.rs index 26e65d6ba3..e51b52154b 100644 --- a/crates/nu-command/src/help/help_modules.rs +++ b/crates/nu-command/src/help/help_modules.rs @@ -35,7 +35,7 @@ are also available in the current scope. Commands/aliases that were imported und "string to find in module names and usage", Some('f'), ) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) } diff --git a/crates/nu-command/src/help/help_operators.rs b/crates/nu-command/src/help/help_operators.rs index b7286b9f49..72c9e752e9 100644 --- a/crates/nu-command/src/help/help_operators.rs +++ b/crates/nu-command/src/help/help_operators.rs @@ -15,7 +15,7 @@ impl Command for HelpOperators { fn signature(&self) -> Signature { Signature::build("help operators") .category(Category::Core) - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) } diff --git a/crates/nu-command/src/math/avg.rs b/crates/nu-command/src/math/avg.rs index 826e9334b2..8b1b1640f0 100644 --- a/crates/nu-command/src/math/avg.rs +++ b/crates/nu-command/src/math/avg.rs @@ -23,8 +23,8 @@ impl Command for SubCommand { (Type::List(Box::new(Type::Number)), Type::Number), (Type::Number, Type::Number), (Type::Range, Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/max.rs b/crates/nu-command/src/math/max.rs index 86932cb699..edda0526ed 100644 --- a/crates/nu-command/src/math/max.rs +++ b/crates/nu-command/src/math/max.rs @@ -20,8 +20,8 @@ impl Command for SubCommand { (Type::List(Box::new(Type::Filesize)), Type::Filesize), (Type::List(Box::new(Type::Any)), Type::Any), (Type::Range, Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/median.rs b/crates/nu-command/src/math/median.rs index c95f764082..32c4fd04a8 100644 --- a/crates/nu-command/src/math/median.rs +++ b/crates/nu-command/src/math/median.rs @@ -17,8 +17,8 @@ impl Command for SubCommand { (Type::List(Box::new(Type::Duration)), Type::Duration), (Type::List(Box::new(Type::Filesize)), Type::Filesize), (Type::Range, Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/min.rs b/crates/nu-command/src/math/min.rs index 3cd922cbc6..5c7d43d4d8 100644 --- a/crates/nu-command/src/math/min.rs +++ b/crates/nu-command/src/math/min.rs @@ -20,8 +20,8 @@ impl Command for SubCommand { (Type::List(Box::new(Type::Filesize)), Type::Filesize), (Type::List(Box::new(Type::Any)), Type::Any), (Type::Range, Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/mode.rs b/crates/nu-command/src/math/mode.rs index 3c1dc0d8c9..7ce87ad842 100644 --- a/crates/nu-command/src/math/mode.rs +++ b/crates/nu-command/src/math/mode.rs @@ -48,7 +48,7 @@ impl Command for SubCommand { Type::List(Box::new(Type::Filesize)), Type::List(Box::new(Type::Filesize)), ), - (Type::Table(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/product.rs b/crates/nu-command/src/math/product.rs index d88160a871..d42ede8150 100644 --- a/crates/nu-command/src/math/product.rs +++ b/crates/nu-command/src/math/product.rs @@ -17,8 +17,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::List(Box::new(Type::Number)), Type::Number), (Type::Range, Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/stddev.rs b/crates/nu-command/src/math/stddev.rs index a5d7482915..d200275aa9 100644 --- a/crates/nu-command/src/math/stddev.rs +++ b/crates/nu-command/src/math/stddev.rs @@ -14,8 +14,8 @@ impl Command for SubCommand { Signature::build("math stddev") .input_output_types(vec![ (Type::List(Box::new(Type::Number)), Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .switch( "sample", diff --git a/crates/nu-command/src/math/sum.rs b/crates/nu-command/src/math/sum.rs index a324d57a2a..9a8285c6c5 100644 --- a/crates/nu-command/src/math/sum.rs +++ b/crates/nu-command/src/math/sum.rs @@ -19,8 +19,8 @@ impl Command for SubCommand { (Type::List(Box::new(Type::Duration)), Type::Duration), (Type::List(Box::new(Type::Filesize)), Type::Filesize), (Type::Range, Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .category(Category::Math) diff --git a/crates/nu-command/src/math/variance.rs b/crates/nu-command/src/math/variance.rs index 6777aec0fa..a20a3f262a 100644 --- a/crates/nu-command/src/math/variance.rs +++ b/crates/nu-command/src/math/variance.rs @@ -13,8 +13,8 @@ impl Command for SubCommand { Signature::build("math variance") .input_output_types(vec![ (Type::List(Box::new(Type::Number)), Type::Number), - (Type::Table(vec![]), Type::Record(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::record()), + (Type::record(), Type::record()), ]) .switch( "sample", diff --git a/crates/nu-command/src/misc/panic.rs b/crates/nu-command/src/misc/panic.rs index a24809670b..cf1a5e053a 100644 --- a/crates/nu-command/src/misc/panic.rs +++ b/crates/nu-command/src/misc/panic.rs @@ -14,7 +14,7 @@ impl Command for Panic { fn signature(&self) -> nu_protocol::Signature { Signature::build("panic") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) // LsGlobPattern is similar to string, it won't auto-expand // and we use it to track if the user input is quoted. .optional("msg", SyntaxShape::String, "The glob pattern to use.") diff --git a/crates/nu-command/src/network/url/build_query.rs b/crates/nu-command/src/network/url/build_query.rs index 92b5057b60..dd50d9124f 100644 --- a/crates/nu-command/src/network/url/build_query.rs +++ b/crates/nu-command/src/network/url/build_query.rs @@ -11,8 +11,8 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("url build-query") .input_output_types(vec![ - (Type::Record(vec![]), Type::String), - (Type::Table(vec![]), Type::String), + (Type::record(), Type::String), + (Type::table(), Type::String), ]) .category(Category::Network) } diff --git a/crates/nu-command/src/network/url/decode.rs b/crates/nu-command/src/network/url/decode.rs index 1d95dba36e..8789eb13ca 100644 --- a/crates/nu-command/src/network/url/decode.rs +++ b/crates/nu-command/src/network/url/decode.rs @@ -19,8 +19,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/network/url/encode.rs b/crates/nu-command/src/network/url/encode.rs index 0673500228..845487963b 100644 --- a/crates/nu-command/src/network/url/encode.rs +++ b/crates/nu-command/src/network/url/encode.rs @@ -16,8 +16,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .switch( diff --git a/crates/nu-command/src/network/url/join.rs b/crates/nu-command/src/network/url/join.rs index eaa157ff2e..a2d6de8852 100644 --- a/crates/nu-command/src/network/url/join.rs +++ b/crates/nu-command/src/network/url/join.rs @@ -10,7 +10,7 @@ impl Command for SubCommand { fn signature(&self) -> nu_protocol::Signature { Signature::build("url join") - .input_output_types(vec![(Type::Record(vec![]), Type::String)]) + .input_output_types(vec![(Type::record(), Type::String)]) .category(Category::Network) } diff --git a/crates/nu-command/src/network/url/parse.rs b/crates/nu-command/src/network/url/parse.rs index f3b811e45d..8a80553eca 100644 --- a/crates/nu-command/src/network/url/parse.rs +++ b/crates/nu-command/src/network/url/parse.rs @@ -12,9 +12,9 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("url parse") .input_output_types(vec![ - (Type::String, Type::Record(vec![])), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::String, Type::record()), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/path/join.rs b/crates/nu-command/src/path/join.rs index fc424a7f0e..eb820606af 100644 --- a/crates/nu-command/src/path/join.rs +++ b/crates/nu-command/src/path/join.rs @@ -22,8 +22,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::String), - (Type::Record(vec![]), Type::String), - (Type::Table(vec![]), Type::List(Box::new(Type::String))), + (Type::record(), Type::String), + (Type::table(), Type::List(Box::new(Type::String))), ]) .rest( "append", diff --git a/crates/nu-command/src/path/parse.rs b/crates/nu-command/src/path/parse.rs index e1cebb2ec3..039f1012ed 100644 --- a/crates/nu-command/src/path/parse.rs +++ b/crates/nu-command/src/path/parse.rs @@ -20,8 +20,8 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("path parse") .input_output_types(vec![ - (Type::String, Type::Record(vec![])), - (Type::List(Box::new(Type::String)), Type::Table(vec![])), + (Type::String, Type::record()), + (Type::List(Box::new(Type::String)), Type::table()), ]) .named( "extension", diff --git a/crates/nu-command/src/platform/ansi/link.rs b/crates/nu-command/src/platform/ansi/link.rs index f6423ff0ec..68fc17977b 100644 --- a/crates/nu-command/src/platform/ansi/link.rs +++ b/crates/nu-command/src/platform/ansi/link.rs @@ -16,8 +16,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .named( "text", diff --git a/crates/nu-command/src/platform/ansi/strip.rs b/crates/nu-command/src/platform/ansi/strip.rs index ee64a3ebc1..35d410161c 100644 --- a/crates/nu-command/src/platform/ansi/strip.rs +++ b/crates/nu-command/src/platform/ansi/strip.rs @@ -26,8 +26,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .rest( "cell path", diff --git a/crates/nu-command/src/platform/input/input_listen.rs b/crates/nu-command/src/platform/input/input_listen.rs index 2514700137..3ab44f2e60 100644 --- a/crates/nu-command/src/platform/input/input_listen.rs +++ b/crates/nu-command/src/platform/input/input_listen.rs @@ -36,10 +36,10 @@ impl Command for InputListen { ) .input_output_types(vec![( Type::Nothing, - Type::Record(vec![ + Type::Record([ ("keycode".to_string(), Type::String), ("modifiers".to_string(), Type::List(Box::new(Type::String))), - ]), + ].into()), )]) } diff --git a/crates/nu-command/src/platform/term_size.rs b/crates/nu-command/src/platform/term_size.rs index 011ff2c7c2..6fad20eb41 100644 --- a/crates/nu-command/src/platform/term_size.rs +++ b/crates/nu-command/src/platform/term_size.rs @@ -18,10 +18,7 @@ impl Command for TermSize { .category(Category::Platform) .input_output_types(vec![( Type::Nothing, - Type::Record(vec![ - ("columns".into(), Type::Int), - ("rows".into(), Type::Int), - ]), + Type::Record([("columns".into(), Type::Int), ("rows".into(), Type::Int)].into()), )]) } diff --git a/crates/nu-command/src/stor/create.rs b/crates/nu-command/src/stor/create.rs index 3de6abd0fb..630718489b 100644 --- a/crates/nu-command/src/stor/create.rs +++ b/crates/nu-command/src/stor/create.rs @@ -11,7 +11,7 @@ impl Command for StorCreate { fn signature(&self) -> Signature { Signature::build("stor create") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required_named( "table-name", SyntaxShape::String, diff --git a/crates/nu-command/src/stor/delete.rs b/crates/nu-command/src/stor/delete.rs index 1a6e5b838f..4de4874140 100644 --- a/crates/nu-command/src/stor/delete.rs +++ b/crates/nu-command/src/stor/delete.rs @@ -11,7 +11,7 @@ impl Command for StorDelete { fn signature(&self) -> Signature { Signature::build("stor delete") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required_named( "table-name", SyntaxShape::String, diff --git a/crates/nu-command/src/stor/export.rs b/crates/nu-command/src/stor/export.rs index 7383fc6c8c..95c5ee9f35 100644 --- a/crates/nu-command/src/stor/export.rs +++ b/crates/nu-command/src/stor/export.rs @@ -11,7 +11,7 @@ impl Command for StorExport { fn signature(&self) -> Signature { Signature::build("stor export") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required_named( "file-name", SyntaxShape::String, diff --git a/crates/nu-command/src/stor/import.rs b/crates/nu-command/src/stor/import.rs index fa2aace858..682694e8bb 100644 --- a/crates/nu-command/src/stor/import.rs +++ b/crates/nu-command/src/stor/import.rs @@ -11,7 +11,7 @@ impl Command for StorImport { fn signature(&self) -> Signature { Signature::build("stor import") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required_named( "file-name", SyntaxShape::String, diff --git a/crates/nu-command/src/stor/insert.rs b/crates/nu-command/src/stor/insert.rs index 1b9f377531..2aeb076d44 100644 --- a/crates/nu-command/src/stor/insert.rs +++ b/crates/nu-command/src/stor/insert.rs @@ -11,7 +11,7 @@ impl Command for StorInsert { fn signature(&self) -> Signature { Signature::build("stor insert") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required_named( "table-name", SyntaxShape::String, diff --git a/crates/nu-command/src/stor/reset.rs b/crates/nu-command/src/stor/reset.rs index c1cb3b6b78..d4489fb702 100644 --- a/crates/nu-command/src/stor/reset.rs +++ b/crates/nu-command/src/stor/reset.rs @@ -11,7 +11,7 @@ impl Command for StorReset { fn signature(&self) -> Signature { Signature::build("stor reset") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) .category(Category::Database) } diff --git a/crates/nu-command/src/stor/update.rs b/crates/nu-command/src/stor/update.rs index dd49a36c47..d50614d67f 100644 --- a/crates/nu-command/src/stor/update.rs +++ b/crates/nu-command/src/stor/update.rs @@ -11,7 +11,7 @@ impl Command for StorUpdate { fn signature(&self) -> Signature { Signature::build("stor update") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .required_named( "table-name", SyntaxShape::String, diff --git a/crates/nu-command/src/strings/detect_columns.rs b/crates/nu-command/src/strings/detect_columns.rs index 1cd36ef0d4..9c33ffa494 100644 --- a/crates/nu-command/src/strings/detect_columns.rs +++ b/crates/nu-command/src/strings/detect_columns.rs @@ -21,7 +21,7 @@ impl Command for DetectColumns { "number of rows to skip before detecting", Some('s'), ) - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .switch("no-headers", "don't detect headers", Some('n')) .named( "combine-columns", diff --git a/crates/nu-command/src/strings/encode_decode/decode_base64.rs b/crates/nu-command/src/strings/encode_decode/decode_base64.rs index 3a8d17debb..242a99bb88 100644 --- a/crates/nu-command/src/strings/encode_decode/decode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/decode_base64.rs @@ -17,8 +17,8 @@ impl Command for DecodeBase64 { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Any)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .named( diff --git a/crates/nu-command/src/strings/encode_decode/encode_base64.rs b/crates/nu-command/src/strings/encode_decode/encode_base64.rs index 694c3210f3..04e1fcf6d1 100644 --- a/crates/nu-command/src/strings/encode_decode/encode_base64.rs +++ b/crates/nu-command/src/strings/encode_decode/encode_base64.rs @@ -28,8 +28,8 @@ impl Command for EncodeBase64 { Type::List(Box::new(Type::Any)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .named( diff --git a/crates/nu-command/src/strings/format/date.rs b/crates/nu-command/src/strings/format/date.rs index a85e62c679..2c82eb7541 100644 --- a/crates/nu-command/src/strings/format/date.rs +++ b/crates/nu-command/src/strings/format/date.rs @@ -18,7 +18,7 @@ impl Command for FormatDate { .input_output_types(vec![ (Type::Date, Type::String), (Type::String, Type::String), - (Type::Nothing, Type::Table(vec![])), + (Type::Nothing, Type::table()), ]) .allow_variants_without_examples(true) // https://github.com/nushell/nushell/issues/7032 .switch("list", "lists strftime cheatsheet", Some('l')) diff --git a/crates/nu-command/src/strings/format/duration.rs b/crates/nu-command/src/strings/format/duration.rs index d95d155978..ad6583cec0 100644 --- a/crates/nu-command/src/strings/format/duration.rs +++ b/crates/nu-command/src/strings/format/duration.rs @@ -29,7 +29,7 @@ impl Command for FormatDuration { Type::List(Box::new(Type::Duration)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), + (Type::table(), Type::table()), ]) .allow_variants_without_examples(true) .required( diff --git a/crates/nu-command/src/strings/format/filesize.rs b/crates/nu-command/src/strings/format/filesize.rs index 97a9cad4da..b54dc92f6d 100644 --- a/crates/nu-command/src/strings/format/filesize.rs +++ b/crates/nu-command/src/strings/format/filesize.rs @@ -25,8 +25,8 @@ impl Command for FormatFilesize { Signature::build("format filesize") .input_output_types(vec![ (Type::Filesize, Type::String), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required( diff --git a/crates/nu-command/src/strings/parse.rs b/crates/nu-command/src/strings/parse.rs index 1ea2dfcd0f..658fc20361 100644 --- a/crates/nu-command/src/strings/parse.rs +++ b/crates/nu-command/src/strings/parse.rs @@ -26,8 +26,8 @@ impl Command for Parse { Signature::build("parse") .required("pattern", SyntaxShape::String, "The pattern to match.") .input_output_types(vec![ - (Type::String, Type::Table(vec![])), - (Type::List(Box::new(Type::Any)), Type::Table(vec![])), + (Type::String, Type::table()), + (Type::List(Box::new(Type::Any)), Type::table()), ]) .switch("regex", "use full regex syntax for patterns", Some('r')) .allow_variants_without_examples(true) diff --git a/crates/nu-command/src/strings/split/column.rs b/crates/nu-command/src/strings/split/column.rs index 9b45e35e08..d73243322d 100644 --- a/crates/nu-command/src/strings/split/column.rs +++ b/crates/nu-command/src/strings/split/column.rs @@ -13,11 +13,11 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("split column") .input_output_types(vec![ - (Type::String, Type::Table(vec![])), + (Type::String, Type::table()), ( // TODO: no test coverage (is this behavior a bug or a feature?) Type::List(Box::new(Type::String)), - Type::Table(vec![]), + Type::table(), ), ]) .required( diff --git a/crates/nu-command/src/strings/str_/case/capitalize.rs b/crates/nu-command/src/strings/str_/case/capitalize.rs index 4cd9a78f6a..82f0d102e6 100644 --- a/crates/nu-command/src/strings/str_/case/capitalize.rs +++ b/crates/nu-command/src/strings/str_/case/capitalize.rs @@ -16,8 +16,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/strings/str_/case/downcase.rs b/crates/nu-command/src/strings/str_/case/downcase.rs index d87b48f913..7fa4785499 100644 --- a/crates/nu-command/src/strings/str_/case/downcase.rs +++ b/crates/nu-command/src/strings/str_/case/downcase.rs @@ -16,8 +16,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/strings/str_/case/upcase.rs b/crates/nu-command/src/strings/str_/case/upcase.rs index 2e6c7aca51..222c9eeab4 100644 --- a/crates/nu-command/src/strings/str_/case/upcase.rs +++ b/crates/nu-command/src/strings/str_/case/upcase.rs @@ -16,8 +16,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/strings/str_/contains.rs b/crates/nu-command/src/strings/str_/contains.rs index bea42ec198..abb0ce1a2b 100644 --- a/crates/nu-command/src/strings/str_/contains.rs +++ b/crates/nu-command/src/strings/str_/contains.rs @@ -29,8 +29,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Bool), // TODO figure out cell-path type behavior - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))) ]) .required("string", SyntaxShape::String, "The substring to find.") diff --git a/crates/nu-command/src/strings/str_/distance.rs b/crates/nu-command/src/strings/str_/distance.rs index 2b72454c7a..aa45ec5c25 100644 --- a/crates/nu-command/src/strings/str_/distance.rs +++ b/crates/nu-command/src/strings/str_/distance.rs @@ -25,8 +25,8 @@ impl Command for SubCommand { Signature::build("str distance") .input_output_types(vec![ (Type::String, Type::Int), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .required( "compare-string", diff --git a/crates/nu-command/src/strings/str_/ends_with.rs b/crates/nu-command/src/strings/str_/ends_with.rs index 5323bf6fcc..1b06acd880 100644 --- a/crates/nu-command/src/strings/str_/ends_with.rs +++ b/crates/nu-command/src/strings/str_/ends_with.rs @@ -28,8 +28,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Bool), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("string", SyntaxShape::String, "The string to match.") diff --git a/crates/nu-command/src/strings/str_/index_of.rs b/crates/nu-command/src/strings/str_/index_of.rs index 6f6807ef23..457713c2df 100644 --- a/crates/nu-command/src/strings/str_/index_of.rs +++ b/crates/nu-command/src/strings/str_/index_of.rs @@ -34,8 +34,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Int), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("string", SyntaxShape::String, "The string to find in the input.") diff --git a/crates/nu-command/src/strings/str_/length.rs b/crates/nu-command/src/strings/str_/length.rs index 7cfc9d98c1..6e2ae4182b 100644 --- a/crates/nu-command/src/strings/str_/length.rs +++ b/crates/nu-command/src/strings/str_/length.rs @@ -28,8 +28,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Int), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Int))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .switch( diff --git a/crates/nu-command/src/strings/str_/replace.rs b/crates/nu-command/src/strings/str_/replace.rs index e8a3290d4f..5d5863e70a 100644 --- a/crates/nu-command/src/strings/str_/replace.rs +++ b/crates/nu-command/src/strings/str_/replace.rs @@ -31,8 +31,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), // TODO: clarify behavior with cell-path-rest argument - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ( Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), diff --git a/crates/nu-command/src/strings/str_/reverse.rs b/crates/nu-command/src/strings/str_/reverse.rs index 6faa051746..becfd9be50 100644 --- a/crates/nu-command/src/strings/str_/reverse.rs +++ b/crates/nu-command/src/strings/str_/reverse.rs @@ -17,8 +17,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/strings/str_/starts_with.rs b/crates/nu-command/src/strings/str_/starts_with.rs index ec94204d73..73396911e2 100644 --- a/crates/nu-command/src/strings/str_/starts_with.rs +++ b/crates/nu-command/src/strings/str_/starts_with.rs @@ -29,8 +29,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::Bool), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::Bool))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .required("string", SyntaxShape::String, "The string to match.") diff --git a/crates/nu-command/src/strings/str_/stats.rs b/crates/nu-command/src/strings/str_/stats.rs index d362393e8e..20ef35c51f 100644 --- a/crates/nu-command/src/strings/str_/stats.rs +++ b/crates/nu-command/src/strings/str_/stats.rs @@ -18,7 +18,7 @@ impl Command for SubCommand { fn signature(&self) -> Signature { Signature::build("str stats") .category(Category::Strings) - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/strings/str_/substring.rs b/crates/nu-command/src/strings/str_/substring.rs index 8934a861e2..d137ce5c76 100644 --- a/crates/nu-command/src/strings/str_/substring.rs +++ b/crates/nu-command/src/strings/str_/substring.rs @@ -42,8 +42,8 @@ impl Command for SubCommand { .input_output_types(vec![ (Type::String, Type::String), (Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String))), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .switch( diff --git a/crates/nu-command/src/strings/str_/trim/trim_.rs b/crates/nu-command/src/strings/str_/trim/trim_.rs index 9d0b9530b3..ee414d0da6 100644 --- a/crates/nu-command/src/strings/str_/trim/trim_.rs +++ b/crates/nu-command/src/strings/str_/trim/trim_.rs @@ -36,8 +36,8 @@ impl Command for SubCommand { Type::List(Box::new(Type::String)), Type::List(Box::new(Type::String)), ), - (Type::Table(vec![]), Type::Table(vec![])), - (Type::Record(vec![]), Type::Record(vec![])), + (Type::table(), Type::table()), + (Type::record(), Type::record()), ]) .allow_variants_without_examples(true) .rest( diff --git a/crates/nu-command/src/system/complete.rs b/crates/nu-command/src/system/complete.rs index e12f65fb5a..80dae4d37a 100644 --- a/crates/nu-command/src/system/complete.rs +++ b/crates/nu-command/src/system/complete.rs @@ -13,7 +13,7 @@ impl Command for Complete { fn signature(&self) -> Signature { Signature::build("complete") .category(Category::System) - .input_output_types(vec![(Type::Any, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Any, Type::record())]) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/system/ps.rs b/crates/nu-command/src/system/ps.rs index 418aaf76ff..11eb66011d 100644 --- a/crates/nu-command/src/system/ps.rs +++ b/crates/nu-command/src/system/ps.rs @@ -23,7 +23,7 @@ impl Command for Ps { fn signature(&self) -> Signature { Signature::build("ps") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .switch( "long", "list all available columns for each entry", diff --git a/crates/nu-command/src/system/sys.rs b/crates/nu-command/src/system/sys.rs index 6c6d8b6bda..1fe41ac7c2 100644 --- a/crates/nu-command/src/system/sys.rs +++ b/crates/nu-command/src/system/sys.rs @@ -18,7 +18,7 @@ impl Command for Sys { Signature::build("sys") .filter() .category(Category::System) - .input_output_types(vec![(Type::Nothing, Type::Record(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::record())]) } fn usage(&self) -> &str { diff --git a/crates/nu-command/src/system/uname.rs b/crates/nu-command/src/system/uname.rs index ca576bd770..e267fcaeb2 100644 --- a/crates/nu-command/src/system/uname.rs +++ b/crates/nu-command/src/system/uname.rs @@ -16,7 +16,7 @@ impl Command for UName { fn signature(&self) -> Signature { Signature::build("uname") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .category(Category::System) } diff --git a/crates/nu-command/src/system/which_.rs b/crates/nu-command/src/system/which_.rs index 21ab7b0d9f..4e3e8c5786 100644 --- a/crates/nu-command/src/system/which_.rs +++ b/crates/nu-command/src/system/which_.rs @@ -12,7 +12,7 @@ impl Command for Which { fn signature(&self) -> Signature { Signature::build("which") - .input_output_types(vec![(Type::Nothing, Type::Table(vec![]))]) + .input_output_types(vec![(Type::Nothing, Type::table())]) .allow_variants_without_examples(true) .required("application", SyntaxShape::String, "Application.") .rest("rest", SyntaxShape::String, "Additional applications.") diff --git a/crates/nu-command/src/viewers/griddle.rs b/crates/nu-command/src/viewers/griddle.rs index afeb6ee0c4..2795ce646d 100644 --- a/crates/nu-command/src/viewers/griddle.rs +++ b/crates/nu-command/src/viewers/griddle.rs @@ -23,7 +23,7 @@ impl Command for Griddle { Signature::build("grid") .input_output_types(vec![ (Type::List(Box::new(Type::Any)), Type::String), - (Type::Record(vec![]), Type::String), + (Type::record(), Type::String), ]) .named( "width", diff --git a/crates/nu-engine/src/documentation.rs b/crates/nu-engine/src/documentation.rs index 463f8f10e7..2e966a312f 100644 --- a/crates/nu-engine/src/documentation.rs +++ b/crates/nu-engine/src/documentation.rs @@ -400,10 +400,13 @@ fn get_argument_for_color_value( Some(Argument::Positional(Expression { span: Span::unknown(), - ty: Type::Record(vec![ - ("fg".to_string(), Type::String), - ("attr".to_string(), Type::String), - ]), + ty: Type::Record( + [ + ("fg".to_string(), Type::String), + ("attr".to_string(), Type::String), + ] + .into(), + ), expr: Expr::Record(record_exp), custom_completion: None, })) diff --git a/crates/nu-parser/src/flatten.rs b/crates/nu-parser/src/flatten.rs index 9a5c0afcdd..0f99efb6fb 100644 --- a/crates/nu-parser/src/flatten.rs +++ b/crates/nu-parser/src/flatten.rs @@ -242,7 +242,7 @@ pub fn flatten_expression( } } - for arg in args { + for arg in args.as_ref() { //output.push((*arg, FlatShape::ExternalArg)); match arg { ExternalArgument::Regular(expr) => match expr { @@ -297,9 +297,9 @@ pub fn flatten_expression( output } - Expr::ValueWithUnit(x, unit) => { - let mut output = flatten_expression(working_set, x); - output.push((unit.span, FlatShape::String)); + Expr::ValueWithUnit(value) => { + let mut output = flatten_expression(working_set, &value.expr); + output.push((value.unit.span, FlatShape::String)); output } @@ -346,17 +346,17 @@ pub fn flatten_expression( Expr::Overlay(_) => { vec![(expr.span, FlatShape::String)] } - Expr::Range(from, next, to, op) => { + Expr::Range(range) => { let mut output = vec![]; - if let Some(f) = from { + if let Some(f) = &range.from { output.extend(flatten_expression(working_set, f)); } - if let Some(s) = next { - output.extend(vec![(op.next_op_span, FlatShape::Operator)]); + if let Some(s) = &range.next { + output.extend(vec![(range.operator.next_op_span, FlatShape::Operator)]); output.extend(flatten_expression(working_set, s)); } - output.extend(vec![(op.span, FlatShape::Operator)]); - if let Some(t) = to { + output.extend(vec![(range.operator.span, FlatShape::Operator)]); + if let Some(t) = &range.to { output.extend(flatten_expression(working_set, t)); } output @@ -495,9 +495,9 @@ pub fn flatten_expression( output } - Expr::Keyword(_, span, expr) => { - let mut output = vec![(*span, FlatShape::Keyword)]; - output.extend(flatten_expression(working_set, expr)); + Expr::Keyword(kw) => { + let mut output = vec![(kw.span, FlatShape::Keyword)]; + output.extend(flatten_expression(working_set, &kw.expr)); output } Expr::Operator(_) => { @@ -509,12 +509,12 @@ pub fn flatten_expression( Expr::String(_) => { vec![(expr.span, FlatShape::String)] } - Expr::Table(headers, cells) => { + Expr::Table(table) => { let outer_span = expr.span; let mut last_end = outer_span.start; let mut output = vec![]; - for e in headers { + for e in table.columns.as_ref() { let flattened = flatten_expression(working_set, e); if let Some(first) = flattened.first() { if first.0.start > last_end { @@ -528,8 +528,8 @@ pub fn flatten_expression( output.extend(flattened); } - for row in cells { - for expr in row { + for row in table.rows.as_ref() { + for expr in row.as_ref() { let flattened = flatten_expression(working_set, expr); if let Some(first) = flattened.first() { if first.0.start > last_end { diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 314192ef89..4f594148e8 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -1041,10 +1041,10 @@ pub fn parse_alias( // Then from the command itself true => match alias_call.arguments.get(1) { Some(Argument::Positional(Expression { - expr: Expr::Keyword(.., expr), + expr: Expr::Keyword(kw), .. })) => { - let aliased = working_set.get_span_contents(expr.span); + let aliased = working_set.get_span_contents(kw.expr.span); ( format!("Alias for `{}`", String::from_utf8_lossy(aliased)), String::new(), diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index af34b6e23a..cca0eaaa2c 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -256,8 +256,6 @@ fn parse_external_arg(working_set: &mut StateWorkingSet, span: Span) -> External pub fn parse_external_call(working_set: &mut StateWorkingSet, spans: &[Span]) -> Expression { trace!("parse external"); - let mut args = vec![]; - let head_contents = working_set.get_span_contents(spans[0]); let head_span = if head_contents.starts_with(b"^") { @@ -286,10 +284,10 @@ pub fn parse_external_call(working_set: &mut StateWorkingSet, spans: &[Span]) -> }) }; - for span in &spans[1..] { - let arg = parse_external_arg(working_set, *span); - args.push(arg); - } + let args = spans[1..] + .iter() + .map(|&span| parse_external_arg(working_set, span)) + .collect(); Expression { expr: Expr::ExternalCall(head, args), @@ -695,25 +693,29 @@ pub fn parse_multispan_value( String::from_utf8_lossy(keyword).into(), Span::new(spans[*spans_idx - 1].end, spans[*spans_idx - 1].end), )); + let keyword = Keyword { + keyword: keyword.as_slice().into(), + span: spans[*spans_idx - 1], + expr: Expression::garbage(arg_span), + }; return Expression { - expr: Expr::Keyword( - keyword.clone(), - spans[*spans_idx - 1], - Box::new(Expression::garbage(arg_span)), - ), + expr: Expr::Keyword(Box::new(keyword)), span: arg_span, ty: Type::Any, custom_completion: None, }; } - let keyword_span = spans[*spans_idx - 1]; - let expr = parse_multispan_value(working_set, spans, spans_idx, arg); - let ty = expr.ty.clone(); + + let keyword = Keyword { + keyword: keyword.as_slice().into(), + span: spans[*spans_idx - 1], + expr: parse_multispan_value(working_set, spans, spans_idx, arg), + }; Expression { - expr: Expr::Keyword(keyword.clone(), keyword_span, Box::new(expr)), + ty: keyword.expr.ty.clone(), + expr: Expr::Keyword(Box::new(keyword)), span: arg_span, - ty, custom_completion: None, } } @@ -1128,18 +1130,17 @@ pub fn parse_call(working_set: &mut StateWorkingSet, spans: &[Span], head: Span) { trace!("parsing: alias of external call"); - let mut final_args = args.clone(); + let mut head = head.clone(); + head.span = spans[0]; // replacing the spans preserves syntax highlighting - for arg_span in spans.iter().skip(1) { + let mut final_args = args.clone().into_vec(); + for arg_span in &spans[1..] { let arg = parse_external_arg(working_set, *arg_span); final_args.push(arg); } - let mut head = head.clone(); - head.span = spans[0]; // replacing the spans preserves syntax highlighting - return Expression { - expr: Expr::ExternalCall(head, final_args), + expr: Expr::ExternalCall(head, final_args.into()), span: span(spans), ty: ty.clone(), custom_completion: *custom_completion, @@ -1493,22 +1494,14 @@ pub fn parse_range(working_set: &mut StateWorkingSet, span: Span) -> Expression None } else { let from_span = Span::new(span.start, span.start + dotdot_pos[0]); - Some(Box::new(parse_value( - working_set, - from_span, - &SyntaxShape::Number, - ))) + Some(parse_value(working_set, from_span, &SyntaxShape::Number)) }; let to = if token.ends_with(range_op_str) { None } else { let to_span = Span::new(range_op_span.end, span.end); - Some(Box::new(parse_value( - working_set, - to_span, - &SyntaxShape::Number, - ))) + Some(parse_value(working_set, to_span, &SyntaxShape::Number)) }; trace!("-- from: {:?} to: {:?}", from, to); @@ -1523,25 +1516,28 @@ pub fn parse_range(working_set: &mut StateWorkingSet, span: Span) -> Expression let next_span = Span::new(next_op_span.end, range_op_span.start); ( - Some(Box::new(parse_value( - working_set, - next_span, - &SyntaxShape::Number, - ))), + Some(parse_value(working_set, next_span, &SyntaxShape::Number)), next_op_span, ) } else { (None, span) }; - let range_op = RangeOperator { + let operator = RangeOperator { inclusion, span: range_op_span, next_op_span, }; + let range = Range { + from, + next, + to, + operator, + }; + Expression { - expr: Expr::Range(from, next, to, range_op), + expr: Expr::Range(Box::new(range)), span, ty: Type::Range, custom_completion: None, @@ -2317,19 +2313,20 @@ pub fn parse_unit_value<'res>( }; trace!("-- found {} {:?}", num, unit); + let value = ValueWithUnit { + expr: Expression { + expr: Expr::Int(num), + span: lhs_span, + ty: Type::Number, + custom_completion: None, + }, + unit: Spanned { + item: unit, + span: unit_span, + }, + }; let expr = Expression { - expr: Expr::ValueWithUnit( - Box::new(Expression { - expr: Expr::Int(num), - span: lhs_span, - ty: Type::Number, - custom_completion: None, - }), - Spanned { - item: unit, - span: unit_span, - }, - ), + expr: Expr::ValueWithUnit(Box::new(value)), span, ty, custom_completion: None, @@ -4007,11 +4004,16 @@ fn parse_table_expression(working_set: &mut StateWorkingSet, span: Span) -> Expr working_set.parse_errors.extend(errs); ty } else { - Type::Table(vec![]) + Type::table() + }; + + let table = Table { + columns: head.into(), + rows: rows.into_iter().map(Into::into).collect(), }; Expression { - expr: Expr::Table(head, rows), + expr: Expr::Table(table), span, ty, custom_completion: None, @@ -4057,7 +4059,7 @@ fn table_type(head: &[Expression], rows: &[Vec]) -> (Type, Vec Expression { @@ -5371,7 +5373,7 @@ pub fn parse_record(working_set: &mut StateWorkingSet, span: Span) -> Expression match &inner.ty { Type::Record(inner_fields) => { if let Some(fields) = &mut field_types { - for (field, ty) in inner_fields { + for (field, ty) in inner_fields.as_ref() { fields.push((field.clone(), ty.clone())); } } @@ -5450,7 +5452,7 @@ pub fn parse_record(working_set: &mut StateWorkingSet, span: Span) -> Expression expr: Expr::Record(output), span, ty: (if let Some(fields) = field_types { - Type::Record(fields) + Type::Record(fields.into()) } else { Type::Any }), @@ -5988,7 +5990,7 @@ pub fn discover_captures_in_expr( Expr::ExternalCall(head, args) => { discover_captures_in_expr(working_set, head, seen, seen_blocks, output)?; - for ExternalArgument::Regular(expr) | ExternalArgument::Spread(expr) in args { + for ExternalArgument::Regular(expr) | ExternalArgument::Spread(expr) in args.as_ref() { discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; } } @@ -6004,8 +6006,8 @@ pub fn discover_captures_in_expr( Expr::Nothing => {} Expr::GlobPattern(_, _) => {} Expr::Int(_) => {} - Expr::Keyword(_, _, expr) => { - discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; + Expr::Keyword(kw) => { + discover_captures_in_expr(working_set, &kw.expr, seen, seen_blocks, output)?; } Expr::List(list) => { for item in list { @@ -6013,15 +6015,15 @@ pub fn discover_captures_in_expr( } } Expr::Operator(_) => {} - Expr::Range(expr1, expr2, expr3, _) => { - if let Some(expr) = expr1 { - discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; + Expr::Range(range) => { + if let Some(from) = &range.from { + discover_captures_in_expr(working_set, from, seen, seen_blocks, output)?; } - if let Some(expr) = expr2 { - discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; + if let Some(next) = &range.next { + discover_captures_in_expr(working_set, next, seen, seen_blocks, output)?; } - if let Some(expr) = expr3 { - discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; + if let Some(to) = &range.to { + discover_captures_in_expr(working_set, to, seen, seen_blocks, output)?; } } Expr::Record(items) => { @@ -6107,18 +6109,18 @@ pub fn discover_captures_in_expr( } } } - Expr::Table(headers, values) => { - for header in headers { + Expr::Table(table) => { + for header in table.columns.as_ref() { discover_captures_in_expr(working_set, header, seen, seen_blocks, output)?; } - for row in values { - for cell in row { + for row in table.rows.as_ref() { + for cell in row.as_ref() { discover_captures_in_expr(working_set, cell, seen, seen_blocks, output)?; } } } - Expr::ValueWithUnit(expr, _) => { - discover_captures_in_expr(working_set, expr, seen, seen_blocks, output)?; + Expr::ValueWithUnit(value) => { + discover_captures_in_expr(working_set, &value.expr, seen, seen_blocks, output)?; } Expr::Var(var_id) => { if (*var_id > ENV_VARIABLE_ID || *var_id == IN_VARIABLE_ID) && !seen.contains(var_id) { diff --git a/crates/nu-parser/src/type_check.rs b/crates/nu-parser/src/type_check.rs index 9643f74caf..14c88825db 100644 --- a/crates/nu-parser/src/type_check.rs +++ b/crates/nu-parser/src/type_check.rs @@ -90,8 +90,8 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Duration, None), (Type::Filesize, Type::Filesize) => (Type::Filesize, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Any, None), (_, Type::Any) => (Type::Any, None), @@ -146,8 +146,8 @@ pub fn math_result_type( (Type::Duration, Type::Duration) => (Type::Duration, None), (Type::Filesize, Type::Filesize) => (Type::Filesize, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Any, None), (_, Type::Any) => (Type::Any, None), @@ -197,8 +197,8 @@ pub fn math_result_type( (Type::Duration, Type::Float) => (Type::Duration, None), (Type::Float, Type::Duration) => (Type::Duration, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Any, None), (_, Type::Any) => (Type::Any, None), @@ -246,8 +246,8 @@ pub fn math_result_type( (Type::Number, Type::Float) => (Type::Number, None), (Type::Float, Type::Number) => (Type::Number, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Any, None), (_, Type::Any) => (Type::Any, None), @@ -296,8 +296,8 @@ pub fn math_result_type( (Type::Duration, Type::Int) => (Type::Duration, None), (Type::Duration, Type::Float) => (Type::Duration, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Any, None), (_, Type::Any) => (Type::Any, None), @@ -380,10 +380,8 @@ pub fn math_result_type( match (&lhs.ty, &rhs.ty) { (Type::Bool, Type::Bool) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => { - (Type::Custom(a.to_string()), None) - } - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Any, None), (_, Type::Any) => (Type::Any, None), @@ -434,8 +432,8 @@ pub fn math_result_type( (Type::Date, Type::Date) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Nothing, _) => (Type::Nothing, None), (_, Type::Nothing) => (Type::Nothing, None), @@ -484,8 +482,8 @@ pub fn math_result_type( (Type::Date, Type::Date) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Nothing, _) => (Type::Nothing, None), (_, Type::Nothing) => (Type::Nothing, None), @@ -534,8 +532,8 @@ pub fn math_result_type( (Type::Date, Type::Date) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), @@ -584,8 +582,8 @@ pub fn math_result_type( (Type::Date, Type::Date) => (Type::Bool, None), (Type::Filesize, Type::Filesize) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), @@ -620,14 +618,14 @@ pub fn math_result_type( } }, Operator::Comparison(Comparison::Equal) => match (&lhs.ty, &rhs.ty) { - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), _ => (Type::Bool, None), }, Operator::Comparison(Comparison::NotEqual) => match (&lhs.ty, &rhs.ty) { - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), _ => (Type::Bool, None), }, @@ -636,8 +634,8 @@ pub fn math_result_type( (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::String, _) => { *op = Expression::garbage(op.span); @@ -671,8 +669,8 @@ pub fn math_result_type( (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::String, _) => { *op = Expression::garbage(op.span); @@ -706,8 +704,8 @@ pub fn math_result_type( (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::String, _) => { *op = Expression::garbage(op.span); @@ -741,8 +739,8 @@ pub fn math_result_type( (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::String, _) => { *op = Expression::garbage(op.span); @@ -777,8 +775,8 @@ pub fn math_result_type( (Type::String, Type::String) => (Type::Bool, None), (Type::String, Type::Record(_)) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), @@ -815,8 +813,8 @@ pub fn math_result_type( (Type::String, Type::String) => (Type::Bool, None), (Type::String, Type::Record(_)) => (Type::Bool, None), - (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.to_string()), None), - (Type::Custom(a), _) => (Type::Custom(a.to_string()), None), + (Type::Custom(a), Type::Custom(b)) if a == b => (Type::Custom(a.clone()), None), + (Type::Custom(a), _) => (Type::Custom(a.clone()), None), (Type::Any, _) => (Type::Bool, None), (_, Type::Any) => (Type::Bool, None), diff --git a/crates/nu-parser/tests/test_parser.rs b/crates/nu-parser/tests/test_parser.rs index 8446146b98..e73f0f2e02 100644 --- a/crates/nu-parser/tests/test_parser.rs +++ b/crates/nu-parser/tests/test_parser.rs @@ -1,6 +1,6 @@ use nu_parser::*; use nu_protocol::{ - ast::{Argument, Call, Expr, PathMember}, + ast::{Argument, Call, Expr, PathMember, Range}, engine::{Command, EngineState, Stack, StateWorkingSet}, ParseError, PipelineData, ShellError, Signature, Span, SyntaxShape, }; @@ -311,7 +311,7 @@ pub fn parse_cell_path() { working_set.add_variable( "foo".to_string().into_bytes(), Span::test_data(), - nu_protocol::Type::Record(vec![]), + nu_protocol::Type::record(), false, ); @@ -356,7 +356,7 @@ pub fn parse_cell_path_optional() { working_set.add_variable( "foo".to_string().into_bytes(), Span::test_data(), - nu_protocol::Type::Record(vec![]), + nu_protocol::Type::record(), false, ); @@ -986,20 +986,25 @@ mod range { assert_eq!(pipeline.len(), 1, "{tag}: expression length"); let element = &pipeline.elements[0]; assert!(element.redirection.is_none()); - if let Expr::Range( - Some(_), - None, - Some(_), - RangeOperator { - inclusion: the_inclusion, - .. - }, - ) = element.expr.expr - { - assert_eq!( - the_inclusion, inclusion, - "{tag}: wrong RangeInclusion {the_inclusion:?}" - ); + if let Expr::Range(range) = &element.expr.expr { + if let Range { + from: Some(_), + next: None, + to: Some(_), + operator: + RangeOperator { + inclusion: the_inclusion, + .. + }, + } = range.as_ref() + { + assert_eq!( + *the_inclusion, inclusion, + "{tag}: wrong RangeInclusion {the_inclusion:?}" + ); + } else { + panic!("{tag}: expression mismatch.") + } } else { panic!("{tag}: expression mismatch.") }; @@ -1040,20 +1045,25 @@ mod range { assert_eq!(pipeline.len(), 1, "{tag}: expression length 1"); let element = &pipeline.elements[0]; assert!(element.redirection.is_none()); - if let Expr::Range( - Some(_), - None, - Some(_), - RangeOperator { - inclusion: the_inclusion, - .. - }, - ) = element.expr.expr - { - assert_eq!( - the_inclusion, inclusion, - "{tag}: wrong RangeInclusion {the_inclusion:?}" - ); + if let Expr::Range(range) = &element.expr.expr { + if let Range { + from: Some(_), + next: None, + to: Some(_), + operator: + RangeOperator { + inclusion: the_inclusion, + .. + }, + } = range.as_ref() + { + assert_eq!( + *the_inclusion, inclusion, + "{tag}: wrong RangeInclusion {the_inclusion:?}" + ); + } else { + panic!("{tag}: expression mismatch.") + } } else { panic!("{tag}: expression mismatch.") }; @@ -1081,20 +1091,25 @@ mod range { assert_eq!(pipeline.len(), 1, "{tag}: expression length"); let element = &pipeline.elements[0]; assert!(element.redirection.is_none()); - if let Expr::Range( - Some(_), - None, - None, - RangeOperator { - inclusion: the_inclusion, - .. - }, - ) = element.expr.expr - { - assert_eq!( - the_inclusion, inclusion, - "{tag}: wrong RangeInclusion {the_inclusion:?}" - ); + if let Expr::Range(range) = &element.expr.expr { + if let Range { + from: Some(_), + next: None, + to: None, + operator: + RangeOperator { + inclusion: the_inclusion, + .. + }, + } = range.as_ref() + { + assert_eq!( + *the_inclusion, inclusion, + "{tag}: wrong RangeInclusion {the_inclusion:?}" + ); + } else { + panic!("{tag}: expression mismatch.") + } } else { panic!("{tag}: expression mismatch.") }; @@ -1122,20 +1137,25 @@ mod range { assert_eq!(pipeline.len(), 1, "{tag}: expression length"); let element = &pipeline.elements[0]; assert!(element.redirection.is_none()); - if let Expr::Range( - None, - None, - Some(_), - RangeOperator { - inclusion: the_inclusion, - .. - }, - ) = element.expr.expr - { - assert_eq!( - the_inclusion, inclusion, - "{tag}: wrong RangeInclusion {the_inclusion:?}" - ); + if let Expr::Range(range) = &element.expr.expr { + if let Range { + from: None, + next: None, + to: Some(_), + operator: + RangeOperator { + inclusion: the_inclusion, + .. + }, + } = range.as_ref() + { + assert_eq!( + *the_inclusion, inclusion, + "{tag}: wrong RangeInclusion {the_inclusion:?}" + ); + } else { + panic!("{tag}: expression mismatch.") + } } else { panic!("{tag}: expression mismatch.") }; @@ -1163,20 +1183,25 @@ mod range { assert_eq!(pipeline.len(), 1, "{tag}: expression length"); let element = &pipeline.elements[0]; assert!(element.redirection.is_none()); - if let Expr::Range( - Some(_), - Some(_), - Some(_), - RangeOperator { - inclusion: the_inclusion, - .. - }, - ) = element.expr.expr - { - assert_eq!( - the_inclusion, inclusion, - "{tag}: wrong RangeInclusion {the_inclusion:?}" - ); + if let Expr::Range(range) = &element.expr.expr { + if let Range { + from: Some(_), + next: Some(_), + to: Some(_), + operator: + RangeOperator { + inclusion: the_inclusion, + .. + }, + } = range.as_ref() + { + assert_eq!( + *the_inclusion, inclusion, + "{tag}: wrong RangeInclusion {the_inclusion:?}" + ); + } else { + panic!("{tag}: expression mismatch.") + } } else { panic!("{tag}: expression mismatch.") }; diff --git a/crates/nu-protocol/src/ast/expr.rs b/crates/nu-protocol/src/ast/expr.rs index 54ac6149ca..53a0717f34 100644 --- a/crates/nu-protocol/src/ast/expr.rs +++ b/crates/nu-protocol/src/ast/expr.rs @@ -2,13 +2,10 @@ use chrono::FixedOffset; use serde::{Deserialize, Serialize}; use super::{ - Call, CellPath, Expression, ExternalArgument, FullCellPath, MatchPattern, Operator, - RangeOperator, -}; -use crate::{ - ast::ImportPattern, ast::Unit, engine::EngineState, BlockId, OutDest, Signature, Span, Spanned, - VarId, + Call, CellPath, Expression, ExternalArgument, FullCellPath, Keyword, MatchPattern, Operator, + Range, Table, ValueWithUnit, }; +use crate::{ast::ImportPattern, engine::EngineState, BlockId, OutDest, Signature, Span, VarId}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum Expr { @@ -16,16 +13,11 @@ pub enum Expr { Int(i64), Float(f64), Binary(Vec), - Range( - Option>, // from - Option>, // next value after "from" - Option>, // to - RangeOperator, - ), + Range(Box), Var(VarId), VarDecl(VarId), Call(Box), - ExternalCall(Box, Vec), // head, args + ExternalCall(Box, Box<[ExternalArgument]>), // head, args Operator(Operator), RowCondition(BlockId), UnaryNot(Box), @@ -35,10 +27,10 @@ pub enum Expr { Closure(BlockId), MatchBlock(Vec<(MatchPattern, Expression)>), List(Vec), - Table(Vec, Vec>), + Table(Table), Record(Vec), - Keyword(Vec, Span, Box), - ValueWithUnit(Box, Spanned), + Keyword(Box), + ValueWithUnit(Box), DateTime(chrono::DateTime), Filepath(String, bool), Directory(String, bool), @@ -54,6 +46,11 @@ pub enum Expr { Garbage, } +// This is to document/enforce the size of `Expr` in bytes. +// We should try to avoid increasing the size of `Expr`, +// and PRs that do so will have to change the number below so that it's noted in review. +const _: () = assert!(std::mem::size_of::() <= 40); + impl Expr { pub fn pipe_redirection( &self, @@ -72,15 +69,15 @@ impl Expr { | Expr::Int(_) | Expr::Float(_) | Expr::Binary(_) - | Expr::Range(_, _, _, _) + | Expr::Range(_) | Expr::Var(_) | Expr::UnaryNot(_) | Expr::BinaryOp(_, _, _) | Expr::Closure(_) // piping into a closure value, not into a closure call | Expr::List(_) - | Expr::Table(_, _) + | Expr::Table(_) | Expr::Record(_) - | Expr::ValueWithUnit(_, _) + | Expr::ValueWithUnit(_) | Expr::DateTime(_) | Expr::String(_) | Expr::CellPath(_) @@ -112,7 +109,7 @@ impl Expr { // No override necessary, pipes will always be created in eval (None, None) } - Expr::Keyword(_, _, _) => { + Expr::Keyword(_) => { // Not sure about this; let's return no redirection override for now. (None, None) } diff --git a/crates/nu-protocol/src/ast/expression.rs b/crates/nu-protocol/src/ast/expression.rs index 3b98f4679e..8766b3f8e5 100644 --- a/crates/nu-protocol/src/ast/expression.rs +++ b/crates/nu-protocol/src/ast/expression.rs @@ -88,7 +88,7 @@ impl Expression { pub fn as_keyword(&self) -> Option<&Expression> { match &self.expr { - Expr::Keyword(_, _, expr) => Some(expr), + Expr::Keyword(kw) => Some(&kw.expr), _ => None, } } @@ -189,7 +189,9 @@ impl Expression { if head.has_in_variable(working_set) { return true; } - for ExternalArgument::Regular(expr) | ExternalArgument::Spread(expr) in args { + for ExternalArgument::Regular(expr) | ExternalArgument::Spread(expr) in + args.as_ref() + { if expr.has_in_variable(working_set) { return true; } @@ -211,7 +213,7 @@ impl Expression { Expr::Nothing => false, Expr::GlobPattern(_, _) => false, Expr::Int(_) => false, - Expr::Keyword(_, _, expr) => expr.has_in_variable(working_set), + Expr::Keyword(kw) => kw.expr.has_in_variable(working_set), Expr::List(list) => { for item in list { if item.expr().has_in_variable(working_set) { @@ -230,18 +232,18 @@ impl Expression { } Expr::Operator(_) => false, Expr::MatchBlock(_) => false, - Expr::Range(left, middle, right, ..) => { - if let Some(left) = &left { + Expr::Range(range) => { + if let Some(left) = &range.from { if left.has_in_variable(working_set) { return true; } } - if let Some(middle) = &middle { + if let Some(middle) = &range.next { if middle.has_in_variable(working_set) { return true; } } - if let Some(right) = &right { + if let Some(right) = &range.to { if right.has_in_variable(working_set) { return true; } @@ -283,14 +285,14 @@ impl Expression { false } } - Expr::Table(headers, cells) => { - for header in headers { + Expr::Table(table) => { + for header in table.columns.as_ref() { if header.has_in_variable(working_set) { return true; } } - for row in cells { + for row in table.rows.as_ref() { for cell in row.iter() { if cell.has_in_variable(working_set) { return true; @@ -301,7 +303,7 @@ impl Expression { false } - Expr::ValueWithUnit(expr, _) => expr.has_in_variable(working_set), + Expr::ValueWithUnit(value) => value.expr.has_in_variable(working_set), Expr::Var(var_id) => *var_id == IN_VARIABLE_ID, Expr::VarDecl(_) => false, } @@ -372,7 +374,9 @@ impl Expression { Expr::DateTime(_) => {} Expr::ExternalCall(head, args) => { head.replace_span(working_set, replaced, new_span); - for ExternalArgument::Regular(expr) | ExternalArgument::Spread(expr) in args { + for ExternalArgument::Regular(expr) | ExternalArgument::Spread(expr) in + args.as_mut() + { expr.replace_span(working_set, replaced, new_span); } } @@ -391,7 +395,7 @@ impl Expression { Expr::GlobPattern(_, _) => {} Expr::MatchBlock(_) => {} Expr::Int(_) => {} - Expr::Keyword(_, _, expr) => expr.replace_span(working_set, replaced, new_span), + Expr::Keyword(kw) => kw.expr.replace_span(working_set, replaced, new_span), Expr::List(list) => { for item in list { item.expr_mut() @@ -399,14 +403,14 @@ impl Expression { } } Expr::Operator(_) => {} - Expr::Range(left, middle, right, ..) => { - if let Some(left) = left { + Expr::Range(range) => { + if let Some(left) = &mut range.from { left.replace_span(working_set, replaced, new_span) } - if let Some(middle) = middle { + if let Some(middle) = &mut range.next { middle.replace_span(working_set, replaced, new_span) } - if let Some(right) = right { + if let Some(right) = &mut range.to { right.replace_span(working_set, replaced, new_span) } } @@ -441,19 +445,19 @@ impl Expression { *block_id = working_set.add_block(Arc::new(block)); } - Expr::Table(headers, cells) => { - for header in headers { + Expr::Table(table) => { + for header in table.columns.as_mut() { header.replace_span(working_set, replaced, new_span) } - for row in cells { + for row in table.rows.as_mut() { for cell in row.iter_mut() { cell.replace_span(working_set, replaced, new_span) } } } - Expr::ValueWithUnit(expr, _) => expr.replace_span(working_set, replaced, new_span), + Expr::ValueWithUnit(value) => value.expr.replace_span(working_set, replaced, new_span), Expr::Var(_) => {} Expr::VarDecl(_) => {} } diff --git a/crates/nu-protocol/src/ast/keyword.rs b/crates/nu-protocol/src/ast/keyword.rs new file mode 100644 index 0000000000..62707c8522 --- /dev/null +++ b/crates/nu-protocol/src/ast/keyword.rs @@ -0,0 +1,10 @@ +use super::Expression; +use crate::Span; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Keyword { + pub keyword: Box<[u8]>, + pub span: Span, + pub expr: Expression, +} diff --git a/crates/nu-protocol/src/ast/mod.rs b/crates/nu-protocol/src/ast/mod.rs index 0840c84018..7c627997fe 100644 --- a/crates/nu-protocol/src/ast/mod.rs +++ b/crates/nu-protocol/src/ast/mod.rs @@ -4,10 +4,14 @@ mod cell_path; mod expr; mod expression; mod import_pattern; +mod keyword; mod match_pattern; mod operator; mod pipeline; +mod range; +pub mod table; mod unit; +mod value_with_unit; pub use block::*; pub use call::*; @@ -15,7 +19,11 @@ pub use cell_path::*; pub use expr::*; pub use expression::*; pub use import_pattern::*; +pub use keyword::*; pub use match_pattern::*; pub use operator::*; pub use pipeline::*; +pub use range::*; +pub use table::Table; pub use unit::*; +pub use value_with_unit::*; diff --git a/crates/nu-protocol/src/ast/range.rs b/crates/nu-protocol/src/ast/range.rs new file mode 100644 index 0000000000..cd83a0f62d --- /dev/null +++ b/crates/nu-protocol/src/ast/range.rs @@ -0,0 +1,10 @@ +use super::{Expression, RangeOperator}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Range { + pub from: Option, + pub next: Option, + pub to: Option, + pub operator: RangeOperator, +} diff --git a/crates/nu-protocol/src/ast/table.rs b/crates/nu-protocol/src/ast/table.rs new file mode 100644 index 0000000000..4983163b4d --- /dev/null +++ b/crates/nu-protocol/src/ast/table.rs @@ -0,0 +1,8 @@ +use super::Expression; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct Table { + pub columns: Box<[Expression]>, + pub rows: Box<[Box<[Expression]>]>, +} diff --git a/crates/nu-protocol/src/ast/value_with_unit.rs b/crates/nu-protocol/src/ast/value_with_unit.rs new file mode 100644 index 0000000000..2b722534c3 --- /dev/null +++ b/crates/nu-protocol/src/ast/value_with_unit.rs @@ -0,0 +1,9 @@ +use super::Expression; +use crate::{Spanned, Unit}; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct ValueWithUnit { + pub expr: Expression, + pub unit: Spanned, +} diff --git a/crates/nu-protocol/src/debugger/profiler.rs b/crates/nu-protocol/src/debugger/profiler.rs index 427c51d9c3..d1efe90cb0 100644 --- a/crates/nu-protocol/src/debugger/profiler.rs +++ b/crates/nu-protocol/src/debugger/profiler.rs @@ -243,22 +243,22 @@ fn expr_to_string(engine_state: &EngineState, expr: &Expr) -> String { Expr::GlobPattern(_, _) => "glob pattern".to_string(), Expr::ImportPattern(_) => "import pattern".to_string(), Expr::Int(_) => "int".to_string(), - Expr::Keyword(_, _, _) => "keyword".to_string(), + Expr::Keyword(_) => "keyword".to_string(), Expr::List(_) => "list".to_string(), Expr::MatchBlock(_) => "match block".to_string(), Expr::Nothing => "nothing".to_string(), Expr::Operator(_) => "operator".to_string(), Expr::Overlay(_) => "overlay".to_string(), - Expr::Range(_, _, _, _) => "range".to_string(), + Expr::Range(_) => "range".to_string(), Expr::Record(_) => "record".to_string(), Expr::RowCondition(_) => "row condition".to_string(), Expr::Signature(_) => "signature".to_string(), Expr::String(_) => "string".to_string(), Expr::StringInterpolation(_) => "string interpolation".to_string(), Expr::Subexpression(_) => "subexpression".to_string(), - Expr::Table(_, _) => "table".to_string(), + Expr::Table(_) => "table".to_string(), Expr::UnaryNot(_) => "unary not".to_string(), - Expr::ValueWithUnit(_, _) => "value with unit".to_string(), + Expr::ValueWithUnit(_) => "value with unit".to_string(), Expr::Var(_) => "var".to_string(), Expr::VarDecl(_) => "var decl".to_string(), } diff --git a/crates/nu-protocol/src/engine/pattern_match.rs b/crates/nu-protocol/src/engine/pattern_match.rs index e29779b633..2a2287ea67 100644 --- a/crates/nu-protocol/src/engine/pattern_match.rs +++ b/crates/nu-protocol/src/engine/pattern_match.rs @@ -141,11 +141,11 @@ impl Matcher for Pattern { false } } - Expr::ValueWithUnit(amount, unit) => { - let span = unit.span; + Expr::ValueWithUnit(val) => { + let span = val.unit.span; - if let Expr::Int(size) = amount.expr { - match &unit.item.build_value(size, span) { + if let Expr::Int(size) = val.expr.expr { + match &val.unit.item.build_value(size, span) { Ok(v) => v == value, _ => false, } @@ -153,10 +153,10 @@ impl Matcher for Pattern { false } } - Expr::Range(start, step, end, inclusion) => { + Expr::Range(range) => { // TODO: Add support for floats - let start = if let Some(start) = &start { + let start = if let Some(start) = &range.from { match &start.expr { Expr::Int(start) => *start, _ => return false, @@ -165,7 +165,7 @@ impl Matcher for Pattern { 0 }; - let end = if let Some(end) = &end { + let end = if let Some(end) = &range.to { match &end.expr { Expr::Int(end) => *end, _ => return false, @@ -174,7 +174,7 @@ impl Matcher for Pattern { i64::MAX }; - let step = if let Some(step) = step { + let step = if let Some(step) = &range.next { match &step.expr { Expr::Int(step) => *step - start, _ => return false, @@ -192,7 +192,7 @@ impl Matcher for Pattern { }; if let Value::Int { val, .. } = &value { - if matches!(inclusion.inclusion, RangeInclusion::RightExclusive) { + if matches!(range.operator.inclusion, RangeInclusion::RightExclusive) { *val >= start && *val < end && ((*val - start) % step) == 0 } else { *val >= start && *val <= end && ((*val - start) % step) == 0 diff --git a/crates/nu-protocol/src/eval_base.rs b/crates/nu-protocol/src/eval_base.rs index 9a11f0d537..3281d65c47 100644 --- a/crates/nu-protocol/src/eval_base.rs +++ b/crates/nu-protocol/src/eval_base.rs @@ -100,9 +100,9 @@ pub trait Eval { Ok(Value::record(record, expr.span)) } - Expr::Table(headers, vals) => { + Expr::Table(table) => { let mut output_headers = vec![]; - for expr in headers { + for expr in table.columns.as_ref() { let header = Self::eval::(state, mut_state, expr)?.coerce_into_string()?; if let Some(idx) = output_headers .iter() @@ -111,7 +111,7 @@ pub trait Eval { return Err(ShellError::ColumnDefinedTwice { col_name: header, second_use: expr.span, - first_use: headers[idx].span, + first_use: table.columns[idx].span, }); } else { output_headers.push(header); @@ -119,8 +119,8 @@ pub trait Eval { } let mut output_rows = vec![]; - for val in vals { - let record = output_headers.iter().zip(val).map(|(col, expr)| { + for val in table.rows.as_ref() { + let record = output_headers.iter().zip(val.as_ref()).map(|(col, expr)| { Self::eval::(state, mut_state, expr).map(|val| (col.clone(), val)) }).collect::>()?; @@ -131,15 +131,15 @@ pub trait Eval { } Ok(Value::list(output_rows, expr.span)) } - Expr::Keyword(_, _, expr) => Self::eval::(state, mut_state, expr), + Expr::Keyword(kw) => Self::eval::(state, mut_state, &kw.expr), Expr::String(s) => Ok(Value::string(s.clone(), expr.span)), Expr::Nothing => Ok(Value::nothing(expr.span)), - Expr::ValueWithUnit(e, unit) => match Self::eval::(state, mut_state, e)? { - Value::Int { val, .. } => unit.item.build_value(val, unit.span), + Expr::ValueWithUnit(value) => match Self::eval::(state, mut_state, &value.expr)? { + Value::Int { val, .. } => value.unit.item.build_value(val, value.unit.span), x => Err(ShellError::CantConvert { to_type: "unit value".into(), from_type: x.get_type().to_string(), - span: e.span, + span: value.expr.span, help: None, }), }, @@ -150,27 +150,27 @@ pub trait Eval { Expr::Subexpression(block_id) => { Self::eval_subexpression::(state, mut_state, *block_id, expr.span) } - Expr::Range(from, next, to, operator) => { - let from = if let Some(f) = from { + Expr::Range(range) => { + let from = if let Some(f) = &range.from { Self::eval::(state, mut_state, f)? } else { Value::nothing(expr.span) }; - let next = if let Some(s) = next { + let next = if let Some(s) = &range.next { Self::eval::(state, mut_state, s)? } else { Value::nothing(expr.span) }; - let to = if let Some(t) = to { + let to = if let Some(t) = &range.to { Self::eval::(state, mut_state, t)? } else { Value::nothing(expr.span) }; Ok(Value::range( - Range::new(from, next, to, operator.inclusion, expr.span)?, + Range::new(from, next, to, range.operator.inclusion, expr.span)?, expr.span, )) } diff --git a/crates/nu-protocol/src/ty.rs b/crates/nu-protocol/src/ty.rs index 199fa69bc2..d5ea8c1554 100644 --- a/crates/nu-protocol/src/ty.rs +++ b/crates/nu-protocol/src/ty.rs @@ -15,7 +15,7 @@ pub enum Type { Bool, CellPath, Closure, - Custom(String), + Custom(Box), Date, Duration, Error, @@ -28,14 +28,22 @@ pub enum Type { Nothing, Number, Range, - Record(Vec<(String, Type)>), + Record(Box<[(String, Type)]>), Signature, String, Glob, - Table(Vec<(String, Type)>), + Table(Box<[(String, Type)]>), } impl Type { + pub fn record() -> Self { + Self::Record([].into()) + } + + pub fn table() -> Self { + Self::Table([].into()) + } + pub fn is_subtype(&self, other: &Type) -> bool { // Structural subtyping let is_subtype_collection = |this: &[(String, Type)], that: &[(String, Type)]| { diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 29319ae8f2..2c5019a369 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -793,7 +793,7 @@ impl Value { Value::Error { .. } => Type::Error, Value::Binary { .. } => Type::Binary, Value::CellPath { .. } => Type::CellPath, - Value::Custom { val, .. } => Type::Custom(val.type_name()), + Value::Custom { val, .. } => Type::Custom(val.type_name().into()), } } diff --git a/crates/nu_plugin_example/src/commands/config.rs b/crates/nu_plugin_example/src/commands/config.rs index 905f69dfec..f549bd324f 100644 --- a/crates/nu_plugin_example/src/commands/config.rs +++ b/crates/nu_plugin_example/src/commands/config.rs @@ -23,7 +23,7 @@ impl SimplePluginCommand for Config { fn signature(&self) -> Signature { Signature::build(self.name()) .category(Category::Experimental) - .input_output_type(Type::Nothing, Type::Table(vec![])) + .input_output_type(Type::Nothing, Type::table()) } fn search_terms(&self) -> Vec<&str> { diff --git a/crates/nu_plugin_formats/src/from/eml.rs b/crates/nu_plugin_formats/src/from/eml.rs index 5df336358a..2630e3b1c2 100644 --- a/crates/nu_plugin_formats/src/from/eml.rs +++ b/crates/nu_plugin_formats/src/from/eml.rs @@ -24,7 +24,7 @@ impl SimplePluginCommand for FromEml { fn signature(&self) -> Signature { Signature::build(self.name()) - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) .named( "preview-body", SyntaxShape::Int, diff --git a/crates/nu_plugin_formats/src/from/ics.rs b/crates/nu_plugin_formats/src/from/ics.rs index 34d43307b7..099b3431fe 100644 --- a/crates/nu_plugin_formats/src/from/ics.rs +++ b/crates/nu_plugin_formats/src/from/ics.rs @@ -23,7 +23,7 @@ impl SimplePluginCommand for FromIcs { fn signature(&self) -> Signature { Signature::build(self.name()) - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .category(Category::Formats) } diff --git a/crates/nu_plugin_formats/src/from/ini.rs b/crates/nu_plugin_formats/src/from/ini.rs index b6a861dc1d..cf37ffc3d7 100644 --- a/crates/nu_plugin_formats/src/from/ini.rs +++ b/crates/nu_plugin_formats/src/from/ini.rs @@ -20,7 +20,7 @@ impl SimplePluginCommand for FromIni { fn signature(&self) -> Signature { Signature::build(self.name()) - .input_output_types(vec![(Type::String, Type::Record(vec![]))]) + .input_output_types(vec![(Type::String, Type::record())]) .category(Category::Formats) } diff --git a/crates/nu_plugin_formats/src/from/vcf.rs b/crates/nu_plugin_formats/src/from/vcf.rs index 04dc351961..4de20154d7 100644 --- a/crates/nu_plugin_formats/src/from/vcf.rs +++ b/crates/nu_plugin_formats/src/from/vcf.rs @@ -22,7 +22,7 @@ impl SimplePluginCommand for FromVcf { fn signature(&self) -> Signature { Signature::build(self.name()) - .input_output_types(vec![(Type::String, Type::Table(vec![]))]) + .input_output_types(vec![(Type::String, Type::table())]) .category(Category::Formats) } diff --git a/crates/nu_plugin_polars/src/dataframe/eager/to_nu.rs b/crates/nu_plugin_polars/src/dataframe/eager/to_nu.rs index 55eb0d7205..9acac7355c 100644 --- a/crates/nu_plugin_polars/src/dataframe/eager/to_nu.rs +++ b/crates/nu_plugin_polars/src/dataframe/eager/to_nu.rs @@ -37,7 +37,7 @@ impl PluginCommand for ToNu { .switch("tail", "shows tail rows", Some('t')) .input_output_types(vec![ (Type::Custom("expression".into()), Type::Any), - (Type::Custom("dataframe".into()), Type::Table(vec![])), + (Type::Custom("dataframe".into()), Type::table()), ]) .category(Category::Custom("dataframe".into())) } diff --git a/crates/nuon/src/from.rs b/crates/nuon/src/from.rs index b9b0427d0c..a06a75e3f5 100644 --- a/crates/nuon/src/from.rs +++ b/crates/nuon/src/from.rs @@ -7,7 +7,7 @@ use std::sync::Arc; /// convert a raw string representation of NUON data to an actual Nushell [`Value`] /// -/// > **Note** +/// > **Note** /// > [`Span`] can be passed to [`from_nuon`] if there is context available to the caller, e.g. when /// > using this function in a command implementation such as /// [`from nuon`](https://www.nushell.sh/commands/docs/from_nuon.html). @@ -197,10 +197,13 @@ fn convert_to_value( span: expr.span, }), Expr::Int(val) => Ok(Value::int(val, span)), - Expr::Keyword(kw, ..) => Err(ShellError::OutsideSpannedLabeledError { + Expr::Keyword(kw) => Err(ShellError::OutsideSpannedLabeledError { src: original_text.to_string(), error: "Error when loading".into(), - msg: format!("{} not supported in nuon", String::from_utf8_lossy(&kw)), + msg: format!( + "{} not supported in nuon", + String::from_utf8_lossy(&kw.keyword) + ), span: expr.span, }), Expr::List(vals) => { @@ -237,27 +240,27 @@ fn convert_to_value( msg: "operators not supported in nuon".into(), span: expr.span, }), - Expr::Range(from, next, to, operator) => { - let from = if let Some(f) = from { - convert_to_value(*f, span, original_text)? + Expr::Range(range) => { + let from = if let Some(f) = range.from { + convert_to_value(f, span, original_text)? } else { Value::nothing(expr.span) }; - let next = if let Some(s) = next { - convert_to_value(*s, span, original_text)? + let next = if let Some(s) = range.next { + convert_to_value(s, span, original_text)? } else { Value::nothing(expr.span) }; - let to = if let Some(t) = to { - convert_to_value(*t, span, original_text)? + let to = if let Some(t) = range.to { + convert_to_value(t, span, original_text)? } else { Value::nothing(expr.span) }; Ok(Value::range( - Range::new(from, next, to, operator.inclusion, expr.span)?, + Range::new(from, next, to, range.operator.inclusion, expr.span)?, expr.span, )) } @@ -329,12 +332,12 @@ fn convert_to_value( msg: "subexpressions not supported in nuon".into(), span: expr.span, }), - Expr::Table(mut headers, cells) => { + Expr::Table(mut table) => { let mut cols = vec![]; let mut output = vec![]; - for key in headers.iter_mut() { + for key in table.columns.as_mut() { let key_str = match &mut key.expr { Expr::String(key_str) => key_str, _ => { @@ -351,14 +354,14 @@ fn convert_to_value( return Err(ShellError::ColumnDefinedTwice { col_name: key_str.clone(), second_use: key.span, - first_use: headers[idx].span, + first_use: table.columns[idx].span, }); } else { cols.push(std::mem::take(key_str)); } } - for row in cells { + for row in table.rows.into_vec() { if cols.len() != row.len() { return Err(ShellError::OutsideSpannedLabeledError { src: original_text.to_string(), @@ -370,7 +373,7 @@ fn convert_to_value( let record = cols .iter() - .zip(row) + .zip(row.into_vec()) .map(|(col, cell)| { convert_to_value(cell, span, original_text).map(|val| (col.clone(), val)) }) @@ -381,8 +384,8 @@ fn convert_to_value( Ok(Value::list(output, span)) } - Expr::ValueWithUnit(val, unit) => { - let size = match val.expr { + Expr::ValueWithUnit(value) => { + let size = match value.expr.expr { Expr::Int(val) => val, _ => { return Err(ShellError::OutsideSpannedLabeledError { @@ -394,7 +397,7 @@ fn convert_to_value( } }; - match unit.item { + match value.unit.item { Unit::Byte => Ok(Value::filesize(size, span)), Unit::Kilobyte => Ok(Value::filesize(size * 1000, span)), Unit::Megabyte => Ok(Value::filesize(size * 1000 * 1000, span)),