From 732d80dd9a27c721f61e11b0e37a81d4da89089f Mon Sep 17 00:00:00 2001 From: mars Date: Tue, 1 Mar 2022 13:08:18 -0700 Subject: [PATCH] Lex and parse bool literals --- src/lexer.rs | 4 ++++ src/parse.rs | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/lexer.rs b/src/lexer.rs index e246b40..0001b7e 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -54,6 +54,10 @@ pub enum Token { #[token("==")] OpEq, #[token("!=")] OpNeq, + // boolean literals + #[token("true")] True, + #[token("false")] False, + #[regex(r"[a-zA-Z_][a-zA-Z0-9_]*")] Identifier, diff --git a/src/parse.rs b/src/parse.rs index 6a6075a..bd2ba88 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -299,6 +299,8 @@ impl<'a> Expr<'a> { Token::OctalInteger => Self::Literal(Literal::OctalInteger(lexer.slice())), Token::HexInteger => Self::Literal(Literal::HexInteger(lexer.slice())), Token::DecimalInteger => Self::Literal(Literal::DecimalInteger(lexer.slice())), + Token::True => Self::Literal(Literal::Boolean(true)), + Token::False => Self::Literal(Literal::Boolean(false)), Token::Semicolon | Token::BraceClose | Token::ParanClose => return (None, tok), _ => lexer.panic_message("Unexpected token"), }; @@ -390,6 +392,7 @@ pub enum Literal<'a> { OctalInteger(&'a str), HexInteger(&'a str), DecimalInteger(&'a str), + Boolean(bool), } #[derive(Debug)]