mirror of
https://github.com/nushell/nushell.git
synced 2025-03-30 01:28:11 +01:00
Fix fmt and small cleaning in nu-parser (#3033)
* parse_unit: reduce indentation in loop * fix fmt: crates/nu-parser/src/lex/tests.rs
This commit is contained in:
parent
e3a273cf73
commit
7f7e8465da
@ -218,7 +218,10 @@ mod lite_parse {
|
|||||||
#[test]
|
#[test]
|
||||||
fn incomplete_result() {
|
fn incomplete_result() {
|
||||||
let (result, err) = lex("my_command \"foo' --test", 10);
|
let (result, err) = lex("my_command \"foo' --test", 10);
|
||||||
assert!(matches!(err.unwrap().reason(), nu_errors::ParseErrorReason::Eof { .. }));
|
assert!(matches!(
|
||||||
|
err.unwrap().reason(),
|
||||||
|
nu_errors::ParseErrorReason::Eof { .. }
|
||||||
|
));
|
||||||
let (result, _) = block(result);
|
let (result, _) = block(result);
|
||||||
|
|
||||||
assert_eq!(result.block.len(), 1);
|
assert_eq!(result.block.len(), 1);
|
||||||
|
@ -346,27 +346,26 @@ fn parse_unit(lite_arg: &Spanned<String>) -> (SpannedExpression, Option<ParseErr
|
|||||||
|
|
||||||
for unit_group in unit_groups.iter() {
|
for unit_group in unit_groups.iter() {
|
||||||
for unit in unit_group.1.iter() {
|
for unit in unit_group.1.iter() {
|
||||||
if lite_arg.item.ends_with(unit) {
|
if !lite_arg.item.ends_with(unit) {
|
||||||
let mut lhs = lite_arg.item.clone();
|
continue;
|
||||||
|
}
|
||||||
|
let mut lhs = lite_arg.item.clone();
|
||||||
|
|
||||||
for _ in 0..unit.len() {
|
for _ in 0..unit.len() {
|
||||||
lhs.pop();
|
lhs.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// these units are allowed to be signed
|
// these units are allowed to be signed
|
||||||
if let Ok(x) = lhs.parse::<i64>() {
|
if let Ok(x) = lhs.parse::<i64>() {
|
||||||
let lhs_span =
|
let lhs_span = Span::new(lite_arg.span.start(), lite_arg.span.start() + lhs.len());
|
||||||
Span::new(lite_arg.span.start(), lite_arg.span.start() + lhs.len());
|
let unit_span = Span::new(lite_arg.span.start() + lhs.len(), lite_arg.span.end());
|
||||||
let unit_span =
|
return (
|
||||||
Span::new(lite_arg.span.start() + lhs.len(), lite_arg.span.end());
|
SpannedExpression::new(
|
||||||
return (
|
Expression::unit(x.spanned(lhs_span), unit_group.0.spanned(unit_span)),
|
||||||
SpannedExpression::new(
|
lite_arg.span,
|
||||||
Expression::unit(x.spanned(lhs_span), unit_group.0.spanned(unit_span)),
|
),
|
||||||
lite_arg.span,
|
None,
|
||||||
),
|
);
|
||||||
None,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user