Add commands

This commit is contained in:
JT
2021-09-03 10:58:15 +12:00
parent 94687a7603
commit 7c8504ea24
23 changed files with 536 additions and 324 deletions

View File

@ -1,6 +1,6 @@
use crate::{BlockId, Example, ShellError, Signature, Value};
use crate::{ast::Call, BlockId, Example, ShellError, Signature, Value};
use super::CommandArgs;
use super::EvaluationContext;
pub trait Command {
fn name(&self) -> &str;
@ -15,19 +15,12 @@ pub trait Command {
""
}
fn run(&self, args: CommandArgs) -> Result<Value, ShellError>;
// fn run(&self, args: CommandArgs) -> Result<InputStream, ShellError> {
// let context = args.context.clone();
// let stream = self.run_with_actions(args)?;
// Ok(Box::new(crate::evaluate::internal::InternalIterator {
// context,
// input: stream,
// leftovers: InputStream::empty(),
// })
// .into_output_stream())
// }
fn run(
&self,
context: &EvaluationContext,
call: &Call,
input: Value,
) -> Result<Value, ShellError>;
fn is_binary(&self) -> bool {
false

View File

@ -1,7 +0,0 @@
use super::{EvaluationContext, UnevaluatedCallInfo};
pub struct CommandArgs {
pub context: EvaluationContext,
pub call_info: UnevaluatedCallInfo,
pub input: crate::Value,
}

View File

@ -1,11 +1,9 @@
mod call_info;
mod command;
mod command_args;
mod engine_state;
mod evaluation_context;
pub use call_info::*;
pub use command::*;
pub use command_args::*;
pub use engine_state::*;
pub use evaluation_context::*;

View File

@ -1,6 +1,9 @@
use crate::ast::Call;
use crate::engine::Command;
use crate::engine::EvaluationContext;
use crate::BlockId;
use crate::SyntaxShape;
use crate::Value;
use crate::VarId;
#[derive(Debug, Clone)]
@ -315,7 +318,12 @@ impl Command for Predeclaration {
&self.signature.usage
}
fn run(&self, _args: crate::engine::CommandArgs) -> Result<crate::Value, crate::ShellError> {
fn run(
&self,
_context: &EvaluationContext,
_call: &Call,
_input: Value,
) -> Result<crate::Value, crate::ShellError> {
panic!("Internal error: can't run a predeclaration without a body")
}
}
@ -338,7 +346,12 @@ impl Command for BlockCommand {
&self.signature.usage
}
fn run(&self, _args: crate::engine::CommandArgs) -> Result<crate::Value, crate::ShellError> {
fn run(
&self,
_context: &EvaluationContext,
_call: &Call,
_input: Value,
) -> Result<crate::Value, crate::ShellError> {
panic!("Internal error: can't run custom command with 'run', use block_id");
}