2019-11-24 23:19:12 +01:00
|
|
|
use crate::parser::{hir, TokenNode};
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
mod dynamic;
|
|
|
|
mod external;
|
|
|
|
mod internal;
|
|
|
|
mod pipeline;
|
|
|
|
|
|
|
|
#[allow(unused_imports)]
|
|
|
|
pub(crate) use dynamic::Command as DynamicCommand;
|
2019-11-25 00:16:45 +01:00
|
|
|
#[allow(unused_imports)]
|
2019-11-26 04:25:12 +01:00
|
|
|
pub(crate) use external::{Command as ExternalCommand, ExternalArg, ExternalArgs, StreamNext};
|
2019-11-24 23:19:12 +01:00
|
|
|
pub(crate) use internal::Command as InternalCommand;
|
|
|
|
pub(crate) use pipeline::Pipeline as ClassifiedPipeline;
|
|
|
|
|
|
|
|
pub(crate) struct ClassifiedInputStream {
|
|
|
|
pub(crate) objects: InputStream,
|
|
|
|
pub(crate) stdin: Option<std::fs::File>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ClassifiedInputStream {
|
|
|
|
pub(crate) fn new() -> ClassifiedInputStream {
|
|
|
|
ClassifiedInputStream {
|
2019-11-26 04:25:12 +01:00
|
|
|
objects: vec![UntaggedValue::nothing().into_untagged_value()].into(),
|
2019-11-24 23:19:12 +01:00
|
|
|
stdin: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn from_input_stream(stream: impl Into<InputStream>) -> ClassifiedInputStream {
|
|
|
|
ClassifiedInputStream {
|
|
|
|
objects: stream.into(),
|
|
|
|
stdin: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn from_stdout(stdout: std::fs::File) -> ClassifiedInputStream {
|
|
|
|
ClassifiedInputStream {
|
|
|
|
objects: VecDeque::new().into(),
|
|
|
|
stdin: Some(stdout),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2019-11-26 04:25:12 +01:00
|
|
|
pub enum ClassifiedCommand {
|
2019-11-24 23:19:12 +01:00
|
|
|
#[allow(unused)]
|
|
|
|
Expr(TokenNode),
|
|
|
|
#[allow(unused)]
|
2019-11-26 04:25:12 +01:00
|
|
|
Dynamic(hir::Call),
|
|
|
|
Internal(InternalCommand),
|
2019-11-24 23:19:12 +01:00
|
|
|
External(ExternalCommand),
|
|
|
|
}
|
|
|
|
|
2019-11-26 04:25:12 +01:00
|
|
|
impl PrettyDebugWithSource for ClassifiedCommand {
|
|
|
|
fn pretty_debug(&self, source: &str) -> DebugDocBuilder {
|
2019-11-24 23:19:12 +01:00
|
|
|
match self {
|
2019-11-26 04:25:12 +01:00
|
|
|
ClassifiedCommand::Expr(token) => b::typed("command", token.pretty_debug(source)),
|
|
|
|
ClassifiedCommand::Dynamic(call) => b::typed("command", call.pretty_debug(source)),
|
|
|
|
ClassifiedCommand::Internal(internal) => internal.pretty_debug(source),
|
|
|
|
ClassifiedCommand::External(external) => external.pretty_debug(source),
|
2019-11-24 23:19:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl HasSpan for ClassifiedCommand {
|
|
|
|
fn span(&self) -> Span {
|
|
|
|
match self {
|
|
|
|
ClassifiedCommand::Expr(node) => node.span(),
|
|
|
|
ClassifiedCommand::Internal(command) => command.span(),
|
|
|
|
ClassifiedCommand::Dynamic(call) => call.span,
|
|
|
|
ClassifiedCommand::External(command) => command.span(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|