From 75e73eb5d86dd2b769a68fd704ebb9b8fca271f8 Mon Sep 17 00:00:00 2001 From: Max Mindlin Date: Sun, 16 Jun 2024 15:53:45 -0400 Subject: [PATCH] booleans --- scout-interpreter/src/lib.rs | 2 +- scout-lexer/src/token.rs | 4 ++++ scout-parser/src/lib.rs | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/scout-interpreter/src/lib.rs b/scout-interpreter/src/lib.rs index f44a5c3..e74e0a0 100644 --- a/scout-interpreter/src/lib.rs +++ b/scout-interpreter/src/lib.rs @@ -332,7 +332,7 @@ fn eval_expression<'a>( let res = eval_op(l_obj.clone(), op, r_obj.clone())?; Ok(res) } - _ => Err(EvalError::InvalidExpr), + ExprKind::Boolean(val) => Ok(Arc::new(Object::Boolean(*val))), } } .boxed() diff --git a/scout-lexer/src/token.rs b/scout-lexer/src/token.rs index b060900..b9dc339 100644 --- a/scout-lexer/src/token.rs +++ b/scout-lexer/src/token.rs @@ -29,6 +29,8 @@ pub enum TokenKind { Goto, Scrape, Screenshot, + True, + False, } impl TokenKind { @@ -43,6 +45,8 @@ impl TokenKind { "goto" => Some(Goto), "scrape" => Some(Scrape), "screenshot" => Some(Screenshot), + "true" => Some(True), + "false" => Some(False), _ => None, } } diff --git a/scout-parser/src/lib.rs b/scout-parser/src/lib.rs index 42acdd6..78b4a98 100644 --- a/scout-parser/src/lib.rs +++ b/scout-parser/src/lib.rs @@ -166,6 +166,8 @@ impl Parser { fn parse_single_expr(&mut self) -> ParseResult { let lhs = match self.curr.kind { + TokenKind::False => Ok(ExprKind::Boolean(false)), + TokenKind::True => Ok(ExprKind::Boolean(true)), TokenKind::Ident => { // Parse multiple types of ident expressions match self.peek.kind {