Struct sway_parse::Parser
source · pub struct Parser<'a, 'e> { /* private fields */ }Implementations§
source§impl<'a, 'e> Parser<'a, 'e>
impl<'a, 'e> Parser<'a, 'e>
pub fn new( handler: &'e Handler, token_stream: &'a TokenStream ) -> Parser<'a, 'e>
pub fn emit_error(&mut self, kind: ParseErrorKind) -> ErrorEmitted
pub fn emit_error_with_span( &mut self, kind: ParseErrorKind, span: Span ) -> ErrorEmitted
sourcepub fn take<P: Peek>(&mut self) -> Option<P>
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.
sourcepub fn peek<P: Peek>(&self) -> Option<P>
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.
sourcepub fn guarded_parse_with_recovery<'original, P: Peek, T: Parse>(
&'original mut self
) -> Result<Option<T>, Recoverer<'original, 'a, 'e>>
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.
sourcepub fn try_parse<T: Parse>(
&mut self,
append_diagnostics: bool
) -> Result<T, ErrorEmitted>
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
sourcepub fn parse<T: Parse>(&mut self) -> Result<T, ErrorEmitted>
pub fn parse<T: Parse>(&mut self) -> Result<T, ErrorEmitted>
Parses a T in its canonical way.
sourcepub fn guarded_parse<G: Peek, T: Parse>(
&mut self
) -> Result<Option<T>, ErrorEmitted>
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.
pub fn parse_to_end<T: ParseToEnd>( self ) -> Result<(T, ParserConsumed<'a>), ErrorEmitted>
pub fn try_parse_to_end<T: Parse>( self ) -> Result<Option<(T, ParserConsumed<'a>)>, ErrorEmitted>
pub fn enter_delimited( &mut self, expected_delimiter: Delimiter ) -> Option<(Parser<'_, '_>, Span)>
pub fn is_empty(&self) -> bool
pub fn check_empty(&self) -> Option<ParserConsumed<'a>>
pub fn debug_tokens(&self) -> &[TokenTree]
sourcepub fn ban_visibility_qualifier(
&mut self,
vis: &Option<PubToken>
) -> Result<(), ErrorEmitted>
pub fn ban_visibility_qualifier( &mut self, vis: &Option<PubToken> ) -> Result<(), ErrorEmitted>
Errors given Some(PubToken).
pub fn full_span(&self) -> &Span
sourcepub fn consume_while_line_equals(&mut self, line: usize)
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.