Use consume_and_return when possible

This commit is contained in:
Nickolay Ponomarev 2019-04-27 01:52:32 +03:00
parent 6f44494910
commit bf3110f6ce

View file

@ -260,18 +260,9 @@ impl<'a> Tokenizer<'a> {
//println!("next_token: {:?}", chars.peek());
match chars.peek() {
Some(&ch) => match ch {
' ' => {
chars.next();
Ok(Some(Token::Whitespace(Whitespace::Space)))
}
'\t' => {
chars.next();
Ok(Some(Token::Whitespace(Whitespace::Tab)))
}
'\n' => {
chars.next();
Ok(Some(Token::Whitespace(Whitespace::Newline)))
}
' ' => self.consume_and_return(chars, Token::Whitespace(Whitespace::Space)),
'\t' => self.consume_and_return(chars, Token::Whitespace(Whitespace::Tab)),
'\n' => self.consume_and_return(chars, Token::Whitespace(Whitespace::Newline)),
'\r' => {
// Emit a single Whitespace::Newline token for \r and \r\n
chars.next();