move syntax::parse::lexer::comments -> syntax::util::comments
This commit is contained in:
parent
a1571b6855
commit
27f97aa468
11 changed files with 31 additions and 29 deletions
|
@ -29,7 +29,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use syntax::ast::{self, Attribute, DUMMY_NODE_ID, NodeId, PatKind};
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::parse::lexer::comments::strip_doc_comment_decoration;
|
||||
use syntax::util::comments::strip_doc_comment_decoration;
|
||||
use syntax::print::pprust;
|
||||
use syntax::visit::{self, Visitor};
|
||||
use syntax::print::pprust::{param_to_string, ty_to_string};
|
||||
|
|
|
@ -28,7 +28,7 @@ use rustc::ty::layout::VariantIdx;
|
|||
use rustc::util::nodemap::{FxHashMap, FxHashSet};
|
||||
use syntax::ast::{self, Attribute, AttrStyle, AttrKind, Ident};
|
||||
use syntax::attr;
|
||||
use syntax::parse::lexer::comments;
|
||||
use syntax::util::comments;
|
||||
use syntax::source_map::DUMMY_SP;
|
||||
use syntax_pos::symbol::{Symbol, kw, sym};
|
||||
use syntax_pos::hygiene::MacroKind;
|
||||
|
|
|
@ -86,6 +86,7 @@ pub mod error_codes;
|
|||
|
||||
pub mod util {
|
||||
crate mod classify;
|
||||
pub mod comments;
|
||||
pub mod lev_distance;
|
||||
pub mod node_count;
|
||||
pub mod parser;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use crate::token::{self, Token, TokenKind};
|
||||
use crate::sess::ParseSess;
|
||||
use crate::symbol::{sym, Symbol};
|
||||
use crate::util::comments;
|
||||
|
||||
use errors::{FatalError, DiagnosticBuilder};
|
||||
use syntax_pos::{BytePos, Pos, Span};
|
||||
|
@ -15,7 +16,6 @@ use log::debug;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub mod comments;
|
||||
mod tokentrees;
|
||||
mod unicode_chars;
|
||||
mod unescape_error_reporting;
|
||||
|
@ -179,7 +179,7 @@ impl<'a> StringReader<'a> {
|
|||
rustc_lexer::TokenKind::LineComment => {
|
||||
let string = self.str_from(start);
|
||||
// comments with only more "/"s are not doc comments
|
||||
let tok = if is_doc_comment(string) {
|
||||
let tok = if comments::is_line_doc_comment(string) {
|
||||
self.forbid_bare_cr(start, string, "bare CR not allowed in doc-comment");
|
||||
token::DocComment(Symbol::intern(string))
|
||||
} else {
|
||||
|
@ -192,7 +192,7 @@ impl<'a> StringReader<'a> {
|
|||
let string = self.str_from(start);
|
||||
// block comments starting with "/**" or "/*!" are doc-comments
|
||||
// but comments with only "*"s between two "/"s are not
|
||||
let is_doc_comment = is_block_doc_comment(string);
|
||||
let is_doc_comment = comments::is_block_doc_comment(string);
|
||||
|
||||
if !terminated {
|
||||
let msg = if is_doc_comment {
|
||||
|
@ -643,18 +643,3 @@ impl<'a> StringReader<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn is_doc_comment(s: &str) -> bool {
|
||||
let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') ||
|
||||
s.starts_with("//!");
|
||||
debug!("is {:?} a doc comment? {}", s, res);
|
||||
res
|
||||
}
|
||||
|
||||
fn is_block_doc_comment(s: &str) -> bool {
|
||||
// Prevent `/**/` from being parsed as a doc comment
|
||||
let res = ((s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') ||
|
||||
s.starts_with("/*!")) && s.len() >= 5;
|
||||
debug!("is {:?} a doc comment? {}", s, res);
|
||||
res
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ use super::*;
|
|||
use crate::symbol::Symbol;
|
||||
use crate::source_map::{SourceMap, FilePathMapping};
|
||||
use crate::token;
|
||||
use crate::util::comments::is_doc_comment;
|
||||
use crate::with_default_globals;
|
||||
|
||||
use errors::{Handler, emitter::EmitterWriter};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::{SeqSep, Parser, TokenType, PathStyle};
|
||||
use crate::attr;
|
||||
use crate::ast;
|
||||
use crate::parse::lexer::comments;
|
||||
use crate::util::comments;
|
||||
use crate::token::{self, Nonterminal, DelimToken};
|
||||
use crate::tokenstream::{TokenStream, TokenTree};
|
||||
use crate::source_map::Span;
|
||||
|
|
|
@ -17,7 +17,7 @@ use crate::ast::{
|
|||
};
|
||||
use crate::parse::{Directory, DirectoryOwnership};
|
||||
use crate::parse::lexer::UnmatchedBrace;
|
||||
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||
use crate::util::comments::{doc_comment_style, strip_doc_comment_decoration};
|
||||
use crate::token::{self, Token, TokenKind, DelimToken};
|
||||
use crate::print::pprust;
|
||||
use crate::ptr::P;
|
||||
|
|
|
@ -2,10 +2,10 @@ use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
|
|||
use crate::ast::{SelfKind, GenericBound, TraitBoundModifier};
|
||||
use crate::ast::{Attribute, MacDelimiter, GenericArg};
|
||||
use crate::util::parser::{self, AssocOp, Fixity};
|
||||
use crate::util::comments;
|
||||
use crate::attr;
|
||||
use crate::source_map::{self, SourceMap, Spanned};
|
||||
use crate::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind};
|
||||
use crate::parse::lexer::comments;
|
||||
use crate::print::pp::{self, Breaks};
|
||||
use crate::print::pp::Breaks::{Consistent, Inconsistent};
|
||||
use crate::ptr::P;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
pub use CommentStyle::*;
|
||||
|
||||
use super::is_block_doc_comment;
|
||||
|
||||
use crate::ast;
|
||||
use crate::source_map::SourceMap;
|
||||
use crate::sess::ParseSess;
|
||||
|
@ -10,6 +8,8 @@ use syntax_pos::{BytePos, CharPos, Pos, FileName};
|
|||
|
||||
use std::usize;
|
||||
|
||||
use log::debug;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
|
@ -32,8 +32,23 @@ pub struct Comment {
|
|||
pub pos: BytePos,
|
||||
}
|
||||
|
||||
fn is_doc_comment(s: &str) -> bool {
|
||||
(s.starts_with("///") && super::is_doc_comment(s)) || s.starts_with("//!") ||
|
||||
crate fn is_line_doc_comment(s: &str) -> bool {
|
||||
let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') ||
|
||||
s.starts_with("//!");
|
||||
debug!("is {:?} a doc comment? {}", s, res);
|
||||
res
|
||||
}
|
||||
|
||||
crate fn is_block_doc_comment(s: &str) -> bool {
|
||||
// Prevent `/**/` from being parsed as a doc comment
|
||||
let res = ((s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') ||
|
||||
s.starts_with("/*!")) && s.len() >= 5;
|
||||
debug!("is {:?} a doc comment? {}", s, res);
|
||||
res
|
||||
}
|
||||
|
||||
crate fn is_doc_comment(s: &str) -> bool {
|
||||
(s.starts_with("///") && is_line_doc_comment(s)) || s.starts_with("//!") ||
|
||||
(s.starts_with("/**") && is_block_doc_comment(s)) || s.starts_with("/*!")
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::base::ExtCtxt;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::parse::{self};
|
||||
use syntax::parse::lexer::comments;
|
||||
use syntax::parse;
|
||||
use syntax::util::comments;
|
||||
use syntax::print::pprust;
|
||||
use syntax::sess::ParseSess;
|
||||
use syntax::token;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue