Parse paths in item, trait item, and impl item macro invocations.
This commit is contained in:
parent
a0e178db79
commit
6c08d03039
1 changed files with 6 additions and 21 deletions
|
@ -542,11 +542,6 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_ident_into_path(&mut self) -> PResult<'a, ast::Path> {
|
|
||||||
let ident = self.parse_ident()?;
|
|
||||||
Ok(ast::Path::from_ident(self.last_span, ident))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if the next token is `tok`, and return `true` if so.
|
/// Check if the next token is `tok`, and return `true` if so.
|
||||||
///
|
///
|
||||||
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
|
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
|
||||||
|
@ -1202,14 +1197,11 @@ impl<'a> Parser<'a> {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
(ident, TraitItemKind::Const(ty, default))
|
(ident, TraitItemKind::Const(ty, default))
|
||||||
} else if !self.token.is_any_keyword()
|
} else if self.token.is_path_start() {
|
||||||
&& self.look_ahead(1, |t| *t == token::Not)
|
|
||||||
&& (self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren))
|
|
||||||
|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) {
|
|
||||||
// trait item macro.
|
// trait item macro.
|
||||||
// code copied from parse_macro_use_or_failure... abstraction!
|
// code copied from parse_macro_use_or_failure... abstraction!
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let pth = self.parse_ident_into_path()?;
|
let pth = self.parse_path(PathStyle::Mod)?;
|
||||||
self.expect(&token::Not)?;
|
self.expect(&token::Not)?;
|
||||||
|
|
||||||
// eat a matched-delimiter token tree:
|
// eat a matched-delimiter token tree:
|
||||||
|
@ -4873,17 +4865,14 @@ impl<'a> Parser<'a> {
|
||||||
fn parse_impl_method(&mut self, vis: &Visibility)
|
fn parse_impl_method(&mut self, vis: &Visibility)
|
||||||
-> PResult<'a, (Ident, Vec<ast::Attribute>, ast::ImplItemKind)> {
|
-> PResult<'a, (Ident, Vec<ast::Attribute>, ast::ImplItemKind)> {
|
||||||
// code copied from parse_macro_use_or_failure... abstraction!
|
// code copied from parse_macro_use_or_failure... abstraction!
|
||||||
if !self.token.is_any_keyword()
|
if self.token.is_path_start() {
|
||||||
&& self.look_ahead(1, |t| *t == token::Not)
|
|
||||||
&& (self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren))
|
|
||||||
|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) {
|
|
||||||
// method macro.
|
// method macro.
|
||||||
|
|
||||||
let last_span = self.last_span;
|
let last_span = self.last_span;
|
||||||
self.complain_if_pub_macro(&vis, last_span);
|
self.complain_if_pub_macro(&vis, last_span);
|
||||||
|
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
let pth = self.parse_ident_into_path()?;
|
let pth = self.parse_path(PathStyle::Mod)?;
|
||||||
self.expect(&token::Not)?;
|
self.expect(&token::Not)?;
|
||||||
|
|
||||||
// eat a matched-delimiter token tree:
|
// eat a matched-delimiter token tree:
|
||||||
|
@ -5995,11 +5984,7 @@ impl<'a> Parser<'a> {
|
||||||
lo: BytePos,
|
lo: BytePos,
|
||||||
visibility: Visibility
|
visibility: Visibility
|
||||||
) -> PResult<'a, Option<P<Item>>> {
|
) -> PResult<'a, Option<P<Item>>> {
|
||||||
if macros_allowed && !self.token.is_any_keyword()
|
if macros_allowed && self.token.is_path_start() {
|
||||||
&& self.look_ahead(1, |t| *t == token::Not)
|
|
||||||
&& (self.look_ahead(2, |t| t.is_ident())
|
|
||||||
|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren))
|
|
||||||
|| self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) {
|
|
||||||
// MACRO INVOCATION ITEM
|
// MACRO INVOCATION ITEM
|
||||||
|
|
||||||
let last_span = self.last_span;
|
let last_span = self.last_span;
|
||||||
|
@ -6008,7 +5993,7 @@ impl<'a> Parser<'a> {
|
||||||
let mac_lo = self.span.lo;
|
let mac_lo = self.span.lo;
|
||||||
|
|
||||||
// item macro.
|
// item macro.
|
||||||
let pth = self.parse_ident_into_path()?;
|
let pth = self.parse_path(PathStyle::Mod)?;
|
||||||
self.expect(&token::Not)?;
|
self.expect(&token::Not)?;
|
||||||
|
|
||||||
// a 'special' identifier (like what `macro_rules!` uses)
|
// a 'special' identifier (like what `macro_rules!` uses)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue