Implement node property.
This commit is contained in:
		
							parent
							
								
									f7f29e7a56
								
							
						
					
					
						commit
						8de6f1a817
					
				| @ -53,7 +53,5 @@ pub struct PropertyDrawer<'s> { | ||||
| #[derive(Debug)] | ||||
| pub struct NodeProperty<'s> { | ||||
|     pub source: &'s str, | ||||
|     pub indentation: usize, | ||||
|     pub bullet: &'s str, | ||||
|     pub children: Vec<Element<'s>>, | ||||
|     pub value: Option<&'s str>, | ||||
| } | ||||
|  | ||||
| @ -1,9 +1,13 @@ | ||||
| use nom::branch::alt; | ||||
| use nom::bytes::complete::is_not; | ||||
| use nom::bytes::complete::tag; | ||||
| use nom::bytes::complete::tag_no_case; | ||||
| use nom::character::complete::line_ending; | ||||
| use nom::character::complete::space0; | ||||
| use nom::character::complete::space1; | ||||
| use nom::combinator::eof; | ||||
| use nom::combinator::map; | ||||
| use nom::combinator::opt; | ||||
| use nom::combinator::recognize; | ||||
| use nom::multi::many_till; | ||||
| use nom::sequence::tuple; | ||||
| @ -18,6 +22,7 @@ use crate::parser::greater_element::PropertyDrawer; | ||||
| use crate::parser::parser_context::ContextElement; | ||||
| use crate::parser::parser_context::ExitMatcherNode; | ||||
| use crate::parser::parser_with_context::parser_with_context; | ||||
| use crate::parser::plain_text::plain_text; | ||||
| use crate::parser::util::exit_matcher_parser; | ||||
| use crate::parser::util::get_consumed; | ||||
| use crate::parser::util::immediate_in_section; | ||||
| @ -53,10 +58,10 @@ pub fn property_drawer<'r, 's>( | ||||
|             exit_matcher: &property_drawer_end, | ||||
|         })); | ||||
| 
 | ||||
|     let element_matcher = parser_with_context!(node_property)(&parser_context); | ||||
|     let node_property_matcher = parser_with_context!(node_property)(&parser_context); | ||||
|     let exit_matcher = parser_with_context!(exit_matcher_parser)(&parser_context); | ||||
|     let (remaining, (children, _exit_contents)) = | ||||
|         many_till(element_matcher, exit_matcher)(remaining)?; | ||||
|         many_till(node_property_matcher, exit_matcher)(remaining)?; | ||||
|     let (remaining, _end) = property_drawer_end(&parser_context, remaining)?; | ||||
| 
 | ||||
|     let (remaining, _trailing_ws) = | ||||
| @ -77,10 +82,67 @@ fn property_drawer_end<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res< | ||||
|     )))(input) | ||||
| } | ||||
| 
 | ||||
| #[tracing::instrument(ret, level = "debug")] | ||||
| pub fn node_property<'r, 's>( | ||||
|     context: Context<'r, 's>, | ||||
|     input: &'s str, | ||||
| ) -> Res<&'s str, NodeProperty<'s>> { | ||||
|     todo!() | ||||
|     let (remaining, (_start_of_line, _leading_whitespace, _open_colon, name, _close_colon)) = | ||||
|         tuple(( | ||||
|             parser_with_context!(start_of_line)(context), | ||||
|             space0, | ||||
|             tag(":"), | ||||
|             parser_with_context!(node_property_name)(context), | ||||
|             tag(":"), | ||||
|         ))(input)?; | ||||
|     match tuple((space0::<&str, nom::error::Error<&str>>, line_ending))(remaining) { | ||||
|         Ok((remaining, _ws)) => { | ||||
|             let source = get_consumed(input, remaining); | ||||
|             Ok(( | ||||
|                 remaining, | ||||
|                 NodeProperty { | ||||
|                     source, | ||||
|                     value: None, | ||||
|                 }, | ||||
|             )) | ||||
|         } | ||||
|         Err(_) => { | ||||
|             let (remaining, (_ws, value)) = tuple((space1, is_not("\r\n")))(remaining)?; | ||||
|             let source = get_consumed(input, remaining); | ||||
|             Ok(( | ||||
|                 remaining, | ||||
|                 NodeProperty { | ||||
|                     source, | ||||
|                     value: Some(value), | ||||
|                 }, | ||||
|             )) | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[tracing::instrument(ret, level = "debug")] | ||||
| pub fn node_property_name<'r, 's>( | ||||
|     context: Context<'r, 's>, | ||||
|     input: &'s str, | ||||
| ) -> Res<&'s str, &'s str> { | ||||
|     let parser_context = | ||||
|         context.with_additional_node(ContextElement::ExitMatcherNode(ExitMatcherNode { | ||||
|             class: ExitClass::Alpha, | ||||
|             exit_matcher: &node_property_name_end, | ||||
|         })); | ||||
| 
 | ||||
|     let (remaining, name) = recognize(tuple(( | ||||
|         map(parser_with_context!(plain_text)(&parser_context), |pt| { | ||||
|             pt.source | ||||
|         }), | ||||
|         opt(tag("+")), | ||||
|     )))(input)?; | ||||
|     Ok((remaining, name)) | ||||
| } | ||||
| 
 | ||||
| #[tracing::instrument(ret, level = "debug")] | ||||
| pub fn node_property_name_end<'r, 's>( | ||||
|     context: Context<'r, 's>, | ||||
|     input: &'s str, | ||||
| ) -> Res<&'s str, &'s str> { | ||||
|     alt((tag("+:"), tag(":")))(input) | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander