Skip to content

Commit

Permalink
Comment the arms of the literal parser with example literals
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 31, 2023
1 parent 055a4a5 commit 8dbdb72
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,19 +951,22 @@ mod value {
let repr = token.to_string();

match byte(&repr, 0) {
// "...", r"...", r#"..."#
b'"' | b'r' => {
let (_, suffix) = parse_lit_str(&repr);
return Lit::Str(LitStr {
repr: Box::new(LitRepr { token, suffix }),
});
}
b'b' => match byte(&repr, 1) {
// b"...", br"...", br#"...#"
b'"' | b'r' => {
let (_, suffix) = parse_lit_byte_str(&repr);
return Lit::ByteStr(LitByteStr {
repr: Box::new(LitRepr { token, suffix }),
});
}
// b'...'
b'\'' => {
let (_, suffix) = parse_lit_byte(&repr);
return Lit::Byte(LitByte {
Expand All @@ -972,13 +975,15 @@ mod value {
}
_ => {}
},
// '...'
b'\'' => {
let (_, suffix) = parse_lit_char(&repr);
return Lit::Char(LitChar {
repr: Box::new(LitRepr { token, suffix }),
});
}
b'0'..=b'9' | b'-' => {
// 0, 123, 0xFF, 0o77, 0b11
if let Some((digits, suffix)) = parse_lit_int(&repr) {
return Lit::Int(LitInt {
repr: Box::new(LitIntRepr {
Expand All @@ -988,6 +993,7 @@ mod value {
}),
});
}
// 1.0, 1e-1, 1e+1
if let Some((digits, suffix)) = parse_lit_float(&repr) {
return Lit::Float(LitFloat {
repr: Box::new(LitFloatRepr {
Expand All @@ -998,6 +1004,7 @@ mod value {
});
}
}
// true, false
b't' | b'f' => {
if repr == "true" || repr == "false" {
return Lit::Bool(LitBool {
Expand Down

0 comments on commit 8dbdb72

Please sign in to comment.