mirror of
https://github.com/nushell/nushell
synced 2024-12-27 05:23:11 +00:00
Add '.' and '-' to restricted characters
This means that commands cannot start with these characters. However, we get the following benefits: * Negative numbers > -10 * Ranges with negative numbers > -10..-1 * Left-unbounded ranges > ..10
This commit is contained in:
parent
7ae4ca88b6
commit
56c8987e0f
2 changed files with 32 additions and 2 deletions
|
@ -2103,7 +2103,7 @@ pub fn parse_expression(
|
|||
|
||||
match bytes[0] {
|
||||
b'0' | b'1' | b'2' | b'3' | b'4' | b'5' | b'6' | b'7' | b'8' | b'9' | b'(' | b'{'
|
||||
| b'[' | b'$' | b'"' | b'\'' => parse_math_expression(working_set, spans),
|
||||
| b'[' | b'$' | b'"' | b'\'' | b'.' | b'-' => parse_math_expression(working_set, spans),
|
||||
_ => parse_call(working_set, spans, true),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -302,7 +302,6 @@ mod range {
|
|||
}
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn parse_left_unbounded_range() {
|
||||
let engine_state = EngineState::new();
|
||||
|
@ -364,4 +363,35 @@ mod range {
|
|||
_ => panic!("No match"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_negative_range() {
|
||||
let engine_state = EngineState::new();
|
||||
let mut working_set = StateWorkingSet::new(&engine_state);
|
||||
|
||||
let (block, err) = parse_source(&mut working_set, b"-10..-3", true);
|
||||
|
||||
assert!(err.is_none());
|
||||
assert!(block.len() == 1);
|
||||
match &block[0] {
|
||||
Statement::Pipeline(Pipeline { expressions }) => {
|
||||
assert!(expressions.len() == 1);
|
||||
assert!(matches!(
|
||||
expressions[0],
|
||||
Expression {
|
||||
expr: Expr::Range(
|
||||
Some(_),
|
||||
Some(_),
|
||||
RangeOperator {
|
||||
inclusion: RangeInclusion::Inclusive,
|
||||
..
|
||||
}
|
||||
),
|
||||
..
|
||||
}
|
||||
))
|
||||
}
|
||||
_ => panic!("No match"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue