Finer grained parsing and coloring command tail. (#1382)

This commit is contained in:
Andrés N. Robalino 2020-02-12 20:20:19 -05:00 committed by GitHub
parent c1bec3b443
commit 73312b506f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 9 deletions

View File

@ -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,

View File

@ -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);