Struct sway_parse::Parser

source ·
pub struct Parser<'a, 'e> { /* private fields */ }

Implementations§

source§

impl<'a, 'e> Parser<'a, 'e>

source

pub fn new( handler: &'e Handler, token_stream: &'a TokenStream ) -> Parser<'a, 'e>

source

pub fn emit_error(&mut self, kind: ParseErrorKind) -> ErrorEmitted

source

pub fn emit_error_with_span( &mut self, kind: ParseErrorKind, span: Span ) -> ErrorEmitted

source

pub fn take<P: Peek>(&mut self) -> Option<P>

Eats a P in its canonical way by peeking.

Unlike Parser::peek, this method advances the parser on success, but not on failure.

source

pub fn peek<P: Peek>(&self) -> Option<P>

Tries to peek a P in its canonical way.

Either way, on success or failure, the parser is not advanced.

source

pub fn guarded_parse_with_recovery<'original, P: Peek, T: Parse>( &'original mut self ) -> Result<Option<T>, Recoverer<'original, 'a, 'e>>

This function do three things 1 - it peeks P; 2 - it forks the current parse, and try to parse T using the fork. If it success it put the original parse at the same state as the forked; 3 - if it fails ir returns a Recoverer together with the ErrorEmited.

This recoverer can be used to put the forked parsed back in track and then sync the original parser to allow the parsing to continue.

source

pub fn try_parse<T: Parse>( &mut self, append_diagnostics: bool ) -> Result<T, ErrorEmitted>

Parses a T in its canonical way. Do not advance the parser on failure

source

pub fn parse<T: Parse>(&mut self) -> Result<T, ErrorEmitted>

Parses a T in its canonical way.

source

pub fn guarded_parse<G: Peek, T: Parse>( &mut self ) -> Result<Option<T>, ErrorEmitted>

Parses T given that the guard G was successfully peeked.

Useful to parse e.g., $keyword $stuff as a unit where $keyword is your guard.

source

pub fn parse_to_end<T: ParseToEnd>( self ) -> Result<(T, ParserConsumed<'a>), ErrorEmitted>

source

pub fn try_parse_to_end<T: Parse>( self ) -> Result<Option<(T, ParserConsumed<'a>)>, ErrorEmitted>

source

pub fn enter_delimited( &mut self, expected_delimiter: Delimiter ) -> Option<(Parser<'_, '_>, Span)>

source

pub fn is_empty(&self) -> bool

source

pub fn check_empty(&self) -> Option<ParserConsumed<'a>>

source

pub fn debug_tokens(&self) -> &[TokenTree]

source

pub fn ban_visibility_qualifier( &mut self, vis: &Option<PubToken> ) -> Result<(), ErrorEmitted>

Errors given Some(PubToken).

source

pub fn full_span(&self) -> &Span

source

pub fn consume_while_line_equals(&mut self, line: usize)

Consume tokens while its line equals to line.

Warning

To calculate lines the original source code needs to be transversed.

source

pub fn has_errors(&self) -> bool

source

pub fn has_warnings(&self) -> bool

Auto Trait Implementations§

§

impl<'a, 'e> !RefUnwindSafe for Parser<'a, 'e>

§

impl<'a, 'e> !Send for Parser<'a, 'e>

§

impl<'a, 'e> !Sync for Parser<'a, 'e>

§

impl<'a, 'e> Unpin for Parser<'a, 'e>

§

impl<'a, 'e> !UnwindSafe for Parser<'a, 'e>

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> Same<T> for T

§

type Output = T

Should always be Self
§

impl<T> StorageAsMut for T

§

fn storage<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,

§

fn storage_as_mut<Type>(&mut self) -> StorageMut<'_, Self, Type>where Type: Mappable,

§

impl<T> StorageAsRef for T

§

fn storage<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,

§

fn storage_as_ref<Type>(&self) -> StorageRef<'_, Self, Type>where Type: Mappable,

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V