Store bool for BoolLit instead of str

This commit is contained in:
Guillaume Gomez 2024-07-26 22:05:19 +02:00
parent bb77b1ea41
commit eb4ceae2a3
2 changed files with 9 additions and 5 deletions

View File

@ -1888,8 +1888,12 @@ impl<'a> Generator<'a> {
DisplayWrap::Wrapped DisplayWrap::Wrapped
} }
fn visit_bool_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { fn visit_bool_lit(&mut self, buf: &mut Buffer, s: bool) -> DisplayWrap {
buf.write(s); if s {
buf.write("true");
} else {
buf.write("false");
}
DisplayWrap::Unwrapped DisplayWrap::Unwrapped
} }

View File

@ -35,7 +35,7 @@ macro_rules! expr_prec_layer {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Expr<'a> { pub enum Expr<'a> {
BoolLit(&'a str), BoolLit(bool),
NumLit(&'a str), NumLit(&'a str),
StrLit(&'a str), StrLit(&'a str),
CharLit(&'a str), CharLit(&'a str),
@ -334,8 +334,8 @@ impl<'a> Expr<'a> {
let start = i; let start = i;
map(path_or_identifier, |v| match v { map(path_or_identifier, |v| match v {
PathOrIdentifier::Path(v) => Self::Path(v), PathOrIdentifier::Path(v) => Self::Path(v),
PathOrIdentifier::Identifier(v @ "true") => Self::BoolLit(v), PathOrIdentifier::Identifier("true") => Self::BoolLit(true),
PathOrIdentifier::Identifier(v @ "false") => Self::BoolLit(v), PathOrIdentifier::Identifier("false") => Self::BoolLit(false),
PathOrIdentifier::Identifier(v) => Self::Var(v), PathOrIdentifier::Identifier(v) => Self::Var(v),
})(i) })(i)
.map(|(i, expr)| (i, WithSpan::new(expr, start))) .map(|(i, expr)| (i, WithSpan::new(expr, start)))