forked from extern/nushell
Add support for module imports
This commit is contained in:
13
crates/nu-protocol/src/ast/import_pattern.rs
Normal file
13
crates/nu-protocol/src/ast/import_pattern.rs
Normal file
@ -0,0 +1,13 @@
|
||||
use crate::Span;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ImportPatternMember {
|
||||
Glob { span: Span },
|
||||
Name { name: Vec<u8>, span: Span },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ImportPattern {
|
||||
pub head: Vec<u8>,
|
||||
pub members: Vec<ImportPatternMember>,
|
||||
}
|
@ -3,6 +3,7 @@ mod call;
|
||||
mod cell_path;
|
||||
mod expr;
|
||||
mod expression;
|
||||
mod import_pattern;
|
||||
mod operator;
|
||||
mod pipeline;
|
||||
mod statement;
|
||||
@ -12,6 +13,7 @@ pub use call::*;
|
||||
pub use cell_path::*;
|
||||
pub use expr::*;
|
||||
pub use expression::*;
|
||||
pub use import_pattern::*;
|
||||
pub use operator::*;
|
||||
pub use pipeline::*;
|
||||
pub use statement::*;
|
||||
|
@ -33,6 +33,9 @@ pub enum SyntaxShape {
|
||||
/// A glob pattern is allowed, eg `foo*`
|
||||
GlobPattern,
|
||||
|
||||
/// A module path pattern used for imports
|
||||
ImportPattern,
|
||||
|
||||
/// A block is allowed, eg `{start this thing}`
|
||||
Block(Option<Vec<SyntaxShape>>),
|
||||
|
||||
@ -87,6 +90,7 @@ impl SyntaxShape {
|
||||
SyntaxShape::Filesize => Type::Filesize,
|
||||
SyntaxShape::FullCellPath => Type::Unknown,
|
||||
SyntaxShape::GlobPattern => Type::String,
|
||||
SyntaxShape::ImportPattern => Type::Unknown,
|
||||
SyntaxShape::Int => Type::Int,
|
||||
SyntaxShape::List(x) => {
|
||||
let contents = x.to_type();
|
||||
|
@ -177,9 +177,9 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn follow_cell_path(self, column_path: &[PathMember]) -> Result<Value, ShellError> {
|
||||
pub fn follow_cell_path(self, cell_path: &[PathMember]) -> Result<Value, ShellError> {
|
||||
let mut current = self;
|
||||
for member in column_path {
|
||||
for member in cell_path {
|
||||
// FIXME: this uses a few extra clones for simplicity, but there may be a way
|
||||
// to traverse the path without them
|
||||
match member {
|
||||
|
Reference in New Issue
Block a user