Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 12 pull requests #47870

Merged
merged 38 commits into from
Jan 30, 2018
Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c2e2612
Punctuation and clarity fixes.
jimmantooth Jan 17, 2018
c4befe1
Run rustfmt and add comments
mark-i-m Jan 19, 2018
49431d4
Add a bunch of doc comments
mark-i-m Jan 19, 2018
ca0c080
Fix typos
mark-i-m Jan 21, 2018
831ff77
implement Send for process::Command on unix
little-dude Jan 25, 2018
9e6ed17
make Command.argv Send on unix platforms
little-dude Jan 26, 2018
0ac4659
Add line numbers and columns to error messages spanning multiple files
varkor Jan 26, 2018
077d343
add test checking that process::Command is Send
little-dude Jan 26, 2018
aa6cc6e
Fix test in macro_backtrace
varkor Jan 26, 2018
ac0c16d
Run rustfmt on /libsyntax/ext/tt/macro_parser.rs
mark-i-m Jan 20, 2018
0d7f193
Added a bunch of comments to macro_parser.rs
mark-i-m Jan 20, 2018
6d4ed65
Added lots of comments + minor reorganization
mark-i-m Jan 25, 2018
b01b481
Added/improved comments
mark-i-m Jan 25, 2018
02d1d92
Still more comments
mark-i-m Jan 25, 2018
e2d558a
A few more comments
mark-i-m Jan 25, 2018
a21b7b3
Improve formatting of else block
varkor Jan 27, 2018
2497d10
Whitelist aes x86 feature flag
gnzlbg Jan 28, 2018
b32dbbc
Whitelist v7 feature for ARM and AARCH64.
gnzlbg Jan 28, 2018
7b4cbbd
Document that `Index` ops can panic on `HashMap` & `BTreeMap`.
frewsxcv Jan 29, 2018
e09a8bd
Add per-stage RUSTFLAGS: RUSTFLAGS_STAGE_{0,1,2} and RUSTFLAGS_STAGE_…
Mark-Simulacrum Jan 29, 2018
8389b66
Increase test coverage of use_nested_groups
pietroalbini Jan 29, 2018
898fdcc
Make run-pass/env-home-dir.rs test more robust
malbarbo Jan 24, 2018
adeb0ae
move comment right onto the line in question
nikomatsakis Jan 29, 2018
ae98f4c
rustdoc: Fix link title rendering with hoedown
ollie27 Jan 29, 2018
2184400
Update comment
mark-i-m Jan 29, 2018
5762942
fix typos
mark-i-m Jan 29, 2018
19aac09
Rollup merge of #47515 - jimmantooth:patch-1, r=QuietMisdreavus
kennytm Jan 30, 2018
3e39180
Rollup merge of #47603 - mark-i-m:markim_comments_0000, r=jseyfried
kennytm Jan 30, 2018
fccc85a
Rollup merge of #47718 - malbarbo:env-home-dir, r=nikomatsakis
kennytm Jan 30, 2018
f06a391
Rollup merge of #47732 - mark-i-m:markim_comments_0001, r=jseyfried
kennytm Jan 30, 2018
4dbfc8d
Rollup merge of #47760 - little-dude:master, r=alexcrichton
kennytm Jan 30, 2018
44b9641
Rollup merge of #47780 - varkor:cross-file-errors-line-col, r=estebank
kennytm Jan 30, 2018
003254e
Rollup merge of #47822 - gnzlbg:patch-1, r=alexcrichton
kennytm Jan 30, 2018
16d3fdb
Rollup merge of #47826 - gnzlbg:patch-2, r=alexcrichton
kennytm Jan 30, 2018
e8868bd
Rollup merge of #47836 - Mark-Simulacrum:stage-flags, r=alexcrichton
kennytm Jan 30, 2018
95572df
Rollup merge of #47839 - frewsxcv:frewsxcv-map-index, r=QuietMisdreavus
kennytm Jan 30, 2018
b83fb0f
Rollup merge of #47853 - rust-lang:increase-nested-groups-test-covera…
kennytm Jan 30, 2018
393a199
Rollup merge of #47855 - ollie27:rustdoc_hoedown_link_title, r=QuietM…
kennytm Jan 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added a bunch of comments to macro_parser.rs
  • Loading branch information
mark-i-m committed Jan 26, 2018
commit 0d7f193dd358cdc13506cac2e0b84fc473b628be
72 changes: 62 additions & 10 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,22 +429,46 @@ fn inner_parse_loop(
Success(())
}

/// Parse the given set of token trees (`ms`), possibly consuming additional token trees from the
/// tokenstream (`tts`).
///
/// # Parameters
///
/// - `sess`: The session into which errors are emitted
/// - `tts`: The tokenstream from which additional token trees may be consumed if needed
/// - `ms`: The token trees we want to parse as macros
/// - `directory`: Information about the file locations (needed for the black-box parser)
/// - `recurse_into_modules`: Whether or not to recurse into modules (needed for the black-box
/// parser)
pub fn parse(
sess: &ParseSess,
tts: TokenStream,
ms: &[TokenTree],
directory: Option<Directory>,
recurse_into_modules: bool,
) -> NamedParseResult {
// Create a parser that can be used for the "black box" parts.
let mut parser = Parser::new(sess, tts, directory, recurse_into_modules, true);

// A queue of possible matcher positions. We initialize it with the matcher position in which
// the "dot" is before the first token of the first token tree. `inner_parse_loop` then
// processes all of these possible matcher positions and produces posible next positions into
// `next_items`. After some post-processing, the contents of `next_items` replenish
// `cur_items` and we start over again.
let mut cur_items = SmallVector::one(initial_matcher_pos(ms.to_owned(), parser.span.lo()));
let mut next_items = Vec::new(); // or proceed normally
let mut next_items = Vec::new();

loop {
let mut bb_items = SmallVector::new(); // black-box parsed by parser.rs
// Matcher positions black-box parsed by parser.rs (`parser`)
let mut bb_items = SmallVector::new();

// Matcher positions that would be valid if the macro invocation was over now
let mut eof_items = SmallVector::new();
assert!(next_items.is_empty());

// Process `cur_items` until either we have finished the input or we need to get some
// parsing from the black-box parser done. The result is that `next_items` will contain a
// bunch of possible next matcher positions in `next_items`.
match inner_parse_loop(
sess,
&mut cur_items,
Expand All @@ -462,7 +486,12 @@ pub fn parse(
// inner parse loop handled all cur_items, so it's empty
assert!(cur_items.is_empty());

/* error messages here could be improved with links to orig. rules */
// We need to do some post processing after the `inner_parser_loop`.
//
// Error messages here could be improved with links to original rules.

// If we reached the EOF, check that there is EXACTLY ONE possible matcher. Otherwise,
// either the parse is ambiguous (which should never happen) or their is a syntax error.
if token_name_eq(&parser.token, &token::Eof) {
if eof_items.len() == 1 {
let matches = eof_items[0]
Expand All @@ -478,7 +507,10 @@ pub fn parse(
} else {
return Failure(parser.span, token::Eof);
}
} else if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
}
// Another possibility is that we need to call out to parse some rust nonterminal
// (black-box) parser. However, if there is not EXACTLY ONE of these, something is wrong.
else if (!bb_items.is_empty() && !next_items.is_empty()) || bb_items.len() > 1 {
let nts = bb_items
.iter()
.map(|item| match item.top_elts.get_tt(item.idx) {
Expand All @@ -499,15 +531,23 @@ pub fn parse(
}
),
);
} else if bb_items.is_empty() && next_items.is_empty() {
}
// If there are no posible next positions AND we aren't waiting for the black-box parser,
// then their is a syntax error.
else if bb_items.is_empty() && next_items.is_empty() {
return Failure(parser.span, parser.token);
} else if !next_items.is_empty() {
/* Now process the next token */
}
// Dump all possible `next_items` into `cur_items` for the next iteration.
else if !next_items.is_empty() {
// Now process the next token
cur_items.extend(next_items.drain(..));
parser.bump();
} else
/* bb_items.len() == 1 */
{
}
// Finally, we have the case where we need to call the black-box parser to get some
// nonterminal.
else {
assert_eq!(bb_items.len(), 1);

let mut item = bb_items.pop().unwrap();
if let TokenTree::MetaVarDecl(span, _, ident) = item.top_elts.get_tt(item.idx) {
let match_cur = item.match_cur;
Expand Down Expand Up @@ -595,6 +635,18 @@ fn may_begin_with(name: &str, token: &Token) -> bool {
}
}

/// A call to the "black-box" parser to parse some rust nonterminal.
///
/// # Parameters
///
/// - `p`: the "black-box" parser to use
/// - `sp`: the `Span` we want to parse
/// - `name`: the name of the metavar _matcher_ we want to match (e.g. `tt`, `ident`, `block`,
/// etc...)
///
/// # Returns
///
/// The parsed nonterminal.
fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
if name == "tt" {
return token::NtTT(p.parse_token_tree());
Expand Down