Integrated the partial parser into the rest of the grammar
This commit is contained in:
		
							parent
							
								
									8bfa622c4c
								
							
						
					
					
						commit
						e2f03de297
					
				| @ -92,8 +92,7 @@ struct NamedBlock<'a> { | ||||
| #[derive(Clone, Debug, PartialEq)] | ||||
| struct ParameterizedBlock<'a> { | ||||
|     name: String, | ||||
|     contents: Option<Body<'a>>, | ||||
|     params: Vec<&'a str>, | ||||
|     params: Vec<KVPair<'a>>, | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone, Debug, PartialEq)] | ||||
| @ -342,8 +341,8 @@ where | ||||
|         let (i, (name, params)) = delimited( | ||||
|             tag(open_matcher), | ||||
|             tuple(( | ||||
|                 key, | ||||
|                 opt(preceded(space1, separated_list(space1, is_not(" ")))), | ||||
|                 alt((map(key, String::from), quoted_string)), | ||||
|                 opt(preceded(space1, separated_list(space1, key_value_pair))), | ||||
|             )), | ||||
|             tag("/}"), | ||||
|         )(i)?; | ||||
| @ -351,8 +350,7 @@ where | ||||
|         Ok(( | ||||
|             i, | ||||
|             constructor(ParameterizedBlock { | ||||
|                 name: name.to_owned(), | ||||
|                 contents: None, | ||||
|                 name: name, | ||||
|                 params: params.unwrap_or(Vec::new()), | ||||
|             }), | ||||
|         )) | ||||
| @ -691,46 +689,24 @@ mod tests { | ||||
|     } | ||||
| 
 | ||||
|     #[test] | ||||
|     fn test_self_closing_unquoted_partial() { | ||||
|     fn test_unquoted_partial() { | ||||
|         assert_eq!( | ||||
|             delimited( | ||||
|                 tag("{>"), | ||||
|                 tuple(( | ||||
|                     key, | ||||
|                     opt(preceded(space1, separated_list(space1, key_value_pair))), | ||||
|                 )), | ||||
|                 tag("/}"), | ||||
|             )("{>foo bar=baz/}"), | ||||
|             dust_tag(r#"{>foo bar=baz animal="cat"/}"#), | ||||
|             Ok(( | ||||
|                 "", | ||||
|                 ( | ||||
|                     "foo", | ||||
|                     Some(vec![KVPair { | ||||
|                         key: "bar", | ||||
|                         value: RValue::RVPath(Path { keys: vec!["baz"] }) | ||||
|                     }]) | ||||
|                 ) | ||||
|             )) | ||||
|         ); | ||||
| 
 | ||||
|         assert_eq!( | ||||
|             delimited( | ||||
|                 tag("{>"), | ||||
|                 tuple(( | ||||
|                     key, | ||||
|                     opt(preceded(space1, separated_list(space1, key_value_pair))), | ||||
|                 )), | ||||
|                 tag("/}"), | ||||
|             )(r#"{>foo bar="ba\"z"/}"#), | ||||
|             Ok(( | ||||
|                 "", | ||||
|                 ( | ||||
|                     "foo", | ||||
|                     Some(vec![KVPair { | ||||
|                         key: "bar", | ||||
|                         value: RValue::RVString("ba\"z".to_owned()) | ||||
|                     }]) | ||||
|                 ) | ||||
|                 DustTag::DTPartial(ParameterizedBlock { | ||||
|                     name: "foo".to_owned(), | ||||
|                     params: vec![ | ||||
|                         KVPair { | ||||
|                             key: "bar", | ||||
|                             value: RValue::RVPath(Path { keys: vec!["baz"] }) | ||||
|                         }, | ||||
|                         KVPair { | ||||
|                             key: "animal", | ||||
|                             value: RValue::RVString("cat".to_owned()) | ||||
|                         } | ||||
|                     ] | ||||
|                 }) | ||||
|             )) | ||||
|         ); | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Tom Alexander
						Tom Alexander