org_rust_parser/element/
paragraph.rs1use crate::node_pool::NodeID;
2use crate::parse::parse_object;
3use crate::types::{Cursor, ParseOpts, Parseable, Parser, Result};
4
5#[derive(Debug, Clone)]
6pub struct Paragraph(pub Vec<NodeID>);
7
8impl<'a> Parseable<'a> for Paragraph {
9 fn parse(
10 parser: &mut Parser<'a>,
11 mut cursor: Cursor<'a>,
12 parent: Option<NodeID>,
13 mut parse_opts: ParseOpts,
14 ) -> Result<NodeID> {
15 let start = cursor.index;
16 let mut content_vec: Vec<NodeID> = Vec::new();
17 parse_opts.from_paragraph = true;
18
19 let new_id = parser.pool.reserve_id();
21
22 while let Ok(id) = parse_object(parser, cursor, Some(new_id), parse_opts) {
23 cursor.index = parser.pool[id].end;
24 content_vec.push(id);
25 }
26
27 Ok(parser.alloc_with_id(
28 Paragraph(content_vec),
29 start,
30 cursor.index + 1, parent,
32 new_id,
33 ))
34 }
35}