diff options
author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-15 22:32:38 +0300 |
---|---|---|
committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2025-08-15 22:32:38 +0300 |
commit | a97fef6f099767924c5203782a2b04b1a559ac6b (patch) | |
tree | 6ad526863433b8f657f4c969acb81ae0132c7c29 | |
parent | 0328272d2a52264f36770d524aaa11b425e34370 (diff) | |
download | myslip-a97fef6f099767924c5203782a2b04b1a559ac6b.tar.gz myslip-a97fef6f099767924c5203782a2b04b1a559ac6b.zip |
fix: prevented loading non-let expressions as declarations
-rw-r--r-- | src/main.rs | 9 | ||||
-rw-r--r-- | stdlib.slip | 2 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 0fcf340..30bd136 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,14 @@ fn read_bind_files( let mut contents = String::new(); file.read_to_string(&mut contents) .map_err(|e| e.to_string())?; - res.extend(parse_to_ast(&contents)?.parts()); + let exps = parse_to_ast(&contents)?.parts(); + for exp in exps { + if exp.clone().check_let().is_some() { + res.push(exp); + } else { + return Err(format!("'{}' isn't a declaration", exp)); + } + } } Ok(res) } diff --git a/stdlib.slip b/stdlib.slip index 9e20c64..dce325a 100644 --- a/stdlib.slip +++ b/stdlib.slip @@ -18,4 +18,4 @@ (fn x Int Int (- x 1) ) -)
\ No newline at end of file +) |