/// The entry point for this library. Pass a `Read` containing the config file
/// and get back a `ParsedConfigFile`.
The entry point for this library. Pass a `Read` containing the config file
and get back a `ParsedConfigFile`.
The entry point for this library . Pass a ` Read ` containing the config file and get back a ` ParsedConfigFile ` .
pub fn parse<R>(input: R) -> errors::Result<ParsedConfigFile> where R: Read {
    let buf_reader = BufReader::new(input);
    let mut success_lines = Vec::new();
    let mut warning_lines = Vec::new();
    let mut inline_file_parse_state: Option<InlineFileParseState> = None;
    for (line_index, line_result) in buf_reader.lines().enumerate() {
        let line_no = line_index;
        let line = line_result.chain_err(|| "Error reading input")?;
        let mut reset_inline_state = false;
        if let Some(ref mut parse_state) = inline_file_parse_state {
            if parse_state.is_completed_by_line(&line) {
                success_lines.push(parse_state.to_config_line());
                reset_inline_state = true
            } else {
                parse_state.add_line(line.clone());
                continue;
            }
        }
        if reset_inline_state {
            inline_file_parse_state = None;
            continue;
        }
        if let Some(captures) = INLINE_START_REGEX.captures(&line) {
            let option = &captures[1];
            if INLINE_FILE_OPTIONS.contains(option) {
                inline_file_parse_state = Some(InlineFileParseState::new(line_no, option.to_string()));
                continue;
            }
        }
        if line.trim().starts_with('#') || line.trim().is_empty() {
            continue
        }
        let line_without_comments = COMMENT_REGEX.replace(&line, "");
        let command_and_args: Vec<&str> = line_without_comments.split_whitespace().collect();
        let command = command_and_args[0];
        let args = &command_and_args[1..];
        match config_directive::parse_line(command, args) {
            config_directive::LineParseResult::NoMatchingCommand => {
                warning_lines.push(ConfigLine{number: line_no as i32, result: ParseWarning::NoMatchingCommand})
            },
            config_directive::LineParseResult::NotEnoughArguments => {
                warning_lines.push(ConfigLine{number: line_no as i32, result: ParseWarning::NotEnoughArguments})
            },
            config_directive::LineParseResult::Success(directive) => {
                success_lines.push(ConfigLine{ number: line_no as i32, result: directive })
            }
        }
    }
    Ok(ParsedConfigFile{
        success_lines: success_lines,
        warning_lines: warning_lines,
    })
}
pub fn parse < R > ( input : R ) -> errors :: Result < ParsedConfigFile > where R : Read { let buf_reader = BufReader :: new ( input ) ; let mut success_lines = Vec :: new ( ) ; let mut warning_lines = Vec :: new ( ) ; let mut inline_file_parse_state : Option < InlineFileParseState > = None ; for ( line_index , line_result ) in buf_reader . lines ( ) . enumerate ( ) { let line_no = line_index ; let line = line_result . chain_err ( | | " " ) ? ; let mut reset_inline_state = false ; if let Some ( ref mut parse_state ) = inline_file_parse_state { if parse_state . is_completed_by_line ( & line ) { success_lines . push ( parse_state . to_config_line ( ) ) ; reset_inline_state = true } else { parse_state . add_line ( line . clone ( ) ) ; continue ; } } if reset_inline_state { inline_file_parse_state = None ; continue ; } if let Some ( captures ) = INLINE_START_REGEX . captures ( & line ) { let option = & captures [ 1 ] ; if INLINE_FILE_OPTIONS . contains ( option ) { inline_file_parse_state = Some ( InlineFileParseState :: new ( line_no , option . to_string ( ) ) ) ; continue ; } } if line . trim ( ) . starts_with ( '#' ) || line . trim ( ) . is_empty ( ) { continue } let line_without_comments = COMMENT_REGEX . replace ( & line , " " ) ; let command_and_args : Vec < & str > = line_without_comments . split_whitespace ( ) . collect ( ) ; let command = command_and_args [ 0 ] ; let args = & command_and_args [ 1 .. ] ; match config_directive :: parse_line ( command , args ) { config_directive :: LineParseResult :: NoMatchingCommand => { warning_lines . push ( ConfigLine { number : line_no as i32 , result : ParseWarning :: NoMatchingCommand } ) } , config_directive :: LineParseResult :: NotEnoughArguments => { warning_lines . push ( ConfigLine { number : line_no as i32 , result : ParseWarning :: NotEnoughArguments } ) } , config_directive :: LineParseResult :: Success ( directive ) => { success_lines . push ( ConfigLine { number : line_no as i32 , result : directive } ) } } } Ok ( ParsedConfigFile { success_lines : success_lines , warning_lines : warning_lines , } ) }
The entry point for this library.
The entry point for this library .
input
R