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