[−][src]Function doctor::parse
pub fn parse(input: &str) -> Result<DocComment<'_>, Error>
Parses input
into a DocComment
struct representing the doc comment's AST.
Examples
use doctor::parse; use doctor::ast::{DocComment, Description, BodyItem, InlineTag, BlockTag}; assert_eq!( parse(r#"/** * This is a doc comment. * It contains an {@inlineTag with some body} in its description. * * @blockTag1 * @blockTag2 with body text * @blockTag3 with body text and {@inlineTag} */"# ), Ok(DocComment { description: Some(Description { body_items: vec![ BodyItem::TextSegment("This is a doc comment.\n"), BodyItem::TextSegment("It contains an "), BodyItem::InlineTag(InlineTag { name: "inlineTag", body_lines: vec!["with some body"], }), BodyItem::TextSegment("in its description.\n"), BodyItem::TextSegment("\n"), ] }), block_tags: vec![ BlockTag { name: "blockTag1", body_items: vec![] }, BlockTag { name: "blockTag2", body_items: vec![BodyItem::TextSegment("with body text\n"),] }, BlockTag { name: "blockTag3", body_items: vec![ BodyItem::TextSegment("with body text and "), BodyItem::InlineTag(InlineTag { name: "inlineTag", body_lines: vec![] }), BodyItem::TextSegment("\n"), ] }, ] }), );
Errors
If input
is not a valid doc comment, an error explaining where the parsing failed is returned.