mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 09:53:43 +01:00
Add support for compound shorthand flags (#1414)
* Break multicharacter shorthand flags into single character flags * Remove shorthand flag test
This commit is contained in:
parent
2a8cb24309
commit
6d096206b6
@ -685,7 +685,27 @@ pub fn token_list(input: NomSpan) -> IResult<NomSpan, Spanned<Vec<SpannedToken>>
|
||||
|
||||
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! {
|
||||
<nodes>
|
||||
"-katz" -> b::token_list(vec![b::shorthand("katz")])
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_variable() {
|
||||
equal_tokens! {
|
||||
|
@ -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<usize> for Span {
|
||||
fn partial_cmp(&self, other: &usize) -> Option<Ordering> {
|
||||
(self.end - self.start).partial_cmp(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<usize> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user