diff options
author | Vincent Ambo <mail@tazj.in> | 2022-10-16T23·13+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-10-16T23·35+0000 |
commit | 8e9bfc1ca7e1b95419949439f85097e7eb5f840d (patch) | |
tree | eb32feb1206a518c83c50bf3bdba0de86f4da102 /tvix/eval | |
parent | 5ee2258692da4d5c65b22416fcc3ec87db013ff8 (diff) |
fix(tvix/eval): more faithfully serialise ast::Literal r/5149
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>
Diffstat (limited to '')
-rw-r--r-- | tvix/eval/src/pretty_ast.rs | 19 |
1 files changed, 9 insertions, 10 deletions
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<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() } } |