diff --git a/crates/nu-parser/src/commands.rs b/crates/nu-parser/src/commands.rs index 3e94dd7c2f..8bd5cc4ceb 100644 --- a/crates/nu-parser/src/commands.rs +++ b/crates/nu-parser/src/commands.rs @@ -1,11 +1,12 @@ pub mod classified; +use crate::commands::classified::external::{ExternalArg, ExternalArgs, ExternalCommand}; use crate::commands::classified::ClassifiedCommand; use crate::hir::expand_external_tokens::ExternalTokensShape; use crate::hir::syntax_shape::{expand_syntax, ExpandContext}; use crate::hir::tokens_iterator::TokensIterator; use nu_errors::ParseError; -use nu_source::{b, DebugDocBuilder, HasSpan, PrettyDebug, Span, Spanned, Tag, Tagged}; +use nu_source::{Spanned, Tagged}; // Classify this command as an external command, which doesn't give special meaning // to nu syntactic constructs, and passes all arguments to the external command as @@ -32,67 +33,3 @@ pub(crate) fn external_command( }, })) } - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct ExternalArg { - pub arg: String, - pub tag: Tag, -} - -impl std::ops::Deref for ExternalArg { - type Target = str; - - fn deref(&self) -> &str { - &self.arg - } -} - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct ExternalArgs { - pub list: Vec, - pub span: Span, -} - -impl ExternalArgs { - pub fn iter(&self) -> impl Iterator { - self.list.iter() - } -} - -impl std::ops::Deref for ExternalArgs { - type Target = [ExternalArg]; - - fn deref(&self) -> &[ExternalArg] { - &self.list - } -} - -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct ExternalCommand { - pub name: String, - - pub name_tag: Tag, - pub args: ExternalArgs, -} - -impl PrettyDebug for ExternalCommand { - fn pretty(&self) -> DebugDocBuilder { - b::typed( - "external command", - b::description(&self.name) - + b::preceded( - b::space(), - b::intersperse( - self.args.iter().map(|a| b::primitive(format!("{}", a.arg))), - b::space(), - ), - ), - ) - } -} - -impl HasSpan for ExternalCommand { - fn span(&self) -> Span { - self.name_tag.span.until(self.args.span) - } -} diff --git a/crates/nu-parser/src/commands/classified.rs b/crates/nu-parser/src/commands/classified.rs index 3454ce5a75..7a3409db9e 100644 --- a/crates/nu-parser/src/commands/classified.rs +++ b/crates/nu-parser/src/commands/classified.rs @@ -1,8 +1,12 @@ -use crate::commands::ExternalCommand; +pub mod external; +pub mod internal; + +use crate::commands::classified::external::ExternalCommand; +use crate::commands::classified::internal::InternalCommand; use crate::hir; use crate::parse::token_tree::TokenNode; use derive_new::new; -use nu_source::{b, DebugDocBuilder, HasSpan, PrettyDebugWithSource, Span, Tag}; +use nu_source::{b, DebugDocBuilder, HasSpan, PrettyDebugWithSource, Span}; #[derive(Debug, Clone, Eq, PartialEq)] pub enum ClassifiedCommand { @@ -36,30 +40,6 @@ impl HasSpan for ClassifiedCommand { } } -#[derive(new, Debug, Clone, Eq, PartialEq)] -pub struct InternalCommand { - pub name: String, - pub name_tag: Tag, - pub args: hir::Call, -} - -impl PrettyDebugWithSource for InternalCommand { - fn pretty_debug(&self, source: &str) -> DebugDocBuilder { - b::typed( - "internal command", - b::description(&self.name) + b::space() + self.args.pretty_debug(source), - ) - } -} - -impl HasSpan for InternalCommand { - fn span(&self) -> Span { - let start = self.name_tag.span; - - start.until(self.args.span) - } -} - #[derive(new, Debug, Eq, PartialEq)] pub(crate) struct DynamicCommand { pub(crate) args: hir::Call, diff --git a/crates/nu-parser/src/commands/classified/external.rs b/crates/nu-parser/src/commands/classified/external.rs index e69de29bb2..fd71291418 100644 --- a/crates/nu-parser/src/commands/classified/external.rs +++ b/crates/nu-parser/src/commands/classified/external.rs @@ -0,0 +1,65 @@ +use nu_source::{b, DebugDocBuilder, HasSpan, PrettyDebug, Span, Tag}; + +#[derive(Debug, Clone, Eq, PartialEq)] +pub struct ExternalArg { + pub arg: String, + pub tag: Tag, +} + +impl std::ops::Deref for ExternalArg { + type Target = str; + + fn deref(&self) -> &str { + &self.arg + } +} + +#[derive(Debug, Clone, Eq, PartialEq)] +pub struct ExternalArgs { + pub list: Vec, + pub span: Span, +} + +impl ExternalArgs { + pub fn iter(&self) -> impl Iterator { + self.list.iter() + } +} + +impl std::ops::Deref for ExternalArgs { + type Target = [ExternalArg]; + + fn deref(&self) -> &[ExternalArg] { + &self.list + } +} + +#[derive(Debug, Clone, Eq, PartialEq)] +pub struct ExternalCommand { + pub name: String, + + pub name_tag: Tag, + pub args: ExternalArgs, +} + +impl PrettyDebug for ExternalCommand { + fn pretty(&self) -> DebugDocBuilder { + b::typed( + "external command", + b::description(&self.name) + + b::preceded( + b::space(), + b::intersperse( + self.args.iter().map(|a| b::primitive(format!("{}", a.arg))), + b::space(), + ), + ), + ) + } +} + +impl HasSpan for ExternalCommand { + fn span(&self) -> Span { + self.name_tag.span.until(self.args.span) + } +} diff --git a/crates/nu-parser/src/commands/classified/internal.rs b/crates/nu-parser/src/commands/classified/internal.rs new file mode 100644 index 0000000000..399eab0c63 --- /dev/null +++ b/crates/nu-parser/src/commands/classified/internal.rs @@ -0,0 +1,28 @@ +use crate::hir; + +use derive_new::new; +use nu_source::{b, DebugDocBuilder, HasSpan, PrettyDebugWithSource, Span, Tag}; + +#[derive(new, Debug, Clone, Eq, PartialEq)] +pub struct InternalCommand { + pub name: String, + pub name_tag: Tag, + pub args: hir::Call, +} + +impl PrettyDebugWithSource for InternalCommand { + fn pretty_debug(&self, source: &str) -> DebugDocBuilder { + b::typed( + "internal command", + b::description(&self.name) + b::space() + self.args.pretty_debug(source), + ) + } +} + +impl HasSpan for InternalCommand { + fn span(&self) -> Span { + let start = self.name_tag.span; + + start.until(self.args.span) + } +} diff --git a/crates/nu-parser/src/hir/baseline_parse/tests.rs b/crates/nu-parser/src/hir/baseline_parse/tests.rs index d6d3212563..71e013d345 100644 --- a/crates/nu-parser/src/hir/baseline_parse/tests.rs +++ b/crates/nu-parser/src/hir/baseline_parse/tests.rs @@ -1,4 +1,4 @@ -use crate::commands::classified::{ClassifiedCommand, InternalCommand}; +use crate::commands::classified::{internal::InternalCommand, ClassifiedCommand}; use crate::hir::TokensIterator; use crate::hir::{self, named::NamedValue, syntax_shape::*, NamedArguments}; use crate::parse::files::Files; diff --git a/crates/nu-parser/src/hir/syntax_shape.rs b/crates/nu-parser/src/hir/syntax_shape.rs index 6861ada43e..7cf84faa1b 100644 --- a/crates/nu-parser/src/hir/syntax_shape.rs +++ b/crates/nu-parser/src/hir/syntax_shape.rs @@ -2,7 +2,8 @@ mod block; mod expression; pub mod flat_shape; -use crate::commands::classified::{ClassifiedCommand, ClassifiedPipeline, InternalCommand}; +use crate::commands::classified::internal::InternalCommand; +use crate::commands::classified::{ClassifiedCommand, ClassifiedPipeline}; use crate::commands::external_command; use crate::hir; use crate::hir::expand_external_tokens::ExternalTokensShape; diff --git a/crates/nu-parser/src/lib.rs b/crates/nu-parser/src/lib.rs index f1e8baca90..99910b64c0 100644 --- a/crates/nu-parser/src/lib.rs +++ b/crates/nu-parser/src/lib.rs @@ -3,8 +3,9 @@ pub mod hir; pub mod parse; pub mod parse_command; -pub use crate::commands::classified::{ClassifiedCommand, ClassifiedPipeline, InternalCommand}; -pub use crate::commands::ExternalCommand; +pub use crate::commands::classified::{ + external::ExternalCommand, internal::InternalCommand, ClassifiedCommand, ClassifiedPipeline, +}; pub use crate::hir::syntax_shape::flat_shape::FlatShape; pub use crate::hir::syntax_shape::{ expand_syntax, ExpandContext, ExpandSyntax, PipelineShape, SignatureRegistry,