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/improved comments
  • Loading branch information
mark-i-m committed Jan 26, 2018
commit b01b481db3ed9e13ab2fedc711f7cdabc8c1c53c
78 changes: 61 additions & 17 deletions src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ struct MatcherPos {
/// Moreover, matchers and repetitions can be nested; the `matches` field is shared (hence the
/// `Rc`) among all "nested" matchers. `match_lo`, `match_cur`, and `match_hi` keep track of
/// the current position of the `self` matcher position in the shared `matches` list.
///
/// Also, note that while we are descending into a sequence, matchers are given their own
/// `matches` vector. Only once we reach the end of a full repetition of the sequence do we add
/// all bound matches from the submatcher into the shared top-level `matches` vector. If `sep`
/// and `up` are `Some`, then `matches` is _not_ the shared top-level list. Instead, if one
/// wants the shared `matches`, one should use `up.matches`.
matches: Vec<Rc<Vec<NamedMatch>>>,
/// The position in `matches` corresponding to the first metavar in this matcher's sequence of
/// token trees. In other words, the first metavar in the first token of `top_elts` corresponds
Expand Down Expand Up @@ -255,7 +261,7 @@ fn initial_matcher_pos(ms: Vec<TokenTree>, lo: BytePos) -> Box<MatcherPos> {
// Haven't descended into any delimiters, so empty stack
stack: vec![],

// Haven't descended into any sequences, so both of these are `None`
// Haven't descended into any sequences, so both of these are `None`.
sep: None,
up: None,
})
Expand Down Expand Up @@ -355,6 +361,28 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
}
}

/// Process the matcher positions of `cur_items` until it is empty. In the process, this will
/// produce more items in `next_items`, `eof_items`, and `bb_items`.
///
/// For more info about the how this happens, see the module-level doc comments and the inline
/// comments of this function.
///
/// # Parameters
///
/// - `sess`: the parsing session into which errors are emitted.
/// - `cur_items`: the set of current items to be processed. This should be empty by the end of a
/// successful execution of this function.
/// - `next_items`: the set of newly generated items. These are used to replenish `cur_items` in
/// the function `parse`.
/// - `eof_items`: the set of items that would be valid if this was the EOF.
/// - `bb_items`: the set of items that are waiting for the black-box parser.
/// - `token`: the current token of the parser.
/// - `span`: the `Span` in the source code corresponding to the token trees we are trying to match
/// against the matcher positions in `cur_items`.
///
/// # Returns
///
/// A `ParseResult`. Note that matches are kept track of through the items generated.
fn inner_parse_loop(
sess: &ParseSess,
cur_items: &mut SmallVector<Box<MatcherPos>>,
Expand All @@ -364,8 +392,11 @@ fn inner_parse_loop(
token: &Token,
span: syntax_pos::Span,
) -> ParseResult<()> {
// Pop items from `cur_items` until it is empty.
while let Some(mut item) = cur_items.pop() {
// When unzipped trees end, remove them
// When unzipped trees end, remove them. This corresponds to backtracking out of a
// delimited submatcher into which we already descended. In backtracking out again, we need
// to advance the "dot" past the delimiters in the outer matcher.
while item.idx >= item.top_elts.len() {
match item.stack.pop() {
Some(MatcherTtFrame { elts, idx }) => {
Expand All @@ -376,37 +407,46 @@ fn inner_parse_loop(
}
}

// Get the current position of the "dot" (`idx`) in `item` and the number of token trees in
// the matcher (`len`).
let idx = item.idx;
let len = item.top_elts.len();

// at end of sequence
// If `idx >= len`, then we are at or past the end of the matcher of `item`.
if idx >= len {
// We are repeating iff there is a parent
// We are repeating iff there is a parent. If the matcher is inside of a repetition,
// then we could be at the end of a sequence or at the beginning of the next
// repetition.
if item.up.is_some() {
// Disregarding the separator, add the "up" case to the tokens that should be
// examined.
// (remove this condition to make trailing seps ok)
// At this point, regardless of whether there is a separator, we should add all
// matches from the complete repetition of the sequence to the shared, top-level
// `matches` list (actually, `up.matches`, which could itself not be the top-level,
// but anyway...). Moreover, we add another item to `cur_items` in which the "dot"
// is at the end of the `up` matcher. This ensures that the "dot" in the `up`
// matcher is also advanced sufficiently.
//
// NOTE: removing the condition `idx == len` allows trailing separators.
if idx == len {
// Get the `up` matcher
let mut new_pos = item.up.clone().unwrap();

// update matches (the MBE "parse tree") by appending
// each tree as a subtree.

// Only touch the binders we have actually bound
// Add matches from this repetition to the `matches` of `up`
for idx in item.match_lo..item.match_hi {
let sub = item.matches[idx].clone();
let span = span.with_lo(item.sp_lo);
new_pos.push_match(idx, MatchedSeq(sub, span));
}

// Move the "dot" past the repetition in `up`
new_pos.match_cur = item.match_hi;
new_pos.idx += 1;
cur_items.push(new_pos);
}

// Check if we need a separator
// Check if we need a separator.
if idx == len && item.sep.is_some() {
// We have a separator, and it is the current token.
// We have a separator, and it is the current token. We can advance past the
// separator token.
if item.sep
.as_ref()
.map(|sep| token_name_eq(token, sep))
Expand All @@ -415,14 +455,18 @@ fn inner_parse_loop(
item.idx += 1;
next_items.push(item);
}
} else {
// we don't need a separator
}
// We don't need a separator. Move the "dot" back to the beginning of the matcher
// and try to match again.
else {
item.match_cur = item.match_lo;
item.idx = 0;
cur_items.push(item);
}
} else {
// We aren't repeating, so we must be potentially at the end of the input.
}
// If we are not in a repetition, then being at the end of a matcher means that we have
// reached the potential end of the input.
else {
eof_items.push(item);
}
} else {
Expand Down