pub fn parse(data: &str) -> Vec<Comment> {
    let mut comments = vec![];
    let mut chars = data.chars().enumerate().peekable();
    // let v: String = chars;
    while let Some((i, v)) = chars.next() {
        if v == '/' {
            // ::Line comment
            let (comment, length) = parse_comment(&mut chars);
            comments.push(Comment {
                comment,
                comment_type: CommentType::Line,
                position: Position::new(i, length),
            });
        } else if v.is_whitespace() {
            let mut v = v;
            while let Some((_, next_v)) = chars.peek() {
                if v == '\n' {
                    break;
                };
                if !next_v.is_whitespace() {
                    // not an empty line
                    break;
                }
                v = if let Some((_, new_v)) = chars.next() {
                    new_v
                } else {
                    break;
                };
            }
            if v == '\n' {
                // found empty line
                // ::Separator
                comments.push(Comment {
                    comment: String::new(),
                    comment_type: CommentType::Separator,
                    position: Position::new(i, 0),
                });
            }
        } else if !v.is_whitespace() {
            // ::Trail comment
            // skip up to `/` or new line
            for (i, v) in &mut chars {
                match v {
                    '/' => {
                        let (comment, length) = parse_comment(&mut chars);
                        comments.push(Comment {
                            comment,
                            comment_type: CommentType::Trail,
                            position: Position::new(i, length),
                        });
                        break;
                    }
                    '\n' => break,
                    _ => {}
                };
            }
        }
    }
    comments
}
// comments parser is separte from types parser for simplicity
comments parser is separte from types parser for simplicity
comments parser is separte from types parser for simplicity
pub fn parse(data: &str) -> Vec<Comment> {
    let mut comments = vec![];
    let mut chars = data.chars().enumerate().peekable();
    // let v: String = chars;
    while let Some((i, v)) = chars.next() {
        if v == '/' {
            // ::Line comment
            let (comment, length) = parse_comment(&mut chars);
            comments.push(Comment {
                comment,
                comment_type: CommentType::Line,
                position: Position::new(i, length),
            });
        } else if v.is_whitespace() {
            let mut v = v;
            while let Some((_, next_v)) = chars.peek() {
                if v == '\n' {
                    break;
                };
                if !next_v.is_whitespace() {
                    // not an empty line
                    break;
                }
                v = if let Some((_, new_v)) = chars.next() {
                    new_v
                } else {
                    break;
                };
            }
            if v == '\n' {
                // found empty line
                // ::Separator
                comments.push(Comment {
                    comment: String::new(),
                    comment_type: CommentType::Separator,
                    position: Position::new(i, 0),
                });
            }
        } else if !v.is_whitespace() {
            // ::Trail comment
            // skip up to `/` or new line
            for (i, v) in &mut chars {
                match v {
                    '/' => {
                        let (comment, length) = parse_comment(&mut chars);
                        comments.push(Comment {
                            comment,
                            comment_type: CommentType::Trail,
                            position: Position::new(i, length),
                        });
                        break;
                    }
                    '\n' => break,
                    _ => {}
                };
            }
        }
    }
    comments
}
pub fn parse ( data : & str ) -> Vec < Comment > { let mut comments = vec ! [ ] ; let mut chars = data . chars ( ) . enumerate ( ) . peekable ( ) ; // let v: String = chars; while let Some ( ( i , v ) ) = chars . next ( ) { if v == '/' { // ::Line comment let ( comment , length ) = parse_comment ( & mut chars ) ; comments . push ( Comment { comment , comment_type : CommentType :: Line , position : Position :: new ( i , length ) , } ) ; } else if v . is_whitespace ( ) { let mut v = v ; while let Some ( ( _ , next_v ) ) = chars . peek ( ) { if v == '\n' { break ; } ; if ! next_v . is_whitespace ( ) { // not an empty line break ; } v = if let Some ( ( _ , new_v ) ) = chars . next ( ) { new_v } else { break ; } ; } if v == '\n' { // found empty line // ::Separator comments . push ( Comment { comment : String :: new ( ) , comment_type : CommentType :: Separator , position : Position :: new ( i , 0 ) , } ) ; } } else if ! v . is_whitespace ( ) { // ::Trail comment // skip up to `/` or new line for ( i , v ) in & mut chars { match v { '/' => { let ( comment , length ) = parse_comment ( & mut chars ) ; comments . push ( Comment { comment , comment_type : CommentType :: Trail , position : Position :: new ( i , length ) , } ) ; break ; } '\n' => break , _ => { } } ; } } } comments }
comments parser is separte from types parser for simplicity
comments parser is separte from types parser for simplicity
data
&str
data
&str