Make Comments::next
consume a comment.
This avoids the need for a clone, fixing a FIXME comment.
This commit is contained in:
parent
5e7a80b2d2
commit
74e1b46ab2
1 changed files with 7 additions and 9 deletions
|
@ -55,8 +55,8 @@ impl PpAnn for NoAnn {}
|
||||||
|
|
||||||
pub struct Comments<'a> {
|
pub struct Comments<'a> {
|
||||||
sm: &'a SourceMap,
|
sm: &'a SourceMap,
|
||||||
comments: Vec<Comment>,
|
// Stored in reverse order so we can consume them by popping.
|
||||||
current: usize,
|
reversed_comments: Vec<Comment>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `None` if the first `col` chars of `s` contain a non-whitespace char.
|
/// Returns `None` if the first `col` chars of `s` contain a non-whitespace char.
|
||||||
|
@ -182,19 +182,17 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
|
||||||
|
|
||||||
impl<'a> Comments<'a> {
|
impl<'a> Comments<'a> {
|
||||||
pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
|
pub fn new(sm: &'a SourceMap, filename: FileName, input: String) -> Comments<'a> {
|
||||||
let comments = gather_comments(sm, filename, input);
|
let mut comments = gather_comments(sm, filename, input);
|
||||||
Comments { sm, comments, current: 0 }
|
comments.reverse();
|
||||||
|
Comments { sm, reversed_comments: comments }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn peek(&self) -> Option<&Comment> {
|
fn peek(&self) -> Option<&Comment> {
|
||||||
self.comments.get(self.current)
|
self.reversed_comments.last()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: This shouldn't probably clone lmao
|
|
||||||
fn next(&mut self) -> Option<Comment> {
|
fn next(&mut self) -> Option<Comment> {
|
||||||
let cmnt = self.comments.get(self.current).cloned();
|
self.reversed_comments.pop()
|
||||||
self.current += 1;
|
|
||||||
cmnt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trailing_comment(
|
fn trailing_comment(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue