From 0fc8e7b2da9a5773185357f166de0650a6e0ff33 Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 1 Jun 2024 13:22:51 +0200 Subject: [PATCH 1/2] trailing commas: Don't require whitespace after them --- src/parse/diag.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parse/diag.rs b/src/parse/diag.rs index 47575c4..67a04bd 100644 --- a/src/parse/diag.rs +++ b/src/parse/diag.rs @@ -46,7 +46,7 @@ fn wrapws_strings<'a>( } fn opt_comma_tag<'a>(t: &'a str) -> impl FnMut(&'a str) -> IResult<&'a str, &'a str> { - alt((tag(t), map(tuple((tag(","), ws, tag(t))), |(_, (), f)| f))) + alt((tag(t), map(tuple((tag(","), many0_count(ws::<()>), tag(t))), |(_, _, f)| f))) } /// Recognizes one or more binary numerical characters: 0, 1 From d7cc8674537ed77bccec9dee3892fb3662c3d7b2 Mon Sep 17 00:00:00 2001 From: chrysn Date: Sat, 1 Jun 2024 13:29:54 +0200 Subject: [PATCH 2/2] tests: Cover trailing commas --- tests/array.rs | 16 ++++++++++++++++ tests/map.rs | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tests/array.rs b/tests/array.rs index 6e489f1..390024b 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -39,6 +39,22 @@ testcases! { } } + hello_trailingcomma(diag2value) { + DataItem::Array { + data: vec![ + DataItem::TextString(TextString { + data: "hello".into(), + bitwidth: IntegerWidth::Unknown, + }), + ], + bitwidth: Some(IntegerWidth::Unknown), + }, + { + r#"["hello",]"#, + r#"["hello",]"#, + } + } + hello_world(diag2value, value2diag) { DataItem::Array { data: vec![ diff --git a/tests/map.rs b/tests/map.rs index ab43433..d5be41d 100644 --- a/tests/map.rs +++ b/tests/map.rs @@ -39,6 +39,28 @@ testcases! { } } + hello_world_trailingcomma(diag2value) { + DataItem::Map { + data: vec![ + ( + DataItem::TextString(TextString { + data: "hello".into(), + bitwidth: IntegerWidth::Unknown, + }), + DataItem::TextString(TextString { + data: "world".into(), + bitwidth: IntegerWidth::Unknown, + }), + ), + ], + bitwidth: Some(IntegerWidth::Unknown), + }, + { + r#"{"hello":"world",}"#, + r#"{"hello": "world",}"#, + } + } + non_alpha(diag2value, value2diag) { DataItem::Map { data: vec![