fn scan_comment(&mut self) -> Option<TokenAndSpan> {
        match self.curr {
            Some(c) => {
                if c.is_whitespace() {
                    self.span_diagnostic.span_err(codemap::mk_sp(self.last_pos, self.last_pos),
                                    "called consume_any_line_comment, but there was whitespace");
                }
            },
            None => { }
        }

        if self.curr_is('/') {
            match self.nextch() {
                Some('/') => {
                    self.bump();
                    self.bump();
                    // line comments starting with "///" or "//!" are doc-comments
                    if self.curr_is('/') || self.curr_is('!') {
                        let start_bpos = self.pos - BytePos(3);
                        while !self.is_eof() {
                            match self.curr.unwrap() {
                                '\n' => break,
                                '\r' => {
                                    if self.nextch_is('\n') {
                                        // CRLF
                                        break
                                    } else {
                                        self.err_span_(self.last_pos, self.pos,
                                                       "bare CR not allowed in doc-comment");
                                    }
                                }
                                _ => ()
                            }
                            self.bump();
                        }
                        return self.with_str_from(start_bpos, |string| {
                            // but comments with only more "/"s are not
                            let tok = if is_doc_comment(string) {
                                token::DocComment(token::intern(string))
                            } else {
                                token::Comment
                            };

                            return Some(TokenAndSpan{
                                tok: tok,
                                sp: codemap::mk_sp(start_bpos, self.last_pos)
                            });
                        });
                    } else {
                        let start_bpos = self.last_pos - BytePos(2);
                        while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
                        return Some(TokenAndSpan {
                            tok: token::Comment,
                            sp: codemap::mk_sp(start_bpos, self.last_pos)
                        });
                    }
                }
                Some('*') => {
                    self.bump(); self.bump();
                    self.scan_block_comment()
                }
                _ => None
            }
        } else if self.curr_is('#') {
            if self.nextch_is('!') {

                // Parse an inner attribute.
                if self.nextnextch_is('[') {
                    return None;
                }

                // I guess this is the only way to figure out if
                // we're at the beginning of the file...
                let cmap = CodeMap::new();
                cmap.files.borrow_mut().push(self.filemap.clone());
                let loc = cmap.lookup_char_pos_adj(self.last_pos);
                debug!("Skipping a shebang");
                if loc.line == 1 && loc.col == CharPos(0) {
                    // FIXME: Add shebang "token", return it
                    let start = self.last_pos;
                    while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
                    return Some(TokenAndSpan {
                        tok: token::Shebang(self.name_from(start)),
                        sp: codemap::mk_sp(start, self.last_pos)
                    });
                }
            }
            None
        } else {
            None
        }
    }
/// PRECONDITION: self.curr is not whitespace
/// Eats any kind of comment.
self.curr is not whitespace
Eats any kind of comment.
self . curr is not whitespace Eats any kind of comment .
fn scan_comment(&mut self) -> Option<TokenAndSpan> {
        match self.curr {
            Some(c) => {
                if c.is_whitespace() {
                    self.span_diagnostic.span_err(codemap::mk_sp(self.last_pos, self.last_pos),
                                    "called consume_any_line_comment, but there was whitespace");
                }
            },
            None => { }
        }
        if self.curr_is('/') {
            match self.nextch() {
                Some('/') => {
                    self.bump();
                    self.bump();
                    // line comments starting with "///" or "//!" are doc-comments
                    if self.curr_is('/') || self.curr_is('!') {
                        let start_bpos = self.pos - BytePos(3);
                        while !self.is_eof() {
                            match self.curr.unwrap() {
                                '\n' => break,
                                '\r' => {
                                    if self.nextch_is('\n') {
                                        // CRLF
                                        break
                                    } else {
                                        self.err_span_(self.last_pos, self.pos,
                                                       "bare CR not allowed in doc-comment");
                                    }
                                }
                                _ => ()
                            }
                            self.bump();
                        }
                        return self.with_str_from(start_bpos, |string| {
                            // but comments with only more "/"s are not
                            let tok = if is_doc_comment(string) {
                                token::DocComment(token::intern(string))
                            } else {
                                token::Comment
                            };
                            return Some(TokenAndSpan{
                                tok: tok,
                                sp: codemap::mk_sp(start_bpos, self.last_pos)
                            });
                        });
                    } else {
                        let start_bpos = self.last_pos - BytePos(2);
                        while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
                        return Some(TokenAndSpan {
                            tok: token::Comment,
                            sp: codemap::mk_sp(start_bpos, self.last_pos)
                        });
                    }
                }
                Some('*') => {
                    self.bump(); self.bump();
                    self.scan_block_comment()
                }
                _ => None
            }
        } else if self.curr_is('#') {
            if self.nextch_is('!') {
                // Parse an inner attribute.
                if self.nextnextch_is('[') {
                    return None;
                }
                // I guess this is the only way to figure out if
                // we're at the beginning of the file...
                let cmap = CodeMap::new();
                cmap.files.borrow_mut().push(self.filemap.clone());
                let loc = cmap.lookup_char_pos_adj(self.last_pos);
                debug!("Skipping a shebang");
                if loc.line == 1 && loc.col == CharPos(0) {
                    // FIXME: Add shebang "token", return it
                    let start = self.last_pos;
                    while !self.curr_is('\n') && !self.is_eof() { self.bump(); }
                    return Some(TokenAndSpan {
                        tok: token::Shebang(self.name_from(start)),
                        sp: codemap::mk_sp(start, self.last_pos)
                    });
                }
            }
            None
        } else {
            None
        }
    }
fn scan_comment ( & mut self ) -> Option < TokenAndSpan > { match self . curr { Some ( c ) => { if c . is_whitespace ( ) { self . span_diagnostic . span_err ( codemap :: mk_sp ( self . last_pos , self . last_pos ) , " " ) ; } } , None => { } } if self . curr_is ( '/' ) { match self . nextch ( ) { Some ( '/' ) => { self . bump ( ) ; self . bump ( ) ; // line comments starting with "///" or "//!" are doc-comments if self . curr_is ( '/' ) || self . curr_is ( '!' ) { let start_bpos = self . pos - BytePos ( 3 ) ; while ! self . is_eof ( ) { match self . curr . unwrap ( ) { '\n' => break , '\r' => { if self . nextch_is ( '\n' ) { // CRLF break } else { self . err_span_ ( self . last_pos , self . pos , " " ) ; } } _ => ( ) } self . bump ( ) ; } return self . with_str_from ( start_bpos , | string | { // but comments with only more "/"s are not let tok = if is_doc_comment ( string ) { token :: DocComment ( token :: intern ( string ) ) } else { token :: Comment } ; return Some ( TokenAndSpan { tok : tok , sp : codemap :: mk_sp ( start_bpos , self . last_pos ) } ) ; } ) ; } else { let start_bpos = self . last_pos - BytePos ( 2 ) ; while ! self . curr_is ( '\n' ) && ! self . is_eof ( ) { self . bump ( ) ; } return Some ( TokenAndSpan { tok : token :: Comment , sp : codemap :: mk_sp ( start_bpos , self . last_pos ) } ) ; } } Some ( '*' ) => { self . bump ( ) ; self . bump ( ) ; self . scan_block_comment ( ) } _ => None } } else if self . curr_is ( '#' ) { if self . nextch_is ( '!' ) { // Parse an inner attribute. if self . nextnextch_is ( '[' ) { return None ; } // I guess this is the only way to figure out if // we're at the beginning of the file... let cmap = CodeMap :: new ( ) ; cmap . files . borrow_mut ( ) . push ( self . filemap . clone ( ) ) ; let loc = cmap . lookup_char_pos_adj ( self . last_pos ) ; debug ! ( " " ) ; if loc . line == 1 && loc . col == CharPos ( 0 ) { // FIXME: Add shebang "token", return it let start = self . last_pos ; while ! self . curr_is ( '\n' ) && ! self . is_eof ( ) { self . bump ( ) ; } return Some ( TokenAndSpan { tok : token :: Shebang ( self . name_from ( start ) ) , sp : codemap :: mk_sp ( start , self . last_pos ) } ) ; } } None } else { None } }
PRECONDITION: self.curr is not whitespace
Eats any kind of comment.
PRECONDITION : self . curr is not whitespace Eats any kind of comment .
&mut self