From 4bb2497d367717ea416d68ab724277daee7b3a6f Mon Sep 17 00:00:00 2001 From: PThorpe92 Date: Mon, 1 Sep 2025 11:24:12 -0400 Subject: [PATCH] Parser: translate true and false to 0 and 1 literals --- parser/src/parser.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/parser/src/parser.rs b/parser/src/parser.rs index 124058fc9..c392b628d 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -15,6 +15,9 @@ use crate::lexer::{Lexer, Token}; use crate::token::TokenType::{self, *}; use crate::Result; +const TRUE_LIT: &str = "TRUE"; +const FALSE_LIT: &str = "FALSE"; + macro_rules! peek_expect { ( $parser:expr, $( $x:ident ),* $(,)?) => { { @@ -1545,7 +1548,25 @@ impl<'a> Parser<'a> { Name::Ident(s) => Literal::String(s), }))) } else { - Ok(Box::new(Expr::Id(name))) + match name { + Name::Ident(s) => { + let ident = s.to_ascii_uppercase(); + match ident.as_str() { + TRUE_LIT => { + return Ok(Box::new(Expr::Literal(Literal::Numeric( + "1".into(), + )))) + } + FALSE_LIT => { + return Ok(Box::new(Expr::Literal(Literal::Numeric( + "0".into(), + )))) + } + _ => return Ok(Box::new(Expr::Id(Name::Ident(s)))), + } + } + _ => Ok(Box::new(Expr::Id(name))), + } } } }