about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorAleksey Kladov <aleksey.kladov@gmail.com>2019-07-03 14:06:10 +0300
committerAleksey Kladov <aleksey.kladov@gmail.com>2019-07-04 09:08:45 +0300
commit1c6eb19d2fd9be130b6265f6bdbf8da3ba49c513 (patch)
tree3e55d61f43e670a6a073761f531e921bad1cb2b7 /src/libsyntax/parse
parent30fa99e5b8c89df2c27d10a5d38a7c0d50f155a7 (diff)
downloadrust-1c6eb19d2fd9be130b6265f6bdbf8da3ba49c513.tar.gz
rust-1c6eb19d2fd9be130b6265f6bdbf8da3ba49c513.zip
slightly comment lexer API
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/lexer/mod.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs
index b764f9678c5..829083fe4f7 100644
--- a/src/libsyntax/parse/lexer/mod.rs
+++ b/src/libsyntax/parse/lexer/mod.rs
@@ -118,29 +118,36 @@ impl<'a> StringReader<'a> {
         }
     }
 
-    /// Returns the next token. EFFECT: advances the string_reader.
+    /// Returns the next token, including trivia like whitespace or comments.
+    ///
+    /// `Err(())` means that some errors were encountered, which can be
+    /// retrieved using `buffer_fatal_errors`.
     pub fn try_next_token(&mut self) -> Result<Token, ()> {
         let (token, _raw_span) = self.try_next_token_with_raw_span()?;
         Ok(token)
     }
 
+    /// Returns the next token, including trivia like whitespace or comments.
+    ///
+    /// Aborts in case of an error.
     pub fn next_token(&mut self) -> Token {
         let res = self.try_next_token();
         self.unwrap_or_abort(res)
     }
 
-    fn try_real_token(&mut self) -> Result<(Token, Span), ()> {
-        loop {
-            let t = self.try_next_token_with_raw_span()?;
-            match t.0.kind {
-                token::Whitespace | token::Comment | token::Shebang(_) => continue,
-                _ => return Ok(t),
+    /// Returns the next token, skipping over trivia.
+    /// Also returns an unoverriden span which can be used to check tokens
+    fn real_token(&mut self) -> (Token, Span) {
+        let res = try {
+            loop {
+                let t = self.try_next_token_with_raw_span()?;
+                match t.0.kind {
+                    token::Whitespace | token::Comment | token::Shebang(_) => continue,
+                    _ => break t,
+                }
             }
-        }
-    }
+        };
 
-    fn real_token(&mut self) -> (Token, Span) {
-        let res = self.try_real_token();
         self.unwrap_or_abort(res)
     }