Make rustc_lexer::cursor::Cursor public.
`Cursor` is currently hidden, and the main tokenization path uses `rustc_lexer::first_token` which involves constructing a new `Cursor` for every single token, which is weird. Also, `first_token` also can't handle empty input, so callers have to check for that first. This commit makes `Cursor` public, so `StringReader` can contain a `Cursor`, which results in a simpler structure. The commit also changes `StringReader::advance_token` so it returns an `Option<Token>`, simplifying the the empty input case.
This commit is contained in:
@@ -4,7 +4,7 @@ use std::str::Chars;
|
||||
///
|
||||
/// Next characters can be peeked via `first` method,
|
||||
/// and position can be shifted forward via `bump` method.
|
||||
pub(crate) struct Cursor<'a> {
|
||||
pub struct Cursor<'a> {
|
||||
initial_len: usize,
|
||||
/// Iterator over chars. Slightly faster than a &str.
|
||||
chars: Chars<'a>,
|
||||
@@ -15,7 +15,7 @@ pub(crate) struct Cursor<'a> {
|
||||
pub(crate) const EOF_CHAR: char = '\0';
|
||||
|
||||
impl<'a> Cursor<'a> {
|
||||
pub(crate) fn new(input: &'a str) -> Cursor<'a> {
|
||||
pub fn new(input: &'a str) -> Cursor<'a> {
|
||||
Cursor {
|
||||
initial_len: input.len(),
|
||||
chars: input.chars(),
|
||||
|
||||
Reference in New Issue
Block a user