use self::TokenTreeOrTokenTreeSlice::*;
use ast::Ident;
-use syntax_pos::{self, BytePos, Span};
+use syntax_pos::{self, Span};
use errors::FatalError;
use ext::tt::quoted::{self, TokenTree};
use parse::{Directory, ParseSess};
use parse::parser::{Parser, PathStyle};
use parse::token::{self, DocComment, Nonterminal, Token};
use print::pprust;
-use OneVector;
+use smallvec::SmallVec;
use symbol::keywords;
-use tokenstream::TokenStream;
+use tokenstream::{DelimSpan, TokenStream};
use rustc_data_structures::fx::FxHashMap;
use std::collections::hash_map::Entry::{Occupied, Vacant};
top_elts: TokenTreeOrTokenTreeSlice<'a>,
/// The position of the "dot" in this matcher
idx: usize,
- /// The beginning position in the source that the beginning of this matcher corresponds to. In
- /// other words, the token in the source at `sp_lo` is matched against the first token of the
- /// matcher.
- sp_lo: BytePos,
+ /// The first span of source source that the beginning of this matcher corresponds to. In other
+ /// words, the token in the source whose span is `sp_open` is matched against the first token of
+ /// the matcher.
+ sp_open: Span,
/// For each named metavar in the matcher, we keep track of token trees matched against the
/// metavar by the black box parser. In particular, there may be more than one match per
}
/// Generate the top-level matcher position in which the "dot" is before the first token of the
-/// matcher `ms` and we are going to start matching at position `lo` in the source.
-fn initial_matcher_pos(ms: &[TokenTree], lo: BytePos) -> MatcherPos {
+/// matcher `ms` and we are going to start matching at the span `open` in the source.
+fn initial_matcher_pos(ms: &[TokenTree], open: Span) -> MatcherPos {
let match_idx_hi = count_names(ms);
let matches = create_matches(match_idx_hi);
MatcherPos {
top_elts: TtSeq(ms), // "elts" is an abbr. for "elements"
// The "dot" is before the first token of the matcher
idx: 0,
- // We start matching with byte `lo` in the source code
- sp_lo: lo,
+ // We start matching at the span `open` in the source code
+ sp_open: open,
// Initialize `matches` to a bunch of empty `Vec`s -- one for each metavar in `top_elts`.
// `match_lo` for `top_elts` is 0 and `match_hi` is `matches.len()`. `match_cur` is 0 since
/// token tree it was derived from.
#[derive(Debug, Clone)]
pub enum NamedMatch {
- MatchedSeq(Rc<Vec<NamedMatch>>, syntax_pos::Span),
+ MatchedSeq(Rc<Vec<NamedMatch>>, DelimSpan),
MatchedNonterminal(Rc<Nonterminal>),
}
/// A `ParseResult`. Note that matches are kept track of through the items generated.
fn inner_parse_loop<'a>(
sess: &ParseSess,
- cur_items: &mut OneVector<MatcherPosHandle<'a>>,
+ cur_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>,
next_items: &mut Vec<MatcherPosHandle<'a>>,
- eof_items: &mut OneVector<MatcherPosHandle<'a>>,
- bb_items: &mut OneVector<MatcherPosHandle<'a>>,
+ eof_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>,
+ bb_items: &mut SmallVec<[MatcherPosHandle<'a>; 1]>,
token: &Token,
span: syntax_pos::Span,
) -> ParseResult<()> {
// 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);
+ let span = DelimSpan::from_pair(item.sp_open, span);
new_pos.push_match(idx, MatchedSeq(sub, span));
}
match_cur: item.match_cur,
match_hi: item.match_cur + seq.num_captures,
up: Some(item),
- sp_lo: sp.lo(),
+ sp_open: sp.open,
top_elts: Tt(TokenTree::Sequence(sp, seq)),
})));
}
//
// This MatcherPos instance is allocated on the stack. All others -- and
// there are frequently *no* others! -- are allocated on the heap.
- let mut initial = initial_matcher_pos(ms, parser.span.lo());
+ let mut initial = initial_matcher_pos(ms, parser.span);
let mut cur_items = smallvec![MatcherPosHandle::Ref(&mut initial)];
let mut next_items = Vec::new();
loop {
// Matcher positions black-box parsed by parser.rs (`parser`)
- let mut bb_items = OneVector::new();
+ let mut bb_items = SmallVec::new();
// Matcher positions that would be valid if the macro invocation was over now
- let mut eof_items = OneVector::new();
+ let mut eof_items = SmallVec::new();
assert!(next_items.is_empty());
// Process `cur_items` until either we have finished the input or we need to get some
FatalError.raise();
}
},
- "pat" => token::NtPat(panictry!(p.parse_pat())),
+ "pat" => token::NtPat(panictry!(p.parse_pat(None))),
"expr" => token::NtExpr(panictry!(p.parse_expr())),
"literal" => token::NtLiteral(panictry!(p.parse_literal_maybe_minus())),
"ty" => token::NtTy(panictry!(p.parse_ty())),