mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:55:07 +02:00
WIP
This commit is contained in:
@ -1,9 +1,12 @@
|
||||
use std::ops::{Index, IndexMut};
|
||||
|
||||
use crate::Signature;
|
||||
|
||||
use super::Statement;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Block {
|
||||
pub signature: Box<Signature>,
|
||||
pub stmts: Vec<Statement>,
|
||||
}
|
||||
|
||||
@ -39,6 +42,9 @@ impl Default for Block {
|
||||
|
||||
impl Block {
|
||||
pub fn new() -> Self {
|
||||
Self { stmts: vec![] }
|
||||
Self {
|
||||
signature: Box::new(Signature::new("")),
|
||||
stmts: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,8 +50,8 @@ pub trait Command {
|
||||
false
|
||||
}
|
||||
|
||||
// If command is a custom command i.e. def blah [] { }, get the block id
|
||||
fn get_custom_command(&self) -> Option<BlockId> {
|
||||
// If command is a block i.e. def blah [] { }, get the block id
|
||||
fn get_block_id(&self) -> Option<BlockId> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{Span, Type};
|
||||
use crate::{ast::Operator, Span, Type};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ShellError {
|
||||
OperatorMismatch {
|
||||
op_span: Span,
|
||||
@ -9,7 +9,9 @@ pub enum ShellError {
|
||||
rhs_ty: Type,
|
||||
rhs_span: Span,
|
||||
},
|
||||
Unsupported(Span),
|
||||
UnsupportedOperator(Operator, Span),
|
||||
UnknownOperator(String, Span),
|
||||
ExternalNotSupported(Span),
|
||||
InternalError(String),
|
||||
VariableNotFound(Span),
|
||||
CantConvert(String, Span),
|
||||
|
@ -350,7 +350,7 @@ impl Command for BlockCommand {
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
self.signature.clone()
|
||||
panic!("Internal error: can't get signature with 'signature', use block_id");
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
@ -366,7 +366,7 @@ impl Command for BlockCommand {
|
||||
panic!("Internal error: can't run custom command with 'run', use block_id");
|
||||
}
|
||||
|
||||
fn get_custom_command(&self) -> Option<BlockId> {
|
||||
fn get_block_id(&self) -> Option<BlockId> {
|
||||
Some(self.block_id)
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ pub enum Type {
|
||||
RowStream,
|
||||
ValueStream,
|
||||
Unknown,
|
||||
Error,
|
||||
}
|
||||
|
||||
impl Display for Type {
|
||||
@ -41,6 +42,7 @@ impl Display for Type {
|
||||
Type::ValueStream => write!(f, "value stream"),
|
||||
Type::RowStream => write!(f, "row stream"),
|
||||
Type::Unknown => write!(f, "unknown"),
|
||||
Type::Error => write!(f, "error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +158,9 @@ pub enum Value {
|
||||
Nothing {
|
||||
span: Span,
|
||||
},
|
||||
Error {
|
||||
err: ShellError,
|
||||
},
|
||||
}
|
||||
|
||||
impl Value {
|
||||
@ -181,6 +184,7 @@ impl Value {
|
||||
Value::RowStream { span, .. } => *span,
|
||||
Value::ValueStream { span, .. } => *span,
|
||||
Value::Nothing { span, .. } => *span,
|
||||
Value::Error { .. } => Span::unknown(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -197,6 +201,7 @@ impl Value {
|
||||
Value::Table { span, .. } => *span = new_span,
|
||||
Value::Block { span, .. } => *span = new_span,
|
||||
Value::Nothing { span, .. } => *span = new_span,
|
||||
Value::Error { .. } => {}
|
||||
}
|
||||
|
||||
self
|
||||
@ -215,6 +220,7 @@ impl Value {
|
||||
Value::Block { .. } => Type::Block,
|
||||
Value::ValueStream { .. } => Type::ValueStream,
|
||||
Value::RowStream { .. } => Type::RowStream,
|
||||
Value::Error { .. } => Type::Error,
|
||||
}
|
||||
}
|
||||
|
||||
@ -264,6 +270,7 @@ impl Value {
|
||||
} => stream.into_string(headers),
|
||||
Value::Block { val, .. } => format!("<Block {}>", val),
|
||||
Value::Nothing { .. } => String::new(),
|
||||
Value::Error { err } => format!("{:?}", err),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user