sort enums add missing items to parse_shape_name (#7450)

# Description

This PR adds missing items in `parse_shape_name`, sorts the
`SyntaxShape` enum and the `Type` enum. It's a pain to hunt around for
particular items in an enum when they're unsorted.

# User-Facing Changes


# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
Darren Schroeder
2022-12-13 10:46:22 -06:00
committed by GitHub
parent 0c4d4632ef
commit e529746294
3 changed files with 118 additions and 106 deletions

View File

@ -2728,28 +2728,36 @@ pub fn parse_shape_name(
b"any" => SyntaxShape::Any,
b"binary" => SyntaxShape::Binary,
b"block" => SyntaxShape::Block, //FIXME: Blocks should have known output types
b"closure" => SyntaxShape::Closure(None), //FIXME: Blocks should have known output types
b"bool" => SyntaxShape::Boolean,
b"cell-path" => SyntaxShape::CellPath,
b"duration" => SyntaxShape::Duration,
b"path" => SyntaxShape::Filepath,
b"closure" => SyntaxShape::Closure(None), //FIXME: Blocks should have known output types
b"cond" => SyntaxShape::RowCondition,
// b"custom" => SyntaxShape::Custom(Box::new(SyntaxShape::Any), SyntaxShape::Int),
b"datetime" => SyntaxShape::DateTime,
b"directory" => SyntaxShape::Directory,
b"duration" => SyntaxShape::Duration,
b"error" => SyntaxShape::Error,
b"expr" => SyntaxShape::Expression,
b"filesize" => SyntaxShape::Filesize,
b"full-cell-path" => SyntaxShape::FullCellPath,
b"glob" => SyntaxShape::GlobPattern,
b"int" => SyntaxShape::Int,
b"import-pattern" => SyntaxShape::ImportPattern,
b"keyword" => SyntaxShape::Keyword(vec![], Box::new(SyntaxShape::Any)),
b"list" => SyntaxShape::List(Box::new(SyntaxShape::Any)),
b"math" => SyntaxShape::MathExpression,
b"nothing" => SyntaxShape::Nothing,
b"number" => SyntaxShape::Number,
b"one-of" => SyntaxShape::OneOf(vec![]),
b"operator" => SyntaxShape::Operator,
b"path" => SyntaxShape::Filepath,
b"range" => SyntaxShape::Range,
b"cond" => SyntaxShape::RowCondition,
b"bool" => SyntaxShape::Boolean,
b"record" => SyntaxShape::Record,
b"signature" => SyntaxShape::Signature,
b"string" => SyntaxShape::String,
b"variable" => SyntaxShape::Variable,
b"record" => SyntaxShape::Record,
b"list" => SyntaxShape::List(Box::new(SyntaxShape::Any)),
b"table" => SyntaxShape::Table,
b"error" => SyntaxShape::Error,
b"variable" => SyntaxShape::Variable,
b"var-with-opt-type" => SyntaxShape::VarWithOptType,
_ => {
if bytes.contains(&b'@') {
let str = String::from_utf8_lossy(bytes);
@ -2785,19 +2793,23 @@ pub fn parse_shape_name(
pub fn parse_type(_working_set: &StateWorkingSet, bytes: &[u8]) -> Type {
match bytes {
b"int" => Type::Int,
b"float" => Type::Float,
b"range" => Type::Range,
b"bool" => Type::Bool,
b"string" => Type::String,
b"block" => Type::Block,
b"duration" => Type::Duration,
b"date" => Type::Date,
b"filesize" => Type::Filesize,
b"number" => Type::Number,
b"table" => Type::Table(vec![]), //FIXME
b"error" => Type::Error,
b"binary" => Type::Binary,
b"block" => Type::Block,
b"bool" => Type::Bool,
b"cellpath" => Type::CellPath,
b"closure" => Type::Closure,
b"date" => Type::Date,
b"duration" => Type::Duration,
b"error" => Type::Error,
b"filesize" => Type::Filesize,
b"float" => Type::Float,
b"int" => Type::Int,
b"list" => Type::List(Box::new(Type::Any)),
b"number" => Type::Number,
b"range" => Type::Range,
b"record" => Type::Record(vec![]),
b"string" => Type::String,
b"table" => Type::Table(vec![]), //FIXME
_ => Type::Any,
}