Simplify the resume check -- just use an if
This commit is contained in:
parent
c5b769ff45
commit
5fe10fe002
1 changed files with 6 additions and 5 deletions
|
@ -4,11 +4,13 @@
|
||||||
|
|
||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
pub enum Token { LeftParen, RightParen, Id(String), }
|
pub enum Token { LeftParen, RightParen, Id(String), }
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
enum Resume { Here, AtNext }
|
enum Resume { Here, AtNext }
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq)]
|
||||||
enum IterationResult {
|
enum IterationResult {
|
||||||
Continue,
|
Continue,
|
||||||
Emit(Token, Resume),
|
Emit(Token, Resume),
|
||||||
|
@ -65,10 +67,9 @@ impl<T> Iterator for Lexer<T> where T: Iterator<Item=char> {
|
||||||
match result {
|
match result {
|
||||||
IterationResult::Continue => self.input.next(),
|
IterationResult::Continue => self.input.next(),
|
||||||
IterationResult::Emit(token, resume) => {
|
IterationResult::Emit(token, resume) => {
|
||||||
match resume {
|
if resume == Resume::AtNext {
|
||||||
Resume::AtNext => self.input.next(),
|
self.input.next();
|
||||||
Resume::Here => None,
|
}
|
||||||
};
|
|
||||||
return Some(Ok(token))
|
return Some(Ok(token))
|
||||||
},
|
},
|
||||||
IterationResult::Error(msg) => return Some(Err(msg)),
|
IterationResult::Error(msg) => return Some(Err(msg)),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue