// If we hit an error we need to synchronize back to a likely-valid state before we continue parsing again
// To do this, just keep discarding tokens until we think we're at the start of a new statement
If we hit an error we need to synchronize back to a likely-valid state before we continue parsing again
To do this, just keep discarding tokens until we think we're at the start of a new statement
If we hit an error we need to synchronize back to a likely - valid state before we continue parsing again To do this just keep discarding tokens until we think we ' re at the start of a new statement
fn synchronize_stmt(&mut self, inside_block: bool) {
        // Check for either: a token that only appears at the start of a new statement
        // OR try to parse an expression. If we can do it without errors, assume we're in a good state. The expression can be discarded.
        debug!("sync to next stmt...");
        let mut ctx = ErrorContext::new(ContextTag::Sync);
        loop {
            let next = match self.peek() {
                // no more tokens...
                Err(error) if matches!(error.kind(), ErrorKind::EndofTokenStream) => break,
                // skip errors
                Err(..) => continue,  // peek will consume errors
                Ok(token) => token,
            };
            match next.token {
                Token::EOF | Token::Semicolon |
                Token::While  | Token::Loop | Token::For |
                Token::Continue | Token::Break | Token::Return | 
                Token::Label(..) | Token::Assert
                    => break,
                Token::End if inside_block => break,
                _ => if self.parse_expr_variant(&mut ctx).is_ok() {
                    break;
                },
            }
        }
        debug!("done.");
    }
fn synchronize_stmt ( & mut self , inside_block : bool ) { // Check for either: a token that only appears at the start of a new statement // OR try to parse an expression. If we can do it without errors, assume we're in a good state. The expression can be discarded. debug ! ( " " ) ; let mut ctx = ErrorContext :: new ( ContextTag :: Sync ) ; loop { let next = match self . peek ( ) { // no more tokens... Err ( error ) if matches ! ( error kind ( ) ErrorKind EndofTokenStream ) => break , // skip errors Err ( .. ) => continue , // peek will consume errors Ok ( token ) => token , } ; match next . token { Token :: EOF | Token :: Semicolon | Token :: While | Token :: Loop | Token :: For | Token :: Continue | Token :: Break | Token :: Return | Token :: Label ( .. ) | Token :: Assert => break , Token :: End if inside_block => break , _ => if self . parse_expr_variant ( & mut ctx ) . is_ok ( ) { break ; } , } } debug ! ( " " ) ; }
If we hit an error we need to synchronize back to a likely-valid state before we continue parsing again
To do this, just keep discarding tokens until we think we're at the start of a new statement
If we hit an error we need to synchronize back to a likely - valid state before we continue parsing again To do this just keep discarding tokens until we think we ' re at the start of a new statement
&mut self
inside_block
bool