librustc_lexer: Simplify "raw_double_quoted_string" method
This commit is contained in:
parent
d6f722d79c
commit
6e350bd999
1 changed files with 37 additions and 28 deletions
|
@ -600,36 +600,45 @@ impl Cursor<'_> {
|
||||||
/// (amount of the '#' symbols, raw string started, raw string terminated)
|
/// (amount of the '#' symbols, raw string started, raw string terminated)
|
||||||
fn raw_double_quoted_string(&mut self) -> (usize, bool, bool) {
|
fn raw_double_quoted_string(&mut self) -> (usize, bool, bool) {
|
||||||
debug_assert!(self.prev() == 'r');
|
debug_assert!(self.prev() == 'r');
|
||||||
// Count opening '#' symbols.
|
let mut started: bool = false;
|
||||||
let n_hashes = {
|
let mut finished: bool = false;
|
||||||
let mut acc: usize = 0;
|
|
||||||
loop {
|
|
||||||
match self.bump() {
|
|
||||||
Some('#') => acc += 1,
|
|
||||||
Some('"') => break acc,
|
|
||||||
None | Some(_) => return (acc, false, false),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Skip the string itself and check that amount of closing '#'
|
// Count opening '#' symbols.
|
||||||
// symbols is equal to the amount of opening ones.
|
let n_hashes = self.eat_while(|c| c == '#');
|
||||||
loop {
|
|
||||||
match self.bump() {
|
// Check that string is started.
|
||||||
Some('"') => {
|
match self.bump() {
|
||||||
let mut acc = n_hashes;
|
Some('"') => started = true,
|
||||||
while self.nth_char(0) == '#' && acc > 0 {
|
_ => return (n_hashes, started, finished),
|
||||||
self.bump();
|
|
||||||
acc -= 1;
|
|
||||||
}
|
|
||||||
if acc == 0 {
|
|
||||||
return (n_hashes, true, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some(_) => (),
|
|
||||||
None => return (n_hashes, true, false),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Skip the string contents and on each '#' character met, check if this is
|
||||||
|
// a raw string termination.
|
||||||
|
while !finished {
|
||||||
|
self.eat_while(|c| c != '"');
|
||||||
|
|
||||||
|
if self.is_eof() {
|
||||||
|
return (n_hashes, started, finished);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eat closing double quote.
|
||||||
|
self.bump();
|
||||||
|
|
||||||
|
// Check that amount of closing '#' symbols
|
||||||
|
// is equal to the amount of opening ones.
|
||||||
|
let mut hashes_left = n_hashes;
|
||||||
|
let is_closing_hash = |c| {
|
||||||
|
if c == '#' && hashes_left != 0 {
|
||||||
|
hashes_left -= 1;
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
finished = self.eat_while(is_closing_hash) == n_hashes;
|
||||||
|
}
|
||||||
|
|
||||||
|
(n_hashes, started, finished)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_decimal_digits(&mut self) -> bool {
|
fn eat_decimal_digits(&mut self) -> bool {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue