org_rust_parser/object/
node_property.rs1use std::borrow::Cow;
2
3use crate::constants::COLON;
4use crate::element::PropertyDrawer;
5use crate::types::{Cursor, Result};
6use std::fmt::Write;
7
8#[derive(Debug, Clone)]
9pub struct NodeProperty<'a> {
10 pub name: &'a str,
11 pub val: Cow<'a, str>,
12}
13
14pub(crate) fn parse_node_property<'a>(
15 mut cursor: Cursor<'a>,
16 properties: &mut PropertyDrawer<'a>,
17 ) -> Result<usize> {
19 cursor.curr_valid()?;
20 let start = cursor.index;
21 cursor.skip_ws();
22 cursor.word(":")?;
23
24 let name_match = cursor.fn_until(|chr| chr == COLON || chr.is_ascii_whitespace())?;
25 let name = name_match.obj;
26 cursor.index = name_match.end;
27 cursor.word(":")?;
28
29 let val_match = cursor.fn_until(|chr: u8| chr == b'\n')?;
30 let val = val_match.obj.trim();
31 if name.ends_with('+') {
32 let new_name = name.trim_end_matches('+');
33 properties
34 .entry(new_name)
35 .and_modify(|n| {
36 write!(n.to_mut(), " {val}").unwrap(); })
38 .or_insert(Cow::from(val));
39 } else {
40 properties.insert(name, Cow::from(val));
41 }
42
43 Ok(val_match.end + 1)
44}