Skip to content

Commit

Permalink
compliance fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Oct 5, 2024
1 parent 8bc5dfa commit 404e195
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
32 changes: 20 additions & 12 deletions src/v2_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,10 +682,10 @@ static DISALLOWED_IDENT_CHARS: [char; 11] =

pub(crate) fn is_disallowed_ident_char(c: char) -> bool {
DISALLOWED_IDENT_CHARS.iter().any(|ic| ic == &c)
|| NEWLINES.iter().copied().collect::<String>().contains(c)
|| UNICODE_SPACES.iter().any(|us| us == &c)
|| is_disallowed_unicode(c)
|| EQUALS_SIGNS.iter().any(|eq| eq == &c)
|| NEWLINES.iter().copied().collect::<String>().contains(c)
|| UNICODE_SPACES.iter().any(|us| us == &c)
|| is_disallowed_unicode(c)
|| EQUALS_SIGNS.iter().any(|eq| eq == &c)
}

/// `identifier-char := unicode - unicode-space - newline - [\\/(){};\[\]"#] - disallowed-literal-code-points - equals-sign`
Expand Down Expand Up @@ -822,10 +822,11 @@ fn escaped_char<'s>(input: &mut Input<'s>) -> PResult<char> {
)),
),
(
"u{",
"\\u{",
cut_err(take_while(1..6, AsChar::is_hex_digit)),
cut_err("}"),
)
.context(lbl("unicode escape char"))
.verify_map(|(_, hx, _)| {
let val = u32::from_str_radix(hx, 16)
.expect("Should have already been validated to be a hex string.");
Expand Down Expand Up @@ -961,6 +962,10 @@ mod string_tests {
string.parse(new_input("\"foo\"")).unwrap(),
Some(KdlValue::String("foo".into()))
);
assert_eq!(
string.parse(new_input("\"foo\\u{0a}\"")).unwrap(),
Some(KdlValue::String("foo\u{0a}".into()))
);
}

#[test]
Expand Down Expand Up @@ -1166,16 +1171,14 @@ fn comment<'s>(input: &mut Input<'s>) -> PResult<&'s str> {
}

static UNICODE_SPACES: [char; 19] = [
'\u{0009}', '\u{000B}', '\u{0020}', '\u{00A0}', '\u{1680}', '\u{2000}', '\u{2001}',
'\u{2002}', '\u{2003}', '\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}',
'\u{2009}', '\u{200A}', '\u{202F}', '\u{205F}', '\u{3000}',
'\u{0009}', '\u{000B}', '\u{0020}', '\u{00A0}', '\u{1680}', '\u{2000}', '\u{2001}', '\u{2002}',
'\u{2003}', '\u{2004}', '\u{2005}', '\u{2006}', '\u{2007}', '\u{2008}', '\u{2009}', '\u{200A}',
'\u{202F}', '\u{205F}', '\u{3000}',
];

/// `unicode-space := <See Table>`
fn unicode_space<'s>(input: &mut Input<'s>) -> PResult<()> {
one_of(UNICODE_SPACES)
.void()
.parse_next(input)
one_of(UNICODE_SPACES).void().parse_next(input)
}

/// `single-line-comment := '//' ^newline* (newline | eof)`
Expand Down Expand Up @@ -1266,7 +1269,10 @@ fn float_test() {
assert!(float.parse(new_input("_1234.56")).is_err());
assert!(float.parse(new_input("1234a.56")).is_err());
assert_eq!(
value.parse(new_input("2.5")).unwrap().map(|x| x.value().clone()),
value
.parse(new_input("2.5"))
.unwrap()
.map(|x| x.value().clone()),
Some(KdlValue::Base10Float(2.5))
);
}
Expand Down Expand Up @@ -1345,7 +1351,9 @@ fn test_hex() {
hex.parse(new_input("0xdeadbeef123_")).unwrap(),
KdlValue::Base16(0xdeadbeef123)
);
assert!(hex.parse(new_input("0xABCDEF0123456789abcdef")).is_err(), "i64 overflow");
assert!(hex.parse(new_input("0x_deadbeef123")).is_err());

assert!(hex.parse(new_input("0xbeefg1")).is_err());
}

Expand Down
1 change: 0 additions & 1 deletion tests/test_cases/expected_kdl/hex.kdl

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_cases/expected_kdl/hex_int.kdl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node 207698809136909011942886895
node 188900966474565
1 change: 0 additions & 1 deletion tests/test_cases/input/hex.kdl

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_cases/input/hex_int.kdl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node 0xABCDEF0123456789abcdef
node 0xABCDEF012345

0 comments on commit 404e195

Please sign in to comment.