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:
Jakub Žádník 2021-09-05 20:33:53 +03:00
parent 7ae4ca88b6
commit 56c8987e0f
2 changed files with 32 additions and 2 deletions

View File

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

View File

@ -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"),
}
}
}