Skip to content

Commit 1c6eb19

Browse files
committed
slightly comment lexer API
1 parent 30fa99e commit 1c6eb19

File tree

1 file changed

+18
-11
lines changed
  • src/libsyntax/parse/lexer

1 file changed

+18
-11
lines changed

src/libsyntax/parse/lexer/mod.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,36 @@ impl<'a> StringReader<'a> {
118118
}
119119
}
120120

121-
/// Returns the next token. EFFECT: advances the string_reader.
121+
/// Returns the next token, including trivia like whitespace or comments.
122+
///
123+
/// `Err(())` means that some errors were encountered, which can be
124+
/// retrieved using `buffer_fatal_errors`.
122125
pub fn try_next_token(&mut self) -> Result<Token, ()> {
123126
let (token, _raw_span) = self.try_next_token_with_raw_span()?;
124127
Ok(token)
125128
}
126129

130+
/// Returns the next token, including trivia like whitespace or comments.
131+
///
132+
/// Aborts in case of an error.
127133
pub fn next_token(&mut self) -> Token {
128134
let res = self.try_next_token();
129135
self.unwrap_or_abort(res)
130136
}
131137

132-
fn try_real_token(&mut self) -> Result<(Token, Span), ()> {
133-
loop {
134-
let t = self.try_next_token_with_raw_span()?;
135-
match t.0.kind {
136-
token::Whitespace | token::Comment | token::Shebang(_) => continue,
137-
_ => return Ok(t),
138+
/// Returns the next token, skipping over trivia.
139+
/// Also returns an unoverriden span which can be used to check tokens
140+
fn real_token(&mut self) -> (Token, Span) {
141+
let res = try {
142+
loop {
143+
let t = self.try_next_token_with_raw_span()?;
144+
match t.0.kind {
145+
token::Whitespace | token::Comment | token::Shebang(_) => continue,
146+
_ => break t,
147+
}
138148
}
139-
}
140-
}
149+
};
141150

142-
fn real_token(&mut self) -> (Token, Span) {
143-
let res = self.try_real_token();
144151
self.unwrap_or_abort(res)
145152
}
146153

0 commit comments

Comments
 (0)