/// Parse a series of expression, separated by commas and/or newlines.
/// Occurs as part of e.g. function calls, or array literals.
Parse a series of expression, separated by commas and/or newlines.
Occurs as part of e.g. function calls, or array literals.
Parse a series of expression separated by commas and / or newlines . Occurs as part of e . g . function calls or array literals .
pub fn parse_multi_expression(mut cursor: ParseCursor) -> ParseRes<Vec<ExpressionParselets>> {
    let mut expressions = vec![];
    cursor.skip_while(|lexeme| matches!(lexeme, Lexeme::Newline(_)));
    while let Ok((expr_cursor, expr)) = parse_expression(cursor.fork()) {
        expressions.push(expr);
        let mut separator_cursor = expr_cursor.fork();
        match separator_cursor.take() {
            Ok(token) => match token {
                // There is a separator, continue for another expression.
                Lexeme::Comma(_) | Lexeme::Newline(_) => {
                    separator_cursor.skip_while(|lexeme| lexeme.is_newline());
                }
                // No separator, so this is the end of the multi-expression - or a syntax
                // error, but that's for the next parser to find out. Revert eating separator.
                _not_a_separator => return Ok((expr_cursor, expressions)),
            },
            Err(_) => {
                // Reached the end of input. There should probably be a closing symbol,
                // but that is up to the outer parser (which knows what the opening is).
                return Ok((expr_cursor, expressions));
            }
        }
        cursor = separator_cursor
    }
    // Did not find another expression; apparently the last expression had a
    // comma/newline, and we are done.
    Ok((cursor, expressions))
}
pub fn parse_multi_expression ( mut cursor : ParseCursor ) -> ParseRes < Vec < ExpressionParselets > > { let mut expressions = vec ! [ ] ; cursor . skip_while ( | lexeme | matches ! ( lexeme Lexeme Newline ( ) ) ) ; while let Ok ( ( expr_cursor , expr ) ) = parse_expression ( cursor . fork ( ) ) { expressions . push ( expr ) ; let mut separator_cursor = expr_cursor . fork ( ) ; match separator_cursor . take ( ) { Ok ( token ) => match token { // There is a separator, continue for another expression. Lexeme :: Comma ( _ ) | Lexeme :: Newline ( _ ) => { separator_cursor . skip_while ( | lexeme | lexeme . is_newline ( ) ) ; } // No separator, so this is the end of the multi-expression - or a syntax // error, but that's for the next parser to find out. Revert eating separator. _not_a_separator => return Ok ( ( expr_cursor , expressions ) ) , } , Err ( _ ) => { // Reached the end of input. There should probably be a closing symbol, // but that is up to the outer parser (which knows what the opening is). return Ok ( ( expr_cursor , expressions ) ) ; } } cursor = separator_cursor } // Did not find another expression; apparently the last expression had a // comma/newline, and we are done. Ok ( ( cursor , expressions ) ) }
Parse a series of expression, separated by commas and/or newlines.
Parse a series of expression separated by commas and / or newlines .
cursor
ParseCursor