mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Finer grained parsing and coloring command tail. (#1382)
This commit is contained in:
parent
c1bec3b443
commit
73312b506f
@ -363,16 +363,15 @@ impl SpannedToken {
|
||||
|
||||
pub(crate) fn as_flag(&self, value: &str, short: Option<char>, source: &Text) -> Option<Flag> {
|
||||
match self.unspanned() {
|
||||
Token::Flag(flag @ Flag { .. }) => {
|
||||
Token::Flag(flag) => {
|
||||
let name = flag.name().slice(source);
|
||||
let is_long = flag.kind == FlagKind::Longhand && value == name;
|
||||
let is_short = flag.kind == FlagKind::Shorthand
|
||||
&& short.is_some()
|
||||
&& short == name.chars().nth(0);
|
||||
if is_long || is_short {
|
||||
Some(*flag)
|
||||
} else {
|
||||
None
|
||||
|
||||
match flag.kind {
|
||||
FlagKind::Longhand if value == name => Some(*flag),
|
||||
FlagKind::Shorthand if short.is_some() && short == name.chars().next() => {
|
||||
Some(*flag)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
|
@ -42,6 +42,7 @@ pub fn parse_command_tail(
|
||||
tail.color_shape(flag.color(flag.span));
|
||||
tail.move_to(pos);
|
||||
tail.expand_infallible(MaybeSpaceShape);
|
||||
tail.move_to(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -86,6 +87,7 @@ pub fn parse_command_tail(
|
||||
Ok(expr) => {
|
||||
named.insert_optional(name, Some(expr));
|
||||
rest_signature.remove_named(name);
|
||||
tail.move_to(pos);
|
||||
}
|
||||
Err(_) => {
|
||||
found_error = Some(ParseError::argument_error(
|
||||
@ -192,6 +194,8 @@ pub fn continue_parsing_positionals(
|
||||
) -> Result<Vec<SpannedExpression>, ParseError> {
|
||||
let mut positional = vec![];
|
||||
|
||||
eat_any_whitespace(tail);
|
||||
|
||||
for arg in &config.positional {
|
||||
trace!(target: "nu::parse::trace_remaining", "Processing positional {:?}", arg);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user