mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 00:13:21 +01:00
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:
parent
0c4d4632ef
commit
e529746294
@ -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,
|
||||
}
|
||||
|
@ -7,105 +7,105 @@ use crate::{DeclId, Type};
|
||||
/// The syntactic shapes that values must match to be passed into a command. You can think of this as the type-checking that occurs when you call a function.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum SyntaxShape {
|
||||
/// A specific match to a word or symbol
|
||||
Keyword(Vec<u8>, Box<SyntaxShape>),
|
||||
|
||||
/// Any syntactic form is allowed
|
||||
Any,
|
||||
|
||||
/// Strings and string-like bare words are allowed
|
||||
String,
|
||||
|
||||
/// A dotted path to navigate the table
|
||||
CellPath,
|
||||
|
||||
/// A dotted path to navigate the table (including variable)
|
||||
FullCellPath,
|
||||
|
||||
/// Only a numeric (integer or decimal) value is allowed
|
||||
Number,
|
||||
|
||||
/// A range is allowed (eg, `1..3`)
|
||||
Range,
|
||||
|
||||
/// Only an integer value is allowed
|
||||
Int,
|
||||
|
||||
/// A filepath is allowed
|
||||
Filepath,
|
||||
|
||||
/// A directory is allowed
|
||||
Directory,
|
||||
|
||||
/// A glob pattern is allowed, eg `foo*`
|
||||
GlobPattern,
|
||||
|
||||
/// A module path pattern used for imports
|
||||
ImportPattern,
|
||||
|
||||
/// A binary literal
|
||||
Binary,
|
||||
|
||||
/// A closure is allowed, eg `{|| start this thing}`
|
||||
Closure(Option<Vec<SyntaxShape>>),
|
||||
|
||||
/// A block is allowed, eg `{start this thing}`
|
||||
Block,
|
||||
|
||||
/// A table is allowed, eg `[[first, second]; [1, 2]]`
|
||||
Table,
|
||||
/// A boolean value, eg `true` or `false`
|
||||
Boolean,
|
||||
|
||||
/// A list is allowed, eg `[first second]`
|
||||
List(Box<SyntaxShape>),
|
||||
/// A dotted path to navigate the table
|
||||
CellPath,
|
||||
|
||||
/// A filesize value is allowed, eg `10kb`
|
||||
Filesize,
|
||||
/// A closure is allowed, eg `{|| start this thing}`
|
||||
Closure(Option<Vec<SyntaxShape>>),
|
||||
|
||||
/// A duration value is allowed, eg `19day`
|
||||
Duration,
|
||||
/// A custom shape with custom completion logic
|
||||
Custom(Box<SyntaxShape>, DeclId),
|
||||
|
||||
/// A datetime value, eg `2022-02-02` or `2019-10-12T07:20:50.52+00:00`
|
||||
DateTime,
|
||||
|
||||
/// A directory is allowed
|
||||
Directory,
|
||||
|
||||
/// A duration value is allowed, eg `19day`
|
||||
Duration,
|
||||
|
||||
/// An error value
|
||||
Error,
|
||||
|
||||
/// A general expression, eg `1 + 2` or `foo --bar`
|
||||
Expression,
|
||||
|
||||
/// A filepath is allowed
|
||||
Filepath,
|
||||
|
||||
/// A filesize value is allowed, eg `10kb`
|
||||
Filesize,
|
||||
|
||||
/// A dotted path to navigate the table (including variable)
|
||||
FullCellPath,
|
||||
|
||||
/// A glob pattern is allowed, eg `foo*`
|
||||
GlobPattern,
|
||||
|
||||
/// Only an integer value is allowed
|
||||
Int,
|
||||
|
||||
/// A module path pattern used for imports
|
||||
ImportPattern,
|
||||
|
||||
/// A specific match to a word or symbol
|
||||
Keyword(Vec<u8>, Box<SyntaxShape>),
|
||||
|
||||
/// A list is allowed, eg `[first second]`
|
||||
List(Box<SyntaxShape>),
|
||||
|
||||
/// A general math expression, eg `1 + 2`
|
||||
MathExpression,
|
||||
|
||||
/// Nothing
|
||||
Nothing,
|
||||
|
||||
/// Only a numeric (integer or decimal) value is allowed
|
||||
Number,
|
||||
|
||||
/// One of a list of possible items, checked in order
|
||||
OneOf(Vec<SyntaxShape>),
|
||||
|
||||
/// An operator, eg `+`
|
||||
Operator,
|
||||
|
||||
/// A range is allowed (eg, `1..3`)
|
||||
Range,
|
||||
|
||||
/// A record value, eg `{x: 1, y: 2}`
|
||||
Record,
|
||||
|
||||
/// A math expression which expands shorthand forms on the lefthand side, eg `foo > 1`
|
||||
/// The shorthand allows us to more easily reach columns inside of the row being passed in
|
||||
RowCondition,
|
||||
|
||||
/// A general math expression, eg `1 + 2`
|
||||
MathExpression,
|
||||
/// A signature for a definition, `[x:int, --foo]`
|
||||
Signature,
|
||||
|
||||
/// Strings and string-like bare words are allowed
|
||||
String,
|
||||
|
||||
/// A table is allowed, eg `[[first, second]; [1, 2]]`
|
||||
Table,
|
||||
|
||||
/// A variable name, eg `$foo`
|
||||
Variable,
|
||||
|
||||
/// A variable with optional type, `x` or `x: int`
|
||||
VarWithOptType,
|
||||
|
||||
/// A signature for a definition, `[x:int, --foo]`
|
||||
Signature,
|
||||
|
||||
/// A general expression, eg `1 + 2` or `foo --bar`
|
||||
Expression,
|
||||
|
||||
/// A boolean value, eg `true` or `false`
|
||||
Boolean,
|
||||
|
||||
/// A record value, eg `{x: 1, y: 2}`
|
||||
Record,
|
||||
|
||||
/// An error value
|
||||
Error,
|
||||
|
||||
/// A custom shape with custom completion logic
|
||||
Custom(Box<SyntaxShape>, DeclId),
|
||||
|
||||
/// One of a list of possible items, checked in order
|
||||
OneOf(Vec<SyntaxShape>),
|
||||
|
||||
/// Nothing
|
||||
Nothing,
|
||||
}
|
||||
|
||||
impl SyntaxShape {
|
||||
@ -134,6 +134,7 @@ impl SyntaxShape {
|
||||
}
|
||||
SyntaxShape::Keyword(_, expr) => expr.to_type(),
|
||||
SyntaxShape::MathExpression => Type::Any,
|
||||
SyntaxShape::Nothing => Type::Any,
|
||||
SyntaxShape::Number => Type::Number,
|
||||
SyntaxShape::OneOf(_) => Type::Any,
|
||||
SyntaxShape::Operator => Type::Any,
|
||||
@ -146,7 +147,6 @@ impl SyntaxShape {
|
||||
SyntaxShape::Table => Type::List(Box::new(Type::Any)), // FIXME: What role should columns play in the Table type?
|
||||
SyntaxShape::VarWithOptType => Type::Any,
|
||||
SyntaxShape::Variable => Type::Any,
|
||||
SyntaxShape::Nothing => Type::Any,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,29 +7,29 @@ use crate::SyntaxShape;
|
||||
|
||||
#[derive(Clone, Debug, Default, EnumIter, PartialEq, Eq, Serialize, Deserialize, Hash)]
|
||||
pub enum Type {
|
||||
Int,
|
||||
Float,
|
||||
Range,
|
||||
Bool,
|
||||
String,
|
||||
Any,
|
||||
Binary,
|
||||
Block,
|
||||
Closure,
|
||||
Bool,
|
||||
CellPath,
|
||||
Duration,
|
||||
Closure,
|
||||
Custom(String),
|
||||
Date,
|
||||
Duration,
|
||||
Error,
|
||||
Filesize,
|
||||
Float,
|
||||
Int,
|
||||
List(Box<Type>),
|
||||
Number,
|
||||
ListStream,
|
||||
#[default]
|
||||
Nothing,
|
||||
Number,
|
||||
Range,
|
||||
Record(Vec<(String, Type)>),
|
||||
Table(Vec<(String, Type)>),
|
||||
ListStream,
|
||||
Any,
|
||||
Error,
|
||||
Binary,
|
||||
Custom(String),
|
||||
Signature,
|
||||
String,
|
||||
Table(Vec<(String, Type)>),
|
||||
}
|
||||
|
||||
impl Type {
|
||||
|
Loading…
Reference in New Issue
Block a user