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