diff --git a/src/attributes/attrlist.rs b/src/attributes/attrlist.rs index a1759fe..f93331e 100644 --- a/src/attributes/attrlist.rs +++ b/src/attributes/attrlist.rs @@ -25,9 +25,7 @@ impl<'src> Attrlist<'src> { /// the opening or closing square brackets for the attrlist. This is because /// the rules for closing brackets differ when parsing inline, macro, and /// block elements. - pub(crate) fn parse( - source: Span<'src>, - ) -> MatchAndWarnings<'src, Option>> { + pub(crate) fn parse(source: Span<'src>) -> MatchAndWarnings<'src, MatchedItem<'src, Self>> { let mut after = source; let mut attributes: Vec = vec![]; let mut parse_shorthand_items = true; @@ -88,10 +86,10 @@ impl<'src> Attrlist<'src> { } MatchAndWarnings { - item: Some(MatchedItem { + item: MatchedItem { item: Self { attributes, source }, after, - }), + }, warnings, } } diff --git a/src/blocks/macro.rs b/src/blocks/macro.rs index a202fd2..dbf2c34 100644 --- a/src/blocks/macro.rs +++ b/src/blocks/macro.rs @@ -71,30 +71,24 @@ impl<'src> MacroBlock<'src> { let attrlist = open_brace.after.slice(0..open_brace.after.len() - 1); // Note that we already checked that this line ends with a close brace. - let maw_attrlist = Attrlist::parse(attrlist); - - match maw_attrlist.item { - Some(attrlist) => MatchAndWarnings { - item: Some(MatchedItem { - item: Self { - name: name.item, - target: if target.item.is_empty() { - None - } else { - Some(target.item) - }, - attrlist: attrlist.item, - source: line.item, + let attrlist = Attrlist::parse(attrlist); + + MatchAndWarnings { + item: Some(MatchedItem { + item: Self { + name: name.item, + target: if target.item.is_empty() { + None + } else { + Some(target.item) }, + attrlist: attrlist.item.item, + source: line.item, + }, - after: line.after.discard_empty_lines(), - }), - warnings: maw_attrlist.warnings, - }, - None => MatchAndWarnings { - item: None, - warnings: maw_attrlist.warnings, - }, + after: line.after.discard_empty_lines(), + }), + warnings: attrlist.warnings, } } diff --git a/src/tests/asciidoc_lang/attributes/element_attributes.rs b/src/tests/asciidoc_lang/attributes/element_attributes.rs index f0419c7..7ed9616 100644 --- a/src/tests/asciidoc_lang/attributes/element_attributes.rs +++ b/src/tests/asciidoc_lang/attributes/element_attributes.rs @@ -82,9 +82,7 @@ mod attrlist { const ATTRLIST_EXAMPLE: &str = r#"first-positional,second-positional,named="value of named""#; - let mi = Attrlist::parse(Span::new(ATTRLIST_EXAMPLE)) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new(ATTRLIST_EXAMPLE)).unwrap_if_no_warnings(); assert_eq!( mi.item, diff --git a/src/tests/attributes/attrlist.rs b/src/tests/attributes/attrlist.rs index 34d6f98..b2a6b3c 100644 --- a/src/tests/attributes/attrlist.rs +++ b/src/tests/attributes/attrlist.rs @@ -14,18 +14,14 @@ use crate::{ #[test] fn impl_clone() { // Silly test to mark the #[derive(...)] line as covered. - let b1 = Attrlist::parse(Span::new("abc")) - .unwrap_if_no_warnings() - .unwrap(); + let b1 = Attrlist::parse(Span::new("abc")).unwrap_if_no_warnings(); let b2 = b1.item.clone(); assert_eq!(b1.item, b2); } #[test] fn empty_source() { - let mi = Attrlist::parse(Span::new("")) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new("")).unwrap_if_no_warnings(); assert_eq!( mi.item, @@ -75,9 +71,7 @@ fn empty_source() { #[test] fn only_positional_attributes() { - let mi = Attrlist::parse(Span::new("Sunset,300,400")) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new("Sunset,300,400")).unwrap_if_no_warnings(); assert_eq!( mi.item, @@ -311,9 +305,7 @@ fn only_positional_attributes() { #[test] fn only_named_attributes() { - let mi = Attrlist::parse(Span::new("alt=Sunset,width=300,height=400")) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new("alt=Sunset,width=300,height=400")).unwrap_if_no_warnings(); assert_eq!( mi.item, @@ -579,7 +571,7 @@ fn only_named_attributes() { fn err_unparsed_remainder_after_value() { let maw = Attrlist::parse(Span::new("alt=\"Sunset\"width=300")); - let mi = maw.item.as_ref().unwrap().clone(); + let mi = maw.item.clone(); assert_eq!( mi.item, @@ -642,7 +634,7 @@ fn err_unparsed_remainder_after_value() { fn propagates_error_from_element_attribute() { let maw = Attrlist::parse(Span::new("foo%#id")); - let mi = maw.item.as_ref().unwrap().clone(); + let mi = maw.item.clone(); assert_eq!( mi.item, @@ -723,9 +715,7 @@ mod id { #[test] fn via_shorthand_syntax() { - let mi = Attrlist::parse(Span::new("#goals")) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new("#goals")).unwrap_if_no_warnings(); assert_eq!( mi.item, @@ -796,9 +786,7 @@ mod id { #[test] fn via_named_attribute() { - let mi = Attrlist::parse(Span::new("foo=bar,id=goals")) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new("foo=bar,id=goals")).unwrap_if_no_warnings(); assert_eq!( mi.item, @@ -930,18 +918,14 @@ mod id { #[test] #[should_panic] fn via_block_anchor_syntax() { - let _pr = Attrlist::parse(Span::new("[goals]")) - .unwrap_if_no_warnings() - .unwrap(); + let _pr = Attrlist::parse(Span::new("[goals]")).unwrap_if_no_warnings(); // TO DO (#122): Parse block anchor syntax } #[test] fn shorthand_only_first_attribute() { - let mi = Attrlist::parse(Span::new("foo,blah#goals")) - .unwrap_if_no_warnings() - .unwrap(); + let mi = Attrlist::parse(Span::new("foo,blah#goals")).unwrap_if_no_warnings(); assert_eq!( mi.item, @@ -1012,7 +996,7 @@ mod id { fn err_double_comma() { let maw = Attrlist::parse(Span::new("alt=Sunset,width=300,,height=400")); - let mi = maw.item.unwrap().clone(); + let mi = maw.item.clone(); assert_eq!( mi.item,