fix(tvix/eval): more faithfully serialise ast::Literal
The previous serialisation format kind of lost the information about what AST node we're dealing with (e.g. `1234` would serialise to an AST with a literal `1234`). That's great for pretty-printing the _code_, but we explicitly want to serialise how rnix-parser parses something. To that end, literals are now instead serialised into a structure like all the other ones (`kind: literal` and appropriate value fields). Change-Id: I586c95d7db41820b8ec43565ba4016ed3834d1b5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7030 Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Reviewed-by: j4m3s <james.landrein@gmail.com> Reviewed-by: Adam Joseph <adam@westernsemico.com>
This commit is contained in:
		
							parent
							
								
									5ee2258692
								
							
						
					
					
						commit
						8e9bfc1ca7
					
				
					 1 changed files with 9 additions and 10 deletions
				
			
		| 
						 | 
				
			
			@ -135,17 +135,16 @@ impl<'a> Serialize for SerializeAST<&'a ast::Path> {
 | 
			
		|||
 | 
			
		||||
impl<'a> Serialize for SerializeAST<&'a ast::Literal> {
 | 
			
		||||
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
 | 
			
		||||
        let mut map = serializer.serialize_map(Some(2))?;
 | 
			
		||||
        map.serialize_entry("kind", "literal")?;
 | 
			
		||||
 | 
			
		||||
        match self.0.kind() {
 | 
			
		||||
            ast::LiteralKind::Float(val) => serializer.serialize_f64(val.value().unwrap()),
 | 
			
		||||
            ast::LiteralKind::Integer(val) => serializer.serialize_i64(val.value().unwrap()),
 | 
			
		||||
            ast::LiteralKind::Uri(val) => {
 | 
			
		||||
                let url = val.syntax().text();
 | 
			
		||||
                let mut map = serializer.serialize_map(Some(2))?;
 | 
			
		||||
                map.serialize_entry("kind", "url")?;
 | 
			
		||||
                map.serialize_entry("url", url)?;
 | 
			
		||||
                map.end()
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            ast::LiteralKind::Float(val) => map.serialize_entry("float", &val.value().unwrap()),
 | 
			
		||||
            ast::LiteralKind::Integer(val) => map.serialize_entry("int", &val.value().unwrap()),
 | 
			
		||||
            ast::LiteralKind::Uri(val) => map.serialize_entry("uri", val.syntax().text()),
 | 
			
		||||
        }?;
 | 
			
		||||
 | 
			
		||||
        map.end()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue