]> git.lizzy.rs Git - rust.git/commitdiff
lexer: add ident_from and ident_from_to methods
authorCorey Richardson <corey@octayn.net>
Wed, 25 Jun 2014 00:44:50 +0000 (17:44 -0700)
committerCorey Richardson <corey@octayn.net>
Wed, 9 Jul 2014 07:06:29 +0000 (00:06 -0700)
src/libsyntax/parse/lexer/mod.rs

index f22e7af08564f1720af927afd4a0489e3b89a5fe..7a9051c16aed63f5e5a8f096f52e169cef5fe8c9 100644 (file)
@@ -217,6 +217,20 @@ pub fn with_str_from<T>(&self, start: BytePos, f: |s: &str| -> T) -> T {
         self.with_str_from_to(start, self.last_pos, f)
     }
 
+    /// Create an Ident from a given offset to the current offset, each
+    /// adjusted 1 towards each other (assumes that on either side there is a
+    /// single-byte delimiter).
+    pub fn ident_from(&self, start: BytePos) -> ast::Ident {
+        debug!("taking an ident from {} to {}", start, self.last_pos);
+        self.with_str_from(start, str_to_ident)
+    }
+
+    /// As ident_from, with an explicit endpoint.
+    pub fn ident_from_to(&self, start: BytePos, end: BytePos) -> ast::Ident {
+        debug!("taking an ident from {} to {}", start, end);
+        self.with_str_from_to(start, end, str_to_ident)
+    }
+
     /// Calls `f` with a string slice of the source text spanning from `start`
     /// up to but excluding `end`.
     fn with_str_from_to<T>(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T {