From 8e9bfc1ca7e1b95419949439f85097e7eb5f840d Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 17 Oct 2022 02:13:38 +0300 Subject: 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 Tested-by: BuildkiteCI Reviewed-by: j4m3s Reviewed-by: Adam Joseph --- tvix/eval/src/pretty_ast.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'tvix/eval') diff --git a/tvix/eval/src/pretty_ast.rs b/tvix/eval/src/pretty_ast.rs index e8e3b214c497..a829be26d814 100644 --- a/tvix/eval/src/pretty_ast.rs +++ b/tvix/eval/src/pretty_ast.rs @@ -135,17 +135,16 @@ impl<'a> Serialize for SerializeAST<&'a ast::Path> { impl<'a> Serialize for SerializeAST<&'a ast::Literal> { fn serialize(&self, serializer: S) -> Result { + 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() } } -- cgit 1.4.1