-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove type parameter from
parse_*
methods (#9466)
- Loading branch information
1 parent
25bafd2
commit f192c72
Showing
13 changed files
with
98 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use crate::lexer::LexResult; | ||
use crate::Tok; | ||
use std::iter::FusedIterator; | ||
|
||
#[derive(Clone, Debug)] | ||
pub(crate) struct TokenSource { | ||
tokens: std::vec::IntoIter<LexResult>, | ||
} | ||
|
||
impl TokenSource { | ||
pub(crate) fn new(tokens: Vec<LexResult>) -> Self { | ||
Self { | ||
tokens: tokens.into_iter(), | ||
} | ||
} | ||
} | ||
|
||
impl FromIterator<LexResult> for TokenSource { | ||
#[inline] | ||
fn from_iter<T: IntoIterator<Item = LexResult>>(iter: T) -> Self { | ||
Self::new(Vec::from_iter(iter)) | ||
} | ||
} | ||
|
||
impl Iterator for TokenSource { | ||
type Item = LexResult; | ||
|
||
#[inline] | ||
fn next(&mut self) -> Option<Self::Item> { | ||
loop { | ||
let next = self.tokens.next()?; | ||
|
||
if is_trivia(&next) { | ||
continue; | ||
} | ||
|
||
break Some(next); | ||
} | ||
} | ||
} | ||
|
||
impl FusedIterator for TokenSource {} | ||
|
||
const fn is_trivia(result: &LexResult) -> bool { | ||
matches!(result, Ok((Tok::Comment(_) | Tok::NonLogicalNewline, _))) | ||
} |
Oops, something went wrong.