about summary refs log tree commit diff
path: root/tvix/eval/src/eval.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2022-08-16T20·43+0300
committertazjin <tazjin@tvl.su>2022-09-01T17·41+0000
commit813fb9847095bad5af6ca6472b9a53b2f911d870 (patch)
tree728f1b7bca7d2f60701d317df5c0bd2cac0af5dc /tvix/eval/src/eval.rs
parenta00e4730a5ec824a8452152de72458230f72e61a (diff)
refactor(tvix/eval): Upgrade to latest rnix-parser r/4567
Since the latest published version of rnix-parser on crates.io, the
crate has undergone major changes which are only available in the git
repository at the moment. This commit updates the compiler to this
newer version of rnix.

Most notably, the entire AST provided by rnix is now wrapped in the
AST type system. As a result of this traversal is much nicer in many
places, especially for things like nested attribute selection.

There are a handful of smaller features missing for full feature
parity with the previous version, especially handling of path
literals, but PRs for these already exist in rnix-parser.

Change-Id: Icde6d393067976549492b7d89c4cc49e5e575fc7
Reviewed-on: https://cl.tvl.fyi/c/depot/+/6231
Reviewed-by: sterni <sternenseemann@systemli.org>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/eval/src/eval.rs')
-rw-r--r--tvix/eval/src/eval.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/tvix/eval/src/eval.rs b/tvix/eval/src/eval.rs
index 94290af5376d..cd11d3289b12 100644
--- a/tvix/eval/src/eval.rs
+++ b/tvix/eval/src/eval.rs
@@ -1,6 +1,6 @@
 use std::path::PathBuf;
 
-use rnix::{self, types::TypedNode};
+use rnix;
 
 use crate::{
     errors::{Error, EvalResult},
@@ -8,21 +8,27 @@ use crate::{
 };
 
 pub fn interpret(code: &str, location: Option<PathBuf>) -> EvalResult<Value> {
-    let ast = rnix::parse(code);
+    let parsed = rnix::ast::Root::parse(code);
+    let errors = parsed.errors();
 
-    let errors = ast.errors();
     if !errors.is_empty() {
-        for err in &errors {
+        for err in errors {
             eprintln!("parse error: {}", err);
-            return Err(Error::ParseErrors(errors));
         }
+        return Err(Error::ParseErrors(errors.to_vec()));
     }
 
+    // If we've reached this point, there are no errors.
+    let root_expr = parsed
+        .tree()
+        .expr()
+        .expect("expression should exist if no errors occured");
+
     if std::env::var("TVIX_DISPLAY_AST").is_ok() {
-        println!("{}", ast.root().dump());
+        println!("{:?}", root_expr);
     }
 
-    let result = crate::compiler::compile(ast, location)?;
+    let result = crate::compiler::compile(root_expr, location)?;
 
     #[cfg(feature = "disassembler")]
     crate::disassembler::disassemble_chunk(&result.chunk);