From a4a5482a3d16dac997d60b5f7cc5f4d216cfda09 Mon Sep 17 00:00:00 2001 From: Geoffroy Couprie Date: Tue, 17 Feb 2015 16:34:44 +0100 Subject: [PATCH] Adapt the INI parser to optional parsing in chain --- tests/ini.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/ini.rs b/tests/ini.rs index a3f85ab..697fa1d 100644 --- a/tests/ini.rs +++ b/tests/ini.rs @@ -31,22 +31,26 @@ fn parameter_parser(input: &[u8]) -> IResult<&[u8], &str> { alphanumeric(input).map_res(str::from_utf8) } -o!(comment_body <&[u8], &[u8]> semicolon ~ [ not_line_ending]); +o!(comment_body <&[u8], &[u8]> semicolon ~ [ not_line_ending ]); o!(comment <&[u8], ()> comment_body ~ line_ending ~ [ empty_result ]); opt!(opt_comment <&[u8], &[u8]> comment_body); -o!(category <&[u8], &str> lsb ~ [ category_name ] ~ rsb ~ opt_multispace); -opt!(opt_multispace <&[u8], &[u8]> multispace); -opt!(opt_space <&[u8], &[u8]> space); +chain!(category <&[u8], &str>, + lsb ~ + name: category_name ~ + rsb ~ + multispace? , + ||{ name } +); chain!(key_value <&[u8],(&str,&str)>, key: parameter_parser ~ - opt_space ~ + space? ~ equal ~ - opt_space ~ + space? ~ val: value_parser ~ - opt_space ~ - opt_comment ~ - opt_multispace , + space? ~ + comment_body? ~ + multispace? , ||{(key, val)} );