diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 8e0b1e751..e61b9b112 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -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, } diff --git a/crates/nu-protocol/src/syntax_shape.rs b/crates/nu-protocol/src/syntax_shape.rs index 26a32fe46..898a828d1 100644 --- a/crates/nu-protocol/src/syntax_shape.rs +++ b/crates/nu-protocol/src/syntax_shape.rs @@ -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, Box), - /// 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>), - /// 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), + /// 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>), - /// A duration value is allowed, eg `19day` - Duration, + /// A custom shape with custom completion logic + Custom(Box, 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, Box), + + /// A list is allowed, eg `[first second]` + List(Box), + + /// 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), + /// 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, DeclId), - - /// One of a list of possible items, checked in order - OneOf(Vec), - - /// 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, } } } diff --git a/crates/nu-protocol/src/ty.rs b/crates/nu-protocol/src/ty.rs index 4cc478bfa..d607662e1 100644 --- a/crates/nu-protocol/src/ty.rs +++ b/crates/nu-protocol/src/ty.rs @@ -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), - 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 {