fix(numbers): Fix parsing of non-integer and non-decimal numbers (#13)

This commit is contained in:
jam1garner 2021-05-08 17:36:26 -04:00 committed by Kat Marchán
parent 9bc5363bb5
commit c1b7c25c00
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
2 changed files with 26 additions and 1 deletions

View File

@ -259,11 +259,11 @@ fn raw_string(input: &str) -> IResult<&str, &str, KdlParseError<&str>> {
/// `number := decimal | hex | octal | binary`
fn number(input: &str) -> IResult<&str, KdlValue, KdlParseError<&str>> {
alt((
map(integer, KdlValue::Int),
map(hexadecimal, KdlValue::Int),
map(octal, KdlValue::Int),
map(binary, KdlValue::Int),
map(float, KdlValue::Float),
map(integer, KdlValue::Int),
))(input)
}

View File

@ -57,6 +57,31 @@ macro_rules! nodes {
() => { vec![] }
}
const NUMBERS: &str = r#"
hex 0x32;
float 0.5;
binary 0b0110;
octal 0o755;
bignum 1_000_000;
scientific 1.234e-10;
"#;
#[test]
fn test_numbers() {
let doc = parse_document(NUMBERS);
assert_eq!(
doc,
Ok(nodes! {
hex 0x32;
float 0.5;
binary 0b0110;
octal 0o755;
bignum 1_000_000;
scientific 1.234e-10;
})
);
}
#[test]
fn test_ci() {
let doc = parse_document(include_str!("../examples/ci.kdl"));