Skip to content

Commit

Permalink
syntax: refactor with new fn parse_use_tree_glob_or_nested.
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 7, 2019
1 parent 9c6582a commit 6b23c22
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/libsyntax/parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,21 +1077,13 @@ impl<'a> Parser<'a> {
);
}

if self.eat(&token::BinOp(token::Star)) {
UseTreeKind::Glob
} else {
UseTreeKind::Nested(self.parse_use_tree_list()?)
}
self.parse_use_tree_glob_or_nested()?
} else {
// `use path::*;` or `use path::{...};` or `use path;` or `use path as bar;`
prefix = self.parse_path(PathStyle::Mod)?;

if self.eat(&token::ModSep) {
if self.eat(&token::BinOp(token::Star)) {
UseTreeKind::Glob
} else {
UseTreeKind::Nested(self.parse_use_tree_list()?)
}
self.parse_use_tree_glob_or_nested()?
} else {
UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID)
}
Expand All @@ -1100,6 +1092,15 @@ impl<'a> Parser<'a> {
Ok(UseTree { prefix, kind, span: lo.to(self.prev_span) })
}

/// Parses `*` or `{...}`.
fn parse_use_tree_glob_or_nested(&mut self) -> PResult<'a, UseTreeKind> {
Ok(if self.eat(&token::BinOp(token::Star)) {
UseTreeKind::Glob
} else {
UseTreeKind::Nested(self.parse_use_tree_list()?)
})
}

/// Parses a `UseTreeKind::Nested(list)`.
///
/// ```
Expand Down

0 comments on commit 6b23c22

Please sign in to comment.