Allow underscores in integers and floats (#7759)

# Description

This PR makes changes that allow underscores in numbers.

Example:
```nu
# allows underscores to be placed arbitrarily to enhance readability.
let pi = 3.1415_9265_3589_793

# works with integers
let num = 1_000_000_000_000
let fav_color = 0x68_9d_6a
```
This commit is contained in:
mike
2023-01-15 18:03:57 +03:00
committed by GitHub
parent 7221eb7f39
commit 56a9eab7eb
3 changed files with 73 additions and 48 deletions

View File

@ -64,6 +64,29 @@ pub fn parse_int() {
))
}
#[test]
pub fn parse_int_with_underscores() {
let engine_state = EngineState::new();
let mut working_set = StateWorkingSet::new(&engine_state);
let (block, err) = parse(&mut working_set, None, b"420_69_2023", true, &[]);
assert!(err.is_none());
assert_eq!(block.len(), 1);
let expressions = &block[0];
assert_eq!(expressions.len(), 1);
assert!(matches!(
expressions[0],
PipelineElement::Expression(
_,
Expression {
expr: Expr::Int(420692023),
..
}
)
))
}
#[test]
pub fn parse_binary_with_hex_format() {
let engine_state = EngineState::new();