bool literals
This commit is contained in:
parent
505d23a327
commit
9775bfc342
@ -450,6 +450,7 @@ pub enum Expression {
|
||||
IntLiteral(u64),
|
||||
FloatLiteral(f64),
|
||||
StringLiteral(Rc<String>),
|
||||
BoolLiteral(bool),
|
||||
BinExp(Operation, Box<Expression>, Box<Expression>),
|
||||
Variable(Rc<String>),
|
||||
Call {
|
||||
@ -669,6 +670,8 @@ impl Parser {
|
||||
parse_method!(literal(&mut self) -> ParseResult<Expression> {
|
||||
match self.peek() {
|
||||
DigitGroup(_) | HexNumberSigil | BinNumberSigil | Period => self.number_literal(),
|
||||
Keyword(Kw::True) => { self.next(); Ok(Expression::BoolLiteral(true)) },
|
||||
Keyword(Kw::False) => { self.next(); Ok(Expression::BoolLiteral(false)) },
|
||||
StrLiteral(s) => {
|
||||
self.next();
|
||||
Ok(Expression::StringLiteral(s))
|
||||
@ -848,6 +851,12 @@ mod parse_tests {
|
||||
})]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_bools() {
|
||||
parse_test!("false", AST(vec![Expression(BoolLiteral(false))]));
|
||||
parse_test!("true", AST(vec![Expression(BoolLiteral(true))]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parsing_strings() {
|
||||
parse_test!(r#""hello""#, AST(vec![Expression(StringLiteral(rc!(hello)))]));
|
||||
|
Loading…
Reference in New Issue
Block a user