rustc_lexer::cursor

Struct 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 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 fn third(&self) -> char

Peeks the third 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 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.

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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