Skip to content

Commit c8a0252

Browse files
committed
lexer: add ident_from and ident_from_to methods
1 parent 47fe8aa commit c8a0252

File tree

1 file changed

+14
-0
lines changed
  • src/libsyntax/parse/lexer

1 file changed

+14
-0
lines changed

src/libsyntax/parse/lexer/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,20 @@ impl<'a> StringReader<'a> {
217217
self.with_str_from_to(start, self.last_pos, f)
218218
}
219219

220+
/// Create an Ident from a given offset to the current offset, each
221+
/// adjusted 1 towards each other (assumes that on either side there is a
222+
/// single-byte delimiter).
223+
pub fn ident_from(&self, start: BytePos) -> ast::Ident {
224+
debug!("taking an ident from {} to {}", start, self.last_pos);
225+
self.with_str_from(start, str_to_ident)
226+
}
227+
228+
/// As ident_from, with an explicit endpoint.
229+
pub fn ident_from_to(&self, start: BytePos, end: BytePos) -> ast::Ident {
230+
debug!("taking an ident from {} to {}", start, end);
231+
self.with_str_from_to(start, end, str_to_ident)
232+
}
233+
220234
/// Calls `f` with a string slice of the source text spanning from `start`
221235
/// up to but excluding `end`.
222236
fn with_str_from_to<T>(&self, start: BytePos, end: BytePos, f: |s: &str| -> T) -> T {

0 commit comments

Comments
 (0)