Lex and parse bool literals

This commit is contained in:
mars 2022-03-01 13:08:18 -07:00
parent 6217b83cd8
commit 732d80dd9a
2 changed files with 7 additions and 0 deletions

View File

@ -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,

View File

@ -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)]