From 5e5c4f2c47ec867d698c001cfe8d097be5744a57 Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 24 Sep 2024 16:22:31 +0200 Subject: Parse abstractions Got tricked with or()'s function eagerness: Even when the left hand side succeeds, the argument was evaluated which consumed a token in the parser which prevented proper parsing. --- rust/src/ast.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rust/src/ast.rs') diff --git a/rust/src/ast.rs b/rust/src/ast.rs index 0493f59..722e9e0 100644 --- a/rust/src/ast.rs +++ b/rust/src/ast.rs @@ -1,11 +1,12 @@ use std::fmt::{self, Display}; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Clone)] pub enum Value { Num(i32), Bool(bool), Sym(String), App(Box, Box), + Lam(String, Box), } impl Display for Value { @@ -15,6 +16,7 @@ impl Display for Value { Value::Bool(b) => write!(f, "{}", b), Value::Sym(s) => write!(f, "{}", s), Value::App(l, r) => write!(f, "({} {})", l, r), + Value::Lam(var, body) => write!(f, "(lam {} {})", var, body), } } } -- cgit v1.2.3