diff options
| author | Corey Richardson <corey@octayn.net> | 2014-06-24 17:44:50 -0700 |
|---|---|---|
| committer | Corey Richardson <corey@octayn.net> | 2014-07-09 00:06:29 -0700 |
| commit | c8a02527ae6364175c31a5447dd4e21bb6ac3488 (patch) | |
| tree | 86ddfccfb08be24ba4cd4a9e4016dcaa417eb746 /src/libsyntax/parse | |
| parent | 47fe8aa6bfaa18d42561801dc230d2043b984b76 (diff) | |
| download | rust-c8a02527ae6364175c31a5447dd4e21bb6ac3488.tar.gz rust-c8a02527ae6364175c31a5447dd4e21bb6ac3488.zip | |
lexer: add ident_from and ident_from_to methods
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index f22e7af0856..7a9051c16ae 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -217,6 +217,20 @@ impl<'a> StringReader<'a> { 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 { |
