Struct rustc_lexer::cursor::Cursor

source ·
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>

source

pub fn new(input: &'a str) -> Cursor<'a>

source

pub fn as_str(&self) -> &'a str

source

pub(crate) fn prev(&self) -> char

Returns the last eaten symbol (or '\0' in release builds). (For debug assertions only.)

source

pub(crate) 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.

source

pub(crate) fn second(&self) -> char

Peeks the second symbol from the input stream without consuming it.

source

pub(crate) fn is_eof(&self) -> bool

Checks if there is nothing more to consume.

source

pub(crate) fn pos_within_token(&self) -> u32

Returns amount of already consumed symbols.

source

pub(crate) fn reset_pos_within_token(&mut self)

Resets the number of bytes consumed to 0.

source

pub(crate) fn bump(&mut self) -> Option<char>

Moves to the next character.

source

pub(crate) fn eat_while(&mut self, predicate: impl FnMut(char) -> bool)

Eats symbols while predicate returns true or until the end of file is reached.

source§

impl Cursor<'_>

source

pub fn advance_token(&mut self) -> Token

Parses a token from the input string.

source

pub(crate) fn line_comment(&mut self) -> TokenKind

source

pub(crate) fn block_comment(&mut self) -> TokenKind

source

pub(crate) fn whitespace(&mut self) -> TokenKind

source

pub(crate) fn raw_ident(&mut self) -> TokenKind

source

pub(crate) fn ident_or_unknown_prefix(&mut self) -> TokenKind

source

pub(crate) fn fake_ident_or_unknown_prefix(&mut self) -> TokenKind

source

pub(crate) fn c_or_byte_string( &mut self, mk_kind: impl FnOnce(bool) -> LiteralKind, mk_kind_raw: impl FnOnce(Option<u8>) -> LiteralKind, single_quoted: Option<fn(_: bool) -> LiteralKind> ) -> TokenKind

source

pub(crate) fn number(&mut self, first_digit: char) -> LiteralKind

source

pub(crate) fn lifetime_or_char(&mut self) -> TokenKind

source

pub(crate) fn single_quoted_string(&mut self) -> bool

source

pub(crate) fn double_quoted_string(&mut self) -> bool

Eats double-quoted string and returns true if string is terminated.

source

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.

source

pub(crate) fn raw_string_unvalidated( &mut self, prefix_len: u32 ) -> Result<u32, RawStrError>

source

pub(crate) fn eat_decimal_digits(&mut self) -> bool

source

pub(crate) fn eat_hexadecimal_digits(&mut self) -> bool

source

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.

source

pub(crate) fn eat_literal_suffix(&mut self)

source

pub(crate) fn eat_identifier(&mut self)

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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