/// Parse a series of names with types, e.g. for function declarations.
Parse a series of names with types, e.g. for function declarations.
Parse a series of names with types e . g . for function declarations .
pub fn parse_parameters(mut cursor: ParseCursor) -> ParseRes<ParametersParselet> {
    let mut names_seen = HashSet::with_capacity(16);
    let mut params = smallvec![];
    loop {
        let mut iter_cursor = cursor.fork();
        match iter_cursor.take() {
            Ok(Lexeme::Identifier(name)) => {
                if let Some(name) = name.to_simple() {
                    let name = name.clone();
                    if let Lexeme::Colon(_) = iter_cursor.take()? {
                        //TODO @mark: parse complex types like [int, double] or Vec[int]
                        if let Ok((typ_cursor, typ)) = parse_type(iter_cursor) {
                            if names_seen.contains(name.name.as_ustr()) {
                                panic!("duplicate parameter name: {}", &name.name.as_str());
                            }
                            names_seen.insert(name.name.into_ustr());
                            params.push(TypedValueParselet::new(name, typ));
                            cursor = typ_cursor;
                            if cursor.take_if(|lexeme| lexeme.is_newline() || lexeme.is_comma()).is_some() {
                                cursor.skip_while(|lexeme| lexeme.is_newline() || lexeme.is_comma());
                                continue;
                            }
                            break;
                        }
                    } else {
                        panic!("parameter {} is missing a type", name.name);
                    }
                }
            }
            Ok(_) | Err(_) => break,
        }
        break;
    }
    Ok((cursor, ParametersParselet::new(params)))
}
pub fn parse_parameters ( mut cursor : ParseCursor ) -> ParseRes < ParametersParselet > { let mut names_seen = HashSet :: with_capacity ( 16 ) ; let mut params = smallvec ! [ ] ; loop { let mut iter_cursor = cursor . fork ( ) ; match iter_cursor . take ( ) { Ok ( Lexeme :: Identifier ( name ) ) => { if let Some ( name ) = name . to_simple ( ) { let name = name . clone ( ) ; if let Lexeme :: Colon ( _ ) = iter_cursor . take ( ) ? { //TODO @mark: parse complex types like [int, double] or Vec[int] if let Ok ( ( typ_cursor , typ ) ) = parse_type ( iter_cursor ) { if names_seen . contains ( name . name . as_ustr ( ) ) { panic ! ( " " name name as_str ( ) ) ; } names_seen . insert ( name . name . into_ustr ( ) ) ; params . push ( TypedValueParselet :: new ( name , typ ) ) ; cursor = typ_cursor ; if cursor . take_if ( | lexeme | lexeme . is_newline ( ) || lexeme . is_comma ( ) ) . is_some ( ) { cursor . skip_while ( | lexeme | lexeme . is_newline ( ) || lexeme . is_comma ( ) ) ; continue ; } break ; } } else { panic ! ( " " name name ) ; } } } Ok ( _ ) | Err ( _ ) => break , } break ; } Ok ( ( cursor , ParametersParselet :: new ( params ) ) ) }
Parse a series of names with types, e.g.
Parse a series of names with types e . g .
cursor
ParseCursor