Set the source using the full range of affiliated keywords to trailing whitespace.
This commit is contained in:
		
							parent
							
								
									0b989b53a6
								
							
						
					
					
						commit
						7b7779ee7e
					
				| @ -17,6 +17,7 @@ use super::lesser_element::Paragraph; | ||||
| use super::lesser_element::Planning; | ||||
| use super::lesser_element::SrcBlock; | ||||
| use super::lesser_element::VerseBlock; | ||||
| use super::source::SetSource; | ||||
| use super::source::Source; | ||||
| use super::Drawer; | ||||
| 
 | ||||
| @ -70,3 +71,31 @@ impl<'s> Source<'s> for Element<'s> { | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<'s> SetSource<'s> for Element<'s> { | ||||
|     #[tracing::instrument(ret, level = "debug")] | ||||
|     fn set_source(&mut self, source: &'s str) { | ||||
|         match self { | ||||
|             Element::Paragraph(obj) => obj.source = source, | ||||
|             Element::PlainList(obj) => obj.source = source, | ||||
|             Element::GreaterBlock(obj) => obj.source = source, | ||||
|             Element::DynamicBlock(obj) => obj.source = source, | ||||
|             Element::FootnoteDefinition(obj) => obj.source = source, | ||||
|             Element::Comment(obj) => obj.source = source, | ||||
|             Element::Drawer(obj) => obj.source = source, | ||||
|             Element::PropertyDrawer(obj) => obj.source = source, | ||||
|             Element::Table(obj) => obj.source = source, | ||||
|             Element::VerseBlock(obj) => obj.source = source, | ||||
|             Element::CommentBlock(obj) => obj.source = source, | ||||
|             Element::ExampleBlock(obj) => obj.source = source, | ||||
|             Element::ExportBlock(obj) => obj.source = source, | ||||
|             Element::SrcBlock(obj) => obj.source = source, | ||||
|             Element::Clock(obj) => obj.source = source, | ||||
|             Element::DiarySexp(obj) => obj.source = source, | ||||
|             Element::Planning(obj) => obj.source = source, | ||||
|             Element::FixedWidthArea(obj) => obj.source = source, | ||||
|             Element::HorizontalRule(obj) => obj.source = source, | ||||
|             Element::Keyword(obj) => obj.source = source, | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -16,6 +16,7 @@ use super::lesser_block::src_block; | ||||
| use super::lesser_block::verse_block; | ||||
| use super::paragraph::paragraph; | ||||
| use super::plain_list::plain_list; | ||||
| use super::source::SetSource; | ||||
| use super::util::get_consumed; | ||||
| use super::util::maybe_consume_trailing_whitespace_if_not_exiting; | ||||
| 
 | ||||
| @ -42,12 +43,13 @@ pub fn paragraph_element<'r, 's>( | ||||
|     let paragraph_matcher = parser_with_context!(paragraph)(context); | ||||
|     let keyword_matcher = parser_with_context!(keyword)(context); | ||||
|     let (remaining, _affiliated_keywords) = many0(keyword_matcher)(input)?; | ||||
|     let (remaining, element) = map(paragraph_matcher, Element::Paragraph)(remaining)?; | ||||
|     let (remaining, mut element) = map(paragraph_matcher, Element::Paragraph)(remaining)?; | ||||
| 
 | ||||
|     let (remaining, _trailing_ws) = | ||||
|         maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; | ||||
| 
 | ||||
|     let _source = get_consumed(input, remaining); | ||||
|     let source = get_consumed(input, remaining); | ||||
|     element.set_source(source); | ||||
| 
 | ||||
|     Ok((remaining, element)) | ||||
| } | ||||
| @ -73,7 +75,7 @@ pub fn non_paragraph_element<'r, 's>( | ||||
|     let horizontal_rule_matcher = parser_with_context!(horizontal_rule)(context); | ||||
|     let keyword_matcher = parser_with_context!(keyword)(context); | ||||
|     let (remaining, mut affiliated_keywords) = many0(keyword_matcher)(input)?; | ||||
|     let (remaining, element) = match alt(( | ||||
|     let (remaining, mut element) = match alt(( | ||||
|         map(plain_list_matcher, Element::PlainList), | ||||
|         map(greater_block_matcher, Element::GreaterBlock), | ||||
|         map(dynamic_block_matcher, Element::DynamicBlock), | ||||
| @ -102,7 +104,8 @@ pub fn non_paragraph_element<'r, 's>( | ||||
|     let (remaining, _trailing_ws) = | ||||
|         maybe_consume_trailing_whitespace_if_not_exiting(context, remaining)?; | ||||
| 
 | ||||
|     let _source = get_consumed(input, remaining); | ||||
|     let source = get_consumed(input, remaining); | ||||
|     element.set_source(source); | ||||
| 
 | ||||
|     Ok((remaining, element)) | ||||
| } | ||||
|  | ||||
| @ -1,3 +1,6 @@ | ||||
| pub trait Source<'s> { | ||||
|     fn get_source(&'s self) -> &'s str; | ||||
| } | ||||
| pub trait SetSource<'s> { | ||||
|     fn set_source(&mut self, source: &'s str); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander