This commit is contained in:
JT
2021-09-06 11:16:27 +12:00
parent 036c6a9a52
commit aaee3a8b61
10 changed files with 192 additions and 124 deletions

View File

@ -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![],
}
}
}

View File

@ -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
}
}

View File

@ -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),

View File

@ -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)
}
}

View File

@ -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"),
}
}
}

View File

@ -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),
}
}