Skip to content

Commit 60058e5

Browse files
Crate-ify and delete unused code in syntax::parse
1 parent 61d8831 commit 60058e5

File tree

10 files changed

+191
-365
lines changed

10 files changed

+191
-365
lines changed

src/libsyntax/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(const_atomic_usize_new)]
2626
#![feature(rustc_attrs)]
2727
#![feature(str_escape)]
28+
#![feature(crate_visibility_modifier)]
2829

2930
#![recursion_limit="256"]
3031

src/libsyntax/parse/attr.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
use attr;
1212
use ast;
1313
use codemap::respan;
14-
use parse::common::SeqSep;
15-
use parse::PResult;
14+
use parse::{SeqSep, PResult};
1615
use parse::token::{self, Nonterminal};
1716
use parse::parser::{Parser, TokenType, PathStyle};
1817
use tokenstream::TokenStream;
@@ -28,7 +27,7 @@ const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &'static str = "an inner attribute
2827

2928
impl<'a> Parser<'a> {
3029
/// Parse attributes that appear before an item
31-
pub fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
30+
crate fn parse_outer_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
3231
let mut attrs: Vec<ast::Attribute> = Vec::new();
3332
let mut just_parsed_doc_comment = false;
3433
loop {
@@ -139,7 +138,7 @@ impl<'a> Parser<'a> {
139138
})
140139
}
141140

142-
pub fn parse_path_and_tokens(&mut self) -> PResult<'a, (ast::Path, TokenStream)> {
141+
crate fn parse_path_and_tokens(&mut self) -> PResult<'a, (ast::Path, TokenStream)> {
143142
let meta = match self.token {
144143
token::Interpolated(ref nt) => match nt.0 {
145144
Nonterminal::NtMeta(ref meta) => Some(meta.clone()),
@@ -160,7 +159,7 @@ impl<'a> Parser<'a> {
160159
/// terminated by a semicolon.
161160
162161
/// matches inner_attrs*
163-
pub fn parse_inner_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
162+
crate fn parse_inner_attributes(&mut self) -> PResult<'a, Vec<ast::Attribute>> {
164163
let mut attrs: Vec<ast::Attribute> = vec![];
165164
loop {
166165
match self.token {
@@ -231,7 +230,7 @@ impl<'a> Parser<'a> {
231230
Ok(ast::MetaItem { ident, node, span })
232231
}
233232

234-
pub fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
233+
crate fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
235234
Ok(if self.eat(&token::Eq) {
236235
ast::MetaItemKind::NameValue(self.parse_unsuffixed_lit()?)
237236
} else if self.eat(&token::OpenDelim(token::Paren)) {

src/libsyntax/parse/common.rs

-36
This file was deleted.

src/libsyntax/parse/lexer/comments.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub struct Comment {
4040
pub pos: BytePos,
4141
}
4242

43-
pub fn is_doc_comment(s: &str) -> bool {
43+
fn is_doc_comment(s: &str) -> bool {
4444
(s.starts_with("///") && super::is_doc_comment(s)) || s.starts_with("//!") ||
4545
(s.starts_with("/**") && is_block_doc_comment(s)) || s.starts_with("/*!")
4646
}

src/libsyntax/parse/lexer/mod.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ pub struct StringReader<'a> {
5151
pub ch: Option<char>,
5252
pub filemap: Lrc<syntax_pos::FileMap>,
5353
/// Stop reading src at this index.
54-
pub end_src_index: usize,
54+
end_src_index: usize,
5555
/// Whether to record new-lines and multibyte chars in filemap.
5656
/// This is only necessary the first time a filemap is lexed.
5757
/// If part of a filemap is being re-lexed, this should be set to false.
58-
pub save_new_lines_and_multibyte: bool,
58+
save_new_lines_and_multibyte: bool,
5959
// cached:
6060
peek_tok: token::Token,
6161
peek_span: Span,
6262
peek_span_src_raw: Span,
63-
pub fatal_errs: Vec<DiagnosticBuilder<'a>>,
63+
fatal_errs: Vec<DiagnosticBuilder<'a>>,
6464
// cache a direct reference to the source text, so that we don't have to
6565
// retrieve it via `self.filemap.src.as_ref().unwrap()` all the time.
6666
src: Lrc<String>,
@@ -70,7 +70,7 @@ pub struct StringReader<'a> {
7070
/// The raw source span which *does not* take `override_span` into account
7171
span_src_raw: Span,
7272
open_braces: Vec<(token::DelimToken, Span)>,
73-
pub override_span: Option<Span>,
73+
crate override_span: Option<Span>,
7474
}
7575

7676
impl<'a> StringReader<'a> {
@@ -163,11 +163,9 @@ impl<'a> StringReader<'a> {
163163
sp: self.peek_span,
164164
}
165165
}
166-
}
167166

168-
impl<'a> StringReader<'a> {
169167
/// For comments.rs, which hackily pokes into next_pos and ch
170-
pub fn new_raw(sess: &'a ParseSess, filemap: Lrc<syntax_pos::FileMap>,
168+
fn new_raw(sess: &'a ParseSess, filemap: Lrc<syntax_pos::FileMap>,
171169
override_span: Option<Span>) -> Self {
172170
let mut sr = StringReader::new_raw_internal(sess, filemap, override_span);
173171
sr.bump();
@@ -240,17 +238,17 @@ impl<'a> StringReader<'a> {
240238
sr
241239
}
242240

243-
pub fn ch_is(&self, c: char) -> bool {
241+
fn ch_is(&self, c: char) -> bool {
244242
self.ch == Some(c)
245243
}
246244

247245
/// Report a fatal lexical error with a given span.
248-
pub fn fatal_span(&self, sp: Span, m: &str) -> FatalError {
246+
fn fatal_span(&self, sp: Span, m: &str) -> FatalError {
249247
self.sess.span_diagnostic.span_fatal(sp, m)
250248
}
251249

252250
/// Report a lexical error with a given span.
253-
pub fn err_span(&self, sp: Span, m: &str) {
251+
fn err_span(&self, sp: Span, m: &str) {
254252
self.sess.span_diagnostic.span_err(sp, m)
255253
}
256254

@@ -375,7 +373,7 @@ impl<'a> StringReader<'a> {
375373
/// Calls `f` with a string slice of the source text spanning from `start`
376374
/// up to but excluding `self.pos`, meaning the slice does not include
377375
/// the character `self.ch`.
378-
pub fn with_str_from<T, F>(&self, start: BytePos, f: F) -> T
376+
fn with_str_from<T, F>(&self, start: BytePos, f: F) -> T
379377
where F: FnOnce(&str) -> T
380378
{
381379
self.with_str_from_to(start, self.pos, f)
@@ -384,13 +382,13 @@ impl<'a> StringReader<'a> {
384382
/// Create a Name from a given offset to the current offset, each
385383
/// adjusted 1 towards each other (assumes that on either side there is a
386384
/// single-byte delimiter).
387-
pub fn name_from(&self, start: BytePos) -> ast::Name {
385+
fn name_from(&self, start: BytePos) -> ast::Name {
388386
debug!("taking an ident from {:?} to {:?}", start, self.pos);
389387
self.with_str_from(start, Symbol::intern)
390388
}
391389

392390
/// As name_from, with an explicit endpoint.
393-
pub fn name_from_to(&self, start: BytePos, end: BytePos) -> ast::Name {
391+
fn name_from_to(&self, start: BytePos, end: BytePos) -> ast::Name {
394392
debug!("taking an ident from {:?} to {:?}", start, end);
395393
self.with_str_from_to(start, end, Symbol::intern)
396394
}
@@ -454,7 +452,7 @@ impl<'a> StringReader<'a> {
454452

455453
/// Advance the StringReader by one character. If a newline is
456454
/// discovered, add it to the FileMap's list of line start offsets.
457-
pub fn bump(&mut self) {
455+
crate fn bump(&mut self) {
458456
let next_src_index = self.src_index(self.next_pos);
459457
if next_src_index < self.end_src_index {
460458
let next_ch = char_at(&self.src, next_src_index);
@@ -481,7 +479,7 @@ impl<'a> StringReader<'a> {
481479
}
482480
}
483481

484-
pub fn nextch(&self) -> Option<char> {
482+
fn nextch(&self) -> Option<char> {
485483
let next_src_index = self.src_index(self.next_pos);
486484
if next_src_index < self.end_src_index {
487485
Some(char_at(&self.src, next_src_index))
@@ -490,11 +488,11 @@ impl<'a> StringReader<'a> {
490488
}
491489
}
492490

493-
pub fn nextch_is(&self, c: char) -> bool {
491+
fn nextch_is(&self, c: char) -> bool {
494492
self.nextch() == Some(c)
495493
}
496494

497-
pub fn nextnextch(&self) -> Option<char> {
495+
fn nextnextch(&self) -> Option<char> {
498496
let next_src_index = self.src_index(self.next_pos);
499497
if next_src_index < self.end_src_index {
500498
let next_next_src_index =
@@ -506,7 +504,7 @@ impl<'a> StringReader<'a> {
506504
None
507505
}
508506

509-
pub fn nextnextch_is(&self, c: char) -> bool {
507+
fn nextnextch_is(&self, c: char) -> bool {
510508
self.nextnextch() == Some(c)
511509
}
512510

@@ -1732,7 +1730,7 @@ impl<'a> StringReader<'a> {
17321730

17331731
// This tests the character for the unicode property 'PATTERN_WHITE_SPACE' which
17341732
// is guaranteed to be forward compatible. http://unicode.org/reports/tr31/#R3
1735-
pub fn is_pattern_whitespace(c: Option<char>) -> bool {
1733+
crate fn is_pattern_whitespace(c: Option<char>) -> bool {
17361734
c.map_or(false, Pattern_White_Space)
17371735
}
17381736

@@ -1747,14 +1745,14 @@ fn is_dec_digit(c: Option<char>) -> bool {
17471745
in_range(c, '0', '9')
17481746
}
17491747

1750-
pub fn is_doc_comment(s: &str) -> bool {
1748+
fn is_doc_comment(s: &str) -> bool {
17511749
let res = (s.starts_with("///") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'/') ||
17521750
s.starts_with("//!");
17531751
debug!("is {:?} a doc comment? {}", s, res);
17541752
res
17551753
}
17561754

1757-
pub fn is_block_doc_comment(s: &str) -> bool {
1755+
fn is_block_doc_comment(s: &str) -> bool {
17581756
// Prevent `/**/` from being parsed as a doc comment
17591757
let res = ((s.starts_with("/**") && *s.as_bytes().get(3).unwrap_or(&b' ') != b'*') ||
17601758
s.starts_with("/*!")) && s.len() >= 5;

src/libsyntax/parse/lexer/tokentrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tokenstream::{Delimited, TokenStream, TokenTree};
1515

1616
impl<'a> StringReader<'a> {
1717
// Parse a stream of tokens into a list of `TokenTree`s, up to an `Eof`.
18-
pub fn parse_all_token_trees(&mut self) -> PResult<'a, TokenStream> {
18+
crate fn parse_all_token_trees(&mut self) -> PResult<'a, TokenStream> {
1919
let mut tts = Vec::new();
2020
while self.token != token::Eof {
2121
tts.push(self.parse_token_tree()?);

src/libsyntax/parse/lexer/unicode_chars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ const ASCII_ARRAY: &'static [(char, &'static str)] = &[
333333
('=', "Equals Sign"),
334334
('>', "Greater-Than Sign"), ];
335335

336-
pub fn check_for_substitution<'a>(reader: &StringReader<'a>,
336+
crate fn check_for_substitution<'a>(reader: &StringReader<'a>,
337337
ch: char,
338338
err: &mut DiagnosticBuilder<'a>) -> bool {
339339
UNICODE_ARRAY

0 commit comments

Comments
 (0)