diff --git a/crates/nu-parser/src/parse/parser.rs b/crates/nu-parser/src/parse/parser.rs index 93905246a..65d212121 100644 --- a/crates/nu-parser/src/parse/parser.rs +++ b/crates/nu-parser/src/parse/parser.rs @@ -685,7 +685,27 @@ pub fn token_list(input: NomSpan) -> IResult> break; } - Ok((after_node_input, next_node)) => (after_node_input, next_node), + Ok((after_node_input, next_node)) => { + let mut new_nodes = Vec::new(); + for n in next_node { + match n.unspanned() { + Token::Flag(f) if f.kind == FlagKind::Shorthand && f.name > 1 => { + new_nodes.push(TokenTreeBuilder::spanned_shorthand( + Span::new(f.name.start(), f.name.start() + 1), + Span::new(n.span().start(), f.name.start() + 1), + )); + for t in f.name.start() + 1..f.name.end() { + new_nodes.push(TokenTreeBuilder::spanned_shorthand( + Span::for_char(t), + Span::for_char(t), + )) + } + } + _ => new_nodes.push(n), + } + } + (after_node_input, new_nodes) + } }; node_list.extend(next_nodes); @@ -1328,14 +1348,6 @@ mod tests { } } - #[test] - fn test_shorthand_flag() { - equal_tokens! { - - "-katz" -> b::token_list(vec![b::shorthand("katz")]) - } - } - #[test] fn test_variable() { equal_tokens! { diff --git a/crates/nu-source/src/meta.rs b/crates/nu-source/src/meta.rs index 14a5bbe1d..161c5cb08 100644 --- a/crates/nu-source/src/meta.rs +++ b/crates/nu-source/src/meta.rs @@ -6,6 +6,7 @@ use derive_new::new; use getset::Getters; use serde::Deserialize; use serde::Serialize; +use std::cmp::Ordering; use std::path::{Path, PathBuf}; /// Anchors represent a location that a value originated from. The value may have been loaded from a file, fetched from a website, or parsed from some text @@ -664,6 +665,18 @@ impl Span { } } +impl PartialOrd for Span { + fn partial_cmp(&self, other: &usize) -> Option { + (self.end - self.start).partial_cmp(other) + } +} + +impl PartialEq for Span { + fn eq(&self, other: &usize) -> bool { + (self.end - self.start) == *other + } +} + impl language_reporting::ReportingSpan for Span { fn with_start(&self, start: usize) -> Self { if self.end < start {