pub struct Cursor<'a> {
len_remaining: usize,
chars: Chars<'a>,
prev: char,
}
Expand description
Peekable iterator over a char sequence.
Next characters can be peeked via first
method,
and position can be shifted forward via bump
method.
Fields§
§len_remaining: usize
§chars: Chars<'a>
Iterator over chars. Slightly faster than a &str.
prev: char
Implementations§
Source§impl<'a> Cursor<'a>
impl<'a> Cursor<'a>
pub fn new(input: &'a str) -> Cursor<'a>
pub fn as_str(&self) -> &'a str
Sourcepub(crate) fn prev(&self) -> char
pub(crate) fn prev(&self) -> char
Returns the last eaten symbol (or '\0'
in release builds).
(For debug assertions only.)
Sourcepub fn first(&self) -> char
pub fn first(&self) -> char
Peeks the next symbol from the input stream without consuming it.
If requested position doesn’t exist, EOF_CHAR
is returned.
However, getting EOF_CHAR
doesn’t always mean actual end of file,
it should be checked with is_eof
method.
Sourcepub(crate) fn second(&self) -> char
pub(crate) fn second(&self) -> char
Peeks the second symbol from the input stream without consuming it.
Sourcepub(crate) fn pos_within_token(&self) -> u32
pub(crate) fn pos_within_token(&self) -> u32
Returns amount of already consumed symbols.
Sourcepub(crate) fn reset_pos_within_token(&mut self)
pub(crate) fn reset_pos_within_token(&mut self)
Resets the number of bytes consumed to 0.
Source§impl Cursor<'_>
impl Cursor<'_>
Sourcepub fn advance_token(&mut self) -> Token
pub fn advance_token(&mut self) -> Token
Parses a token from the input string.
pub(crate) fn line_comment(&mut self) -> TokenKind
pub(crate) fn block_comment(&mut self) -> TokenKind
pub(crate) fn whitespace(&mut self) -> TokenKind
pub(crate) fn raw_ident(&mut self) -> TokenKind
pub(crate) fn ident_or_unknown_prefix(&mut self) -> TokenKind
pub(crate) fn invalid_ident(&mut self) -> TokenKind
pub(crate) fn c_or_byte_string( &mut self, mk_kind: fn(_: bool) -> LiteralKind, mk_kind_raw: fn(_: Option<u8>) -> LiteralKind, single_quoted: Option<fn(_: bool) -> LiteralKind>, ) -> TokenKind
pub(crate) fn number(&mut self, first_digit: char) -> LiteralKind
pub(crate) fn lifetime_or_char(&mut self) -> TokenKind
pub(crate) fn single_quoted_string(&mut self) -> bool
Sourcepub(crate) fn double_quoted_string(&mut self) -> bool
pub(crate) fn double_quoted_string(&mut self) -> bool
Eats double-quoted string and returns true if string is terminated.
Sourcepub fn guarded_double_quoted_string(&mut self) -> Option<GuardedStr>
pub fn guarded_double_quoted_string(&mut self) -> Option<GuardedStr>
Attempt to lex for a guarded string literal.
Used by rustc_parse::lexer
to lex for guarded strings
conditionally based on edition.
Note: this will not reset the Cursor
when a
guarded string is not found. It is the caller’s
responsibility to do so.
Sourcepub(crate) fn raw_double_quoted_string(
&mut self,
prefix_len: u32,
) -> Result<u8, RawStrError>
pub(crate) fn raw_double_quoted_string( &mut self, prefix_len: u32, ) -> Result<u8, RawStrError>
Eats the double-quoted string and returns n_hashes
and an error if encountered.
pub(crate) fn raw_string_unvalidated( &mut self, prefix_len: u32, ) -> Result<u32, RawStrError>
pub(crate) fn eat_decimal_digits(&mut self) -> bool
pub(crate) fn eat_hexadecimal_digits(&mut self) -> bool
Sourcepub(crate) fn eat_float_exponent(&mut self) -> bool
pub(crate) fn eat_float_exponent(&mut self) -> bool
Eats the float exponent. Returns true if at least one digit was met, and returns false otherwise.
pub(crate) fn eat_literal_suffix(&mut self)
pub(crate) fn eat_identifier(&mut self)
Auto Trait Implementations§
impl<'a> Freeze for Cursor<'a>
impl<'a> RefUnwindSafe for Cursor<'a>
impl<'a> Send for Cursor<'a>
impl<'a> Sync for Cursor<'a>
impl<'a> Unpin for Cursor<'a>
impl<'a> UnwindSafe for Cursor<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes