PtxTokenStream

Struct PtxTokenStream 

Source
pub struct PtxTokenStream<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> PtxTokenStream<'a>

Source

pub fn new(tokens: &'a [(PtxToken, Span)]) -> Self

Source

pub fn peek(&self) -> Result<&'a (PtxToken, Span), PtxParseError>

Peek at the next token without consuming it.

Source

pub fn consume(&mut self) -> Result<&'a (PtxToken, Span), PtxParseError>

Consume and return the next token.

Source

pub fn expect( &mut self, expected: &PtxToken, ) -> Result<&'a (PtxToken, Span), PtxParseError>

Check if the next token is the expected type, and if so, consume it. Otherwise, return an error and do NOT consume the token.

Source

pub fn expect_identifier(&mut self) -> Result<(String, Span), PtxParseError>

Check if the next token is an identifier, and if so, consume it and return the String.

Source

pub fn expect_register(&mut self) -> Result<(String, Span), PtxParseError>

Check if the next token is a register, and if so, consume it and return the String.

Source

pub fn expect_directive(&mut self) -> Result<(String, Span), PtxParseError>

Check if the next token is a directive (Dot + Identifier), and if so, consume them and return the String.

Source

pub fn expect_modifier(&mut self) -> Result<(String, Span), PtxParseError>

Check if the next token is a directive that represents a modifier (type, state space, etc.). This is an alias for expect_directive for semantic clarity when parsing modifiers.

Source

pub fn expect_double_colon(&mut self) -> Result<(), PtxParseError>

Expect and consume a double colon (::) token sequence.

Source

pub fn expect_strings( &mut self, candidates: &[&str], ) -> Result<usize, PtxParseError>

Try to match and consume a sequence of tokens that matches one of the candidate strings. Returns the index of the matched candidate.

This is used for parsing modifiers that may contain :: sequences like “.to::cluster” The candidates should include the leading dot (e.g., [“.to::cluster”, “.to::cta”])

Source

pub fn expect_string(&mut self, expected: &str) -> Result<(), PtxParseError>

Source

pub fn try_match_string(&mut self, pattern: &str) -> bool

Try to match a string pattern by consuming characters from the stream.

§Behavior

Matches the pattern character-by-character against the token stream. Tokens are converted to their string representation and matched from char_offset. If all characters match, the stream is advanced and returns true. If any character fails to match, the stream is reset and returns false.

§Returns
  • true if the entire pattern was successfully matched (chars consumed)
  • false if matching failed at any point (stream position restored)
Source

pub fn check<F>(&self, predicate: F) -> bool
where F: FnOnce(&PtxToken) -> bool,

Check if the next token matches a specific pattern.

Source

pub fn expect_complete(&self) -> Result<(), PtxParseError>

Expect that we’ve consumed a complete token (not stopped in the middle). This should be called at the end of each struct parser to verify that character-level parsing has consumed all characters from the current token.

§Returns
  • Ok(()) if char_offset == 0 (no partial token consumption)
  • Err(PtxParseError) if char_offset > 0 (stopped in middle of token)
Source

pub fn consume_if<F>(&mut self, predicate: F) -> Option<&'a (PtxToken, Span)>
where F: FnOnce(&PtxToken) -> bool,

Consume the next token if it matches the predicate.

Source

pub fn position(&self) -> StreamPosition

Get the current position in the stream, for backtracking.

Source

pub fn set_position(&mut self, pos: StreamPosition)

Reset the stream to an old position, for backtracking.

Source

pub fn is_at_end(&self) -> bool

Check if we’ve reached the end of the token stream.

Source

pub fn remaining(&self) -> &'a [(PtxToken, Span)]

Get the remaining tokens.

Source

pub fn peek_char_in_token(&self) -> Option<char>

Peek at the character at the current char_offset within the current token’s string. Returns None if we’re at the end of the current token’s string or if the token has no string content.

Source

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

Consume one character from the current token by advancing char_offset. If we reach the end of the token’s string, advance to the next token and reset char_offset. Returns the consumed character.

Source

pub fn expect_char_in_token( &mut self, expected: char, ) -> Result<char, PtxParseError>

Match a specific character at the current position within the token. Consumes the character if it matches.

Auto Trait Implementations§

§

impl<'a> Freeze for PtxTokenStream<'a>

§

impl<'a> RefUnwindSafe for PtxTokenStream<'a>

§

impl<'a> Send for PtxTokenStream<'a>

§

impl<'a> Sync for PtxTokenStream<'a>

§

impl<'a> Unpin for PtxTokenStream<'a>

§

impl<'a> UnwindSafe for PtxTokenStream<'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.