5587: Finish use grammar r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-30 12:18:41 +00:00 committed by GitHub
commit 51b18ee2f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 222 additions and 184 deletions

View file

@ -92,7 +92,7 @@ impl AutoImportAssets {
fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option<Self> { fn for_regular_path(path_under_caret: ast::Path, ctx: &AssistContext) -> Option<Self> {
let syntax_under_caret = path_under_caret.syntax().to_owned(); let syntax_under_caret = path_under_caret.syntax().to_owned();
if syntax_under_caret.ancestors().find_map(ast::UseItem::cast).is_some() { if syntax_under_caret.ancestors().find_map(ast::Use::cast).is_some() {
return None; return None;
} }

View file

@ -28,7 +28,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<()
let mut rewriter = SyntaxRewriter::default(); let mut rewriter = SyntaxRewriter::default();
let mut offset = ctx.offset(); let mut offset = ctx.offset();
if let Some(use_item) = tree.syntax().parent().and_then(ast::UseItem::cast) { if let Some(use_item) = tree.syntax().parent().and_then(ast::Use::cast) {
let (merged, to_delete) = next_prev() let (merged, to_delete) = next_prev()
.filter_map(|dir| neighbor(&use_item, dir)) .filter_map(|dir| neighbor(&use_item, dir))
.filter_map(|it| Some((it.clone(), it.use_tree()?))) .filter_map(|it| Some((it.clone(), it.use_tree()?)))

View file

@ -25,7 +25,7 @@ pub(crate) fn replace_qualified_name_with_use(
) -> Option<()> { ) -> Option<()> {
let path: ast::Path = ctx.find_node_at_offset()?; let path: ast::Path = ctx.find_node_at_offset()?;
// We don't want to mess with use statements // We don't want to mess with use statements
if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { if path.syntax().ancestors().find_map(ast::Use::cast).is_some() {
return None; return None;
} }
@ -85,7 +85,7 @@ fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path:
match child { match child {
// Don't modify `use` items, as this can break the `use` item when injecting a new // Don't modify `use` items, as this can break the `use` item when injecting a new
// import into the use tree. // import into the use tree.
ast::UseItem(_it) => continue, ast::Use(_it) => continue,
// Don't descend into submodules, they don't have the same `use` items in scope. // Don't descend into submodules, they don't have the same `use` items in scope.
ast::Module(_it) => continue, ast::Module(_it) => continue,

View file

@ -225,7 +225,7 @@ fn walk_use_tree_for_best_action(
current_use_tree current_use_tree
.syntax() .syntax()
.ancestors() .ancestors()
.find_map(ast::UseItem::cast) .find_map(ast::Use::cast)
.map(|it| it.syntax().clone()), .map(|it| it.syntax().clone()),
true, true,
); );
@ -254,7 +254,7 @@ fn walk_use_tree_for_best_action(
current_use_tree current_use_tree
.syntax() .syntax()
.ancestors() .ancestors()
.find_map(ast::UseItem::cast) .find_map(ast::Use::cast)
.map(|it| it.syntax().clone()), .map(|it| it.syntax().clone()),
true, true,
), ),
@ -304,7 +304,7 @@ fn walk_use_tree_for_best_action(
current_use_tree current_use_tree
.syntax() .syntax()
.ancestors() .ancestors()
.find_map(ast::UseItem::cast) .find_map(ast::Use::cast)
.map(|it| it.syntax().clone()), .map(|it| it.syntax().clone()),
true, true,
); );
@ -377,7 +377,7 @@ fn best_action_for_target(
let mut storage = Vec::with_capacity(16); // this should be the only allocation let mut storage = Vec::with_capacity(16); // this should be the only allocation
let best_action = container let best_action = container
.children() .children()
.filter_map(ast::UseItem::cast) .filter_map(ast::Use::cast)
.filter_map(|it| it.use_tree()) .filter_map(|it| it.use_tree())
.map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target)) .map(|u| walk_use_tree_for_best_action(&mut storage, None, u, target))
.fold(None, |best, a| match best { .fold(None, |best, a| match best {

View file

@ -670,7 +670,7 @@ impl ExprCollector<'_> {
} }
ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
ast::Item::ImplDef(_) ast::Item::ImplDef(_)
| ast::Item::UseItem(_) | ast::Item::Use(_)
| ast::Item::ExternCrate(_) | ast::Item::ExternCrate(_)
| ast::Item::Module(_) | ast::Item::Module(_)
| ast::Item::MacroCall(_) => return None, | ast::Item::MacroCall(_) => return None,

View file

@ -411,7 +411,7 @@ macro_rules! mod_items {
} }
mod_items! { mod_items! {
Import in imports -> ast::UseItem, Import in imports -> ast::Use,
ExternCrate in extern_crates -> ast::ExternCrate, ExternCrate in extern_crates -> ast::ExternCrate,
Function in functions -> ast::FnDef, Function in functions -> ast::FnDef,
Struct in structs -> ast::StructDef, Struct in structs -> ast::StructDef,
@ -482,7 +482,7 @@ pub struct Import {
pub is_prelude: bool, pub is_prelude: bool,
/// AST ID of the `use` or `extern crate` item this import was derived from. Note that many /// AST ID of the `use` or `extern crate` item this import was derived from. Note that many
/// `Import`s can map to the same `use` item. /// `Import`s can map to the same `use` item.
pub ast_id: FileAstId<ast::UseItem>, pub ast_id: FileAstId<ast::Use>,
} }
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]

View file

@ -95,7 +95,7 @@ impl Ctx {
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {} ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
// These don't have inner items. // These don't have inner items.
ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::UseItem(_) => {} ast::Item::Module(_) | ast::Item::ExternCrate(_) | ast::Item::Use(_) => {}
}; };
let attrs = Attrs::new(item, &self.hygiene); let attrs = Attrs::new(item, &self.hygiene);
@ -110,7 +110,7 @@ impl Ctx {
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into), ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into), ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into), ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
ast::Item::UseItem(ast) => Some(ModItems( ast::Item::Use(ast) => Some(ModItems(
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(), self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
)), )),
ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into), ast::Item::ExternCrate(ast) => self.lower_extern_crate(ast).map(Into::into),
@ -469,7 +469,7 @@ impl Ctx {
Some(id(self.data().impls.alloc(res))) Some(id(self.data().impls.alloc(res)))
} }
fn lower_use(&mut self, use_item: &ast::UseItem) -> Vec<FileItemTreeId<Import>> { fn lower_use(&mut self, use_item: &ast::Use) -> Vec<FileItemTreeId<Import>> {
// FIXME: cfg_attr // FIXME: cfg_attr
let is_prelude = use_item.has_atom_attr("prelude_import"); let is_prelude = use_item.has_atom_attr("prelude_import");
let visibility = self.lower_visibility(use_item); let visibility = self.lower_visibility(use_item);

View file

@ -228,9 +228,9 @@ fn smoke() {
top-level items: top-level items:
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UseItem>(0) } Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }]
Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::UseItem>(0) } Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::Use>(0) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }] #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }]
ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrate>(1) } ExternCrate { path: ModPath { kind: Plain, segments: [Name(Text("krate"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::<ra_syntax::ast::generated::nodes::ExternCrate>(1) }
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }] #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }]

View file

@ -67,7 +67,7 @@ impl ModPath {
/// Calls `cb` with all paths, represented by this use item. /// Calls `cb` with all paths, represented by this use item.
pub(crate) fn expand_use_item( pub(crate) fn expand_use_item(
item_src: InFile<ast::UseItem>, item_src: InFile<ast::Use>,
hygiene: &Hygiene, hygiene: &Hygiene,
mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>), mut cb: impl FnMut(ModPath, &ast::UseTree, /* is_glob */ bool, Option<ImportAlias>),
) { ) {

View file

@ -36,7 +36,7 @@ pub(crate) struct CompletionContext<'a> {
pub(super) expected_type: Option<Type>, pub(super) expected_type: Option<Type>,
pub(super) name_ref_syntax: Option<ast::NameRef>, pub(super) name_ref_syntax: Option<ast::NameRef>,
pub(super) function_syntax: Option<ast::FnDef>, pub(super) function_syntax: Option<ast::FnDef>,
pub(super) use_item_syntax: Option<ast::UseItem>, pub(super) use_item_syntax: Option<ast::Use>,
pub(super) record_lit_syntax: Option<ast::RecordLit>, pub(super) record_lit_syntax: Option<ast::RecordLit>,
pub(super) record_pat_syntax: Option<ast::RecordPat>, pub(super) record_pat_syntax: Option<ast::RecordPat>,
pub(super) record_field_syntax: Option<ast::RecordField>, pub(super) record_field_syntax: Option<ast::RecordField>,
@ -343,7 +343,7 @@ impl<'a> CompletionContext<'a> {
} }
self.use_item_syntax = self.use_item_syntax =
self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::UseItem::cast); self.sema.ancestors_with_macros(self.token.parent()).find_map(ast::Use::cast);
self.function_syntax = self self.function_syntax = self
.sema .sema

View file

@ -58,7 +58,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
} }
NodeOrToken::Node(node) => { NodeOrToken::Node(node) => {
// Fold groups of imports // Fold groups of imports
if node.kind() == USE_ITEM && !visited_imports.contains(&node) { if node.kind() == USE && !visited_imports.contains(&node) {
if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) { if let Some(range) = contiguous_range_for_group(&node, &mut visited_imports) {
res.push(Fold { range, kind: FoldKind::Imports }) res.push(Fold { range, kind: FoldKind::Imports })
} }
@ -83,7 +83,7 @@ pub(crate) fn folding_ranges(file: &SourceFile) -> Vec<Fold> {
fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> { fn fold_kind(kind: SyntaxKind) -> Option<FoldKind> {
match kind { match kind {
COMMENT => Some(FoldKind::Comment), COMMENT => Some(FoldKind::Comment),
USE_ITEM => Some(FoldKind::Imports), USE => Some(FoldKind::Imports),
ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList), ARG_LIST | PARAM_LIST => Some(FoldKind::ArgList),
RECORD_FIELD_DEF_LIST RECORD_FIELD_DEF_LIST
| RECORD_FIELD_PAT_LIST | RECORD_FIELD_PAT_LIST

View file

@ -7,7 +7,7 @@ pub(super) fn use_item(p: &mut Parser, m: Marker) {
p.bump(T![use]); p.bump(T![use]);
use_tree(p, true); use_tree(p, true);
p.expect(T![;]); p.expect(T![;]);
m.complete(p, USE_ITEM); m.complete(p, USE);
} }
/// Parse a use 'tree', such as `some::path` in `use some::path;` /// Parse a use 'tree', such as `some::path` in `use some::path;`

View file

@ -130,7 +130,7 @@ pub enum SyntaxKind {
RET_TYPE, RET_TYPE,
EXTERN_CRATE, EXTERN_CRATE,
MODULE, MODULE,
USE_ITEM, USE,
STATIC_DEF, STATIC_DEF,
CONST_DEF, CONST_DEF,
TRAIT_DEF, TRAIT_DEF,

View file

@ -237,7 +237,7 @@ fn is_search_permitted(node: &SyntaxNode) -> bool {
// and the code is `use foo::{baz, bar}`, we'll match `bar`, since it resolves to `foo::bar`. // and the code is `use foo::{baz, bar}`, we'll match `bar`, since it resolves to `foo::bar`.
// However we'll then replace just the part we matched `bar`. We probably need to instead remove // However we'll then replace just the part we matched `bar`. We probably need to instead remove
// `bar` and insert a new use declaration. // `bar` and insert a new use declaration.
node.kind() != SyntaxKind::USE_ITEM node.kind() != SyntaxKind::USE
} }
impl UsageCache { impl UsageCache {

View file

@ -262,9 +262,9 @@ impl ast::PathSegment {
} }
} }
impl ast::UseItem { impl ast::Use {
#[must_use] #[must_use]
pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::UseItem { pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use {
if let Some(old) = self.use_tree() { if let Some(old) = self.use_tree() {
return self.replace_descendant(old, use_tree); return self.replace_descendant(old, use_tree);
} }

View file

@ -213,12 +213,12 @@ impl UnionDef {
} }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseItem { pub struct Use {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
impl ast::AttrsOwner for UseItem {} impl ast::AttrsOwner for Use {}
impl ast::VisibilityOwner for UseItem {} impl ast::VisibilityOwner for Use {}
impl UseItem { impl Use {
pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) }
pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) }
pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) }
@ -268,6 +268,36 @@ pub struct Rename {
impl ast::NameOwner for Rename {} impl ast::NameOwner for Rename {}
impl Rename { impl Rename {
pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) }
pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTree {
pub(crate) syntax: SyntaxNode,
}
impl UseTree {
pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Path {
pub(crate) syntax: SyntaxNode,
}
impl Path {
pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTreeList {
pub(crate) syntax: SyntaxNode,
}
impl UseTreeList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Abi { pub struct Abi {
@ -433,15 +463,6 @@ impl PathType {
pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Path {
pub(crate) syntax: SyntaxNode,
}
impl Path {
pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) }
pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PointerType { pub struct PointerType {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -1178,26 +1199,6 @@ impl Param {
pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTree {
pub(crate) syntax: SyntaxNode,
}
impl UseTree {
pub fn path(&self) -> Option<Path> { support::child(&self.syntax) }
pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) }
pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) }
pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) }
pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct UseTreeList {
pub(crate) syntax: SyntaxNode,
}
impl UseTreeList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) }
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct PathSegment { pub struct PathSegment {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -1282,7 +1283,7 @@ pub enum Item {
TraitDef(TraitDef), TraitDef(TraitDef),
TypeAliasDef(TypeAliasDef), TypeAliasDef(TypeAliasDef),
UnionDef(UnionDef), UnionDef(UnionDef),
UseItem(UseItem), Use(Use),
} }
impl ast::AttrsOwner for Item {} impl ast::AttrsOwner for Item {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@ -1561,8 +1562,8 @@ impl AstNode for UnionDef {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for UseItem { impl AstNode for Use {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE_ITEM } fn can_cast(kind: SyntaxKind) -> bool { kind == USE }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) { if Self::can_cast(syntax.kind()) {
Some(Self { syntax }) Some(Self { syntax })
@ -1627,6 +1628,39 @@ impl AstNode for Rename {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for UseTree {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for Path {
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for UseTreeList {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for Abi { impl AstNode for Abi {
fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } fn can_cast(kind: SyntaxKind) -> bool { kind == ABI }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -1825,17 +1859,6 @@ impl AstNode for PathType {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for Path {
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for PointerType { impl AstNode for PointerType {
fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -2672,28 +2695,6 @@ impl AstNode for Param {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for UseTree {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for UseTreeList {
fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for PathSegment { impl AstNode for PathSegment {
fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -2810,15 +2811,16 @@ impl From<TypeAliasDef> for Item {
impl From<UnionDef> for Item { impl From<UnionDef> for Item {
fn from(node: UnionDef) -> Item { Item::UnionDef(node) } fn from(node: UnionDef) -> Item { Item::UnionDef(node) }
} }
impl From<UseItem> for Item { impl From<Use> for Item {
fn from(node: UseItem) -> Item { Item::UseItem(node) } fn from(node: Use) -> Item { Item::Use(node) }
} }
impl AstNode for Item { impl AstNode for Item {
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool {
match kind { match kind {
CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN_DEF | IMPL_DEF | MACRO_CALL CONST_DEF | ENUM_DEF | EXTERN_BLOCK | EXTERN_CRATE | FN_DEF | IMPL_DEF | MACRO_CALL
| MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | MODULE | STATIC_DEF | STRUCT_DEF | TRAIT_DEF | TYPE_ALIAS_DEF | UNION_DEF | USE => {
| USE_ITEM => true, true
}
_ => false, _ => false,
} }
} }
@ -2837,7 +2839,7 @@ impl AstNode for Item {
TRAIT_DEF => Item::TraitDef(TraitDef { syntax }), TRAIT_DEF => Item::TraitDef(TraitDef { syntax }),
TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }), TYPE_ALIAS_DEF => Item::TypeAliasDef(TypeAliasDef { syntax }),
UNION_DEF => Item::UnionDef(UnionDef { syntax }), UNION_DEF => Item::UnionDef(UnionDef { syntax }),
USE_ITEM => Item::UseItem(UseItem { syntax }), USE => Item::Use(Use { syntax }),
_ => return None, _ => return None,
}; };
Some(res) Some(res)
@ -2857,7 +2859,7 @@ impl AstNode for Item {
Item::TraitDef(it) => &it.syntax, Item::TraitDef(it) => &it.syntax,
Item::TypeAliasDef(it) => &it.syntax, Item::TypeAliasDef(it) => &it.syntax,
Item::UnionDef(it) => &it.syntax, Item::UnionDef(it) => &it.syntax,
Item::UseItem(it) => &it.syntax, Item::Use(it) => &it.syntax,
} }
} }
} }
@ -3530,7 +3532,7 @@ impl std::fmt::Display for UnionDef {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for UseItem { impl std::fmt::Display for Use {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
@ -3560,6 +3562,21 @@ impl std::fmt::Display for Rename {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for UseTree {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for Path {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for UseTreeList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for Abi { impl std::fmt::Display for Abi {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
@ -3650,11 +3667,6 @@ impl std::fmt::Display for PathType {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for Path {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for PointerType { impl std::fmt::Display for PointerType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
@ -4035,16 +4047,6 @@ impl std::fmt::Display for Param {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for UseTree {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for UseTreeList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for PathSegment { impl std::fmt::Display for PathSegment {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)

View file

@ -60,7 +60,7 @@ pub fn use_tree_list(use_trees: impl IntoIterator<Item = ast::UseTree>) -> ast::
ast_from_text(&format!("use {{{}}};", use_trees)) ast_from_text(&format!("use {{{}}};", use_trees))
} }
pub fn use_item(use_tree: ast::UseTree) -> ast::UseItem { pub fn use_item(use_tree: ast::UseTree) -> ast::Use {
ast_from_text(&format!("use {};", use_tree)) ast_from_text(&format!("use {};", use_tree))
} }

View file

@ -6,7 +6,7 @@ SOURCE_FILE@0..42
BANG@22..23 "!" BANG@22..23 "!"
ERROR@23..24 ERROR@23..24
SLASH@23..24 "/" SLASH@23..24 "/"
USE_ITEM@24..28 USE@24..28
USE_KW@24..27 "use" USE_KW@24..27 "use"
ERROR@27..28 ERROR@27..28
SLASH@27..28 "/" SLASH@27..28 "/"

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..12 SOURCE_FILE@0..12
USE_ITEM@0..12 USE@0..12
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..11 USE_TREE@4..11

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..48 SOURCE_FILE@0..48
USE_ITEM@0..13 USE@0..13
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..12 USE_TREE@4..12
@ -14,10 +14,10 @@ SOURCE_FILE@0..48
IDENT@9..12 "bar" IDENT@9..12 "bar"
SEMICOLON@12..13 ";" SEMICOLON@12..13 ";"
WHITESPACE@13..14 "\n" WHITESPACE@13..14 "\n"
USE_ITEM@14..17 USE@14..17
USE_KW@14..17 "use" USE_KW@14..17 "use"
WHITESPACE@17..18 "\n" WHITESPACE@17..18 "\n"
USE_ITEM@18..33 USE@18..33
USE_KW@18..21 "use" USE_KW@18..21 "use"
WHITESPACE@21..22 " " WHITESPACE@21..22 " "
USE_TREE@22..32 USE_TREE@22..32
@ -31,7 +31,7 @@ SOURCE_FILE@0..48
IDENT@29..32 "baz" IDENT@29..32 "baz"
SEMICOLON@32..33 ";" SEMICOLON@32..33 ";"
WHITESPACE@33..34 "\n" WHITESPACE@33..34 "\n"
USE_ITEM@34..37 USE@34..37
USE_KW@34..37 "use" USE_KW@34..37 "use"
WHITESPACE@37..38 "\n" WHITESPACE@37..38 "\n"
FN_DEF@38..47 FN_DEF@38..47

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..37 SOURCE_FILE@0..37
USE_ITEM@0..36 USE@0..36
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..36 USE_TREE@4..36

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..98 SOURCE_FILE@0..98
USE_ITEM@0..12 USE@0..12
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..11 USE_TREE@4..11
@ -9,7 +9,7 @@ SOURCE_FILE@0..98
CRATE_KW@6..11 "crate" CRATE_KW@6..11 "crate"
SEMICOLON@11..12 ";" SEMICOLON@11..12 ";"
WHITESPACE@12..13 "\n" WHITESPACE@12..13 "\n"
USE_ITEM@13..54 USE@13..54
USE_KW@13..16 "use" USE_KW@13..16 "use"
WHITESPACE@16..17 " " WHITESPACE@16..17 " "
USE_TREE@17..53 USE_TREE@17..53
@ -52,7 +52,7 @@ SOURCE_FILE@0..98
R_CURLY@52..53 "}" R_CURLY@52..53 "}"
SEMICOLON@53..54 ";" SEMICOLON@53..54 ";"
WHITESPACE@54..55 "\n" WHITESPACE@54..55 "\n"
USE_ITEM@55..72 USE@55..72
USE_KW@55..58 "use" USE_KW@55..58 "use"
WHITESPACE@58..59 " " WHITESPACE@58..59 " "
USE_TREE@59..71 USE_TREE@59..71
@ -66,7 +66,7 @@ SOURCE_FILE@0..98
CRATE_KW@66..71 "crate" CRATE_KW@66..71 "crate"
SEMICOLON@71..72 ";" SEMICOLON@71..72 ";"
WHITESPACE@72..73 "\n" WHITESPACE@72..73 "\n"
USE_ITEM@73..97 USE@73..97
USE_KW@73..76 "use" USE_KW@73..76 "use"
WHITESPACE@76..77 " " WHITESPACE@76..77 " "
USE_TREE@77..96 USE_TREE@77..96

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..67 SOURCE_FILE@0..67
USE_ITEM@0..12 USE@0..12
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..11 USE_TREE@4..11
@ -9,7 +9,7 @@ SOURCE_FILE@0..67
SUPER_KW@6..11 "super" SUPER_KW@6..11 "super"
SEMICOLON@11..12 ";" SEMICOLON@11..12 ";"
WHITESPACE@12..13 "\n" WHITESPACE@12..13 "\n"
USE_ITEM@13..26 USE@13..26
USE_KW@13..16 "use" USE_KW@13..16 "use"
WHITESPACE@16..17 " " WHITESPACE@16..17 " "
USE_TREE@17..25 USE_TREE@17..25
@ -23,7 +23,7 @@ SOURCE_FILE@0..67
SUPER_KW@20..25 "super" SUPER_KW@20..25 "super"
SEMICOLON@25..26 ";" SEMICOLON@25..26 ";"
WHITESPACE@26..27 "\n" WHITESPACE@26..27 "\n"
USE_ITEM@27..47 USE@27..47
USE_KW@27..30 "use" USE_KW@27..30 "use"
WHITESPACE@30..31 " " WHITESPACE@30..31 " "
USE_TREE@31..46 USE_TREE@31..46
@ -41,7 +41,7 @@ SOURCE_FILE@0..67
SUPER_KW@41..46 "super" SUPER_KW@41..46 "super"
SEMICOLON@46..47 ";" SEMICOLON@46..47 ";"
WHITESPACE@47..48 "\n" WHITESPACE@47..48 "\n"
USE_ITEM@48..66 USE@48..66
USE_KW@48..51 "use" USE_KW@48..51 "use"
WHITESPACE@51..52 " " WHITESPACE@51..52 " "
USE_TREE@52..65 USE_TREE@52..65

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..25 SOURCE_FILE@0..25
USE_ITEM@0..11 USE@0..11
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..10 USE_TREE@4..10
@ -9,7 +9,7 @@ SOURCE_FILE@0..25
SELF_KW@6..10 "self" SELF_KW@6..10 "self"
SEMICOLON@10..11 ";" SEMICOLON@10..11 ";"
WHITESPACE@11..12 "\n" WHITESPACE@11..12 "\n"
USE_ITEM@12..24 USE@12..24
USE_KW@12..15 "use" USE_KW@12..15 "use"
WHITESPACE@15..16 " " WHITESPACE@15..16 " "
USE_TREE@16..23 USE_TREE@16..23

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..13 SOURCE_FILE@0..13
USE_ITEM@0..12 USE@0..12
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..12 USE_TREE@4..12

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..249 SOURCE_FILE@0..249
USE_ITEM@0..58 USE@0..58
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..57 USE_TREE@4..57
@ -51,7 +51,7 @@ SOURCE_FILE@0..249
WHITESPACE@58..59 " " WHITESPACE@58..59 " "
COMMENT@59..97 "// Rust 2018 (with a ..." COMMENT@59..97 "// Rust 2018 (with a ..."
WHITESPACE@97..98 "\n" WHITESPACE@97..98 "\n"
USE_ITEM@98..121 USE@98..121
USE_KW@98..101 "use" USE_KW@98..101 "use"
WHITESPACE@101..102 " " WHITESPACE@101..102 " "
USE_TREE@102..120 USE_TREE@102..120
@ -77,7 +77,7 @@ SOURCE_FILE@0..249
WHITESPACE@121..122 " " WHITESPACE@121..122 " "
COMMENT@122..134 "// Rust 2015" COMMENT@122..134 "// Rust 2015"
WHITESPACE@134..135 "\n" WHITESPACE@134..135 "\n"
USE_ITEM@135..166 USE@135..166
USE_KW@135..138 "use" USE_KW@135..138 "use"
WHITESPACE@138..139 " " WHITESPACE@138..139 " "
USE_TREE@139..165 USE_TREE@139..165
@ -104,7 +104,7 @@ SOURCE_FILE@0..249
WHITESPACE@166..167 " " WHITESPACE@166..167 " "
COMMENT@167..179 "// Rust 2015" COMMENT@167..179 "// Rust 2015"
WHITESPACE@179..180 "\n" WHITESPACE@179..180 "\n"
USE_ITEM@180..205 USE@180..205
USE_KW@180..183 "use" USE_KW@180..183 "use"
WHITESPACE@183..184 " " WHITESPACE@183..184 " "
USE_TREE@184..204 USE_TREE@184..204

View file

@ -1,12 +1,12 @@
SOURCE_FILE@0..60 SOURCE_FILE@0..60
USE_ITEM@0..6 USE@0..6
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..5 USE_TREE@4..5
STAR@4..5 "*" STAR@4..5 "*"
SEMICOLON@5..6 ";" SEMICOLON@5..6 ";"
WHITESPACE@6..7 "\n" WHITESPACE@6..7 "\n"
USE_ITEM@7..15 USE@7..15
USE_KW@7..10 "use" USE_KW@7..10 "use"
WHITESPACE@10..11 " " WHITESPACE@10..11 " "
USE_TREE@11..14 USE_TREE@11..14
@ -14,7 +14,7 @@ SOURCE_FILE@0..60
STAR@13..14 "*" STAR@13..14 "*"
SEMICOLON@14..15 ";" SEMICOLON@14..15 ";"
WHITESPACE@15..16 "\n" WHITESPACE@15..16 "\n"
USE_ITEM@16..36 USE@16..36
USE_KW@16..19 "use" USE_KW@16..19 "use"
WHITESPACE@19..20 " " WHITESPACE@19..20 " "
USE_TREE@20..35 USE_TREE@20..35
@ -35,7 +35,7 @@ SOURCE_FILE@0..60
R_CURLY@34..35 "}" R_CURLY@34..35 "}"
SEMICOLON@35..36 ";" SEMICOLON@35..36 ";"
WHITESPACE@36..37 "\n" WHITESPACE@36..37 "\n"
USE_ITEM@37..59 USE@37..59
USE_KW@37..40 "use" USE_KW@37..40 "use"
WHITESPACE@40..41 " " WHITESPACE@40..41 " "
USE_TREE@41..58 USE_TREE@41..58

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..198 SOURCE_FILE@0..198
USE_ITEM@0..28 USE@0..28
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..27 USE_TREE@4..27
@ -20,7 +20,7 @@ SOURCE_FILE@0..198
IDENT@18..27 "some_name" IDENT@18..27 "some_name"
SEMICOLON@27..28 ";" SEMICOLON@27..28 ";"
WHITESPACE@28..29 "\n" WHITESPACE@28..29 "\n"
USE_ITEM@29..181 USE@29..181
USE_KW@29..32 "use" USE_KW@29..32 "use"
WHITESPACE@32..33 " " WHITESPACE@32..33 " "
USE_TREE@33..180 USE_TREE@33..180
@ -121,7 +121,7 @@ SOURCE_FILE@0..198
R_CURLY@179..180 "}" R_CURLY@179..180 "}"
SEMICOLON@180..181 ";" SEMICOLON@180..181 ";"
WHITESPACE@181..182 "\n" WHITESPACE@181..182 "\n"
USE_ITEM@182..197 USE@182..197
USE_KW@182..185 "use" USE_KW@182..185 "use"
WHITESPACE@185..186 " " WHITESPACE@185..186 " "
USE_TREE@186..196 USE_TREE@186..196

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..16 SOURCE_FILE@0..16
USE_ITEM@0..15 USE@0..15
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..14 USE_TREE@4..14

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..37 SOURCE_FILE@0..37
USE_ITEM@0..18 USE@0..18
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..17 USE_TREE@4..17
@ -17,7 +17,7 @@ SOURCE_FILE@0..37
R_CURLY@16..17 "}" R_CURLY@16..17 "}"
SEMICOLON@17..18 ";" SEMICOLON@17..18 ";"
WHITESPACE@18..19 "\n" WHITESPACE@18..19 "\n"
USE_ITEM@19..36 USE@19..36
USE_KW@19..22 "use" USE_KW@19..22 "use"
WHITESPACE@22..23 " " WHITESPACE@22..23 " "
USE_TREE@23..35 USE_TREE@23..35

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..154 SOURCE_FILE@0..154
USE_ITEM@0..17 USE@0..17
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..16 USE_TREE@4..16
@ -12,7 +12,7 @@ SOURCE_FILE@0..154
WHITESPACE@17..18 " " WHITESPACE@17..18 " "
COMMENT@18..45 "// Rust 2018 - All fl ..." COMMENT@18..45 "// Rust 2018 - All fl ..."
WHITESPACE@45..46 "\n" WHITESPACE@45..46 "\n"
USE_ITEM@46..61 USE@46..61
USE_KW@46..49 "use" USE_KW@46..49 "use"
WHITESPACE@49..50 " " WHITESPACE@49..50 " "
USE_TREE@50..60 USE_TREE@50..60
@ -24,7 +24,7 @@ SOURCE_FILE@0..154
WHITESPACE@61..62 " " WHITESPACE@61..62 " "
COMMENT@62..91 "// Rust 2018 - Anchor ..." COMMENT@62..91 "// Rust 2018 - Anchor ..."
WHITESPACE@91..92 "\n" WHITESPACE@91..92 "\n"
USE_ITEM@92..124 USE@92..124
USE_KW@92..95 "use" USE_KW@92..95 "use"
WHITESPACE@95..96 " " WHITESPACE@95..96 " "
USE_TREE@96..123 USE_TREE@96..123

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..19 SOURCE_FILE@0..19
USE_ITEM@0..8 USE@0..8
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..7 USE_TREE@4..7
@ -9,7 +9,7 @@ SOURCE_FILE@0..19
IDENT@4..7 "foo" IDENT@4..7 "foo"
SEMICOLON@7..8 ";" SEMICOLON@7..8 ";"
WHITESPACE@8..9 "\n" WHITESPACE@8..9 "\n"
USE_ITEM@9..19 USE@9..19
USE_KW@9..12 "use" USE_KW@9..12 "use"
WHITESPACE@12..13 " " WHITESPACE@12..13 " "
USE_TREE@13..18 USE_TREE@13..18

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..40 SOURCE_FILE@0..40
USE_ITEM@0..20 USE@0..20
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..19 USE_TREE@4..19
@ -20,7 +20,7 @@ SOURCE_FILE@0..40
IDENT@16..19 "baz" IDENT@16..19 "baz"
SEMICOLON@19..20 ";" SEMICOLON@19..20 ";"
WHITESPACE@20..21 "\n" WHITESPACE@20..21 "\n"
USE_ITEM@21..39 USE@21..39
USE_KW@21..24 "use" USE_KW@21..24 "use"
WHITESPACE@24..25 " " WHITESPACE@24..25 " "
USE_TREE@25..38 USE_TREE@25..38

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..38 SOURCE_FILE@0..38
USE_ITEM@0..14 USE@0..14
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..13 USE_TREE@4..13
@ -13,7 +13,7 @@ SOURCE_FILE@0..38
IDENT@10..13 "foo" IDENT@10..13 "foo"
SEMICOLON@13..14 ";" SEMICOLON@13..14 ";"
WHITESPACE@14..15 "\n" WHITESPACE@14..15 "\n"
USE_ITEM@15..37 USE@15..37
USE_KW@15..18 "use" USE_KW@15..18 "use"
WHITESPACE@18..19 " " WHITESPACE@18..19 " "
USE_TREE@19..36 USE_TREE@19..36

View file

@ -1,12 +1,12 @@
SOURCE_FILE@0..81 SOURCE_FILE@0..81
USE_ITEM@0..6 USE@0..6
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..5 USE_TREE@4..5
STAR@4..5 "*" STAR@4..5 "*"
SEMICOLON@5..6 ";" SEMICOLON@5..6 ";"
WHITESPACE@6..7 "\n" WHITESPACE@6..7 "\n"
USE_ITEM@7..15 USE@7..15
USE_KW@7..10 "use" USE_KW@7..10 "use"
WHITESPACE@10..11 " " WHITESPACE@10..11 " "
USE_TREE@11..14 USE_TREE@11..14
@ -14,7 +14,7 @@ SOURCE_FILE@0..81
STAR@13..14 "*" STAR@13..14 "*"
SEMICOLON@14..15 ";" SEMICOLON@14..15 ";"
WHITESPACE@15..16 "\n" WHITESPACE@15..16 "\n"
USE_ITEM@16..25 USE@16..25
USE_KW@16..19 "use" USE_KW@16..19 "use"
WHITESPACE@19..20 " " WHITESPACE@19..20 " "
USE_TREE@20..24 USE_TREE@20..24
@ -24,7 +24,7 @@ SOURCE_FILE@0..81
R_CURLY@23..24 "}" R_CURLY@23..24 "}"
SEMICOLON@24..25 ";" SEMICOLON@24..25 ";"
WHITESPACE@25..26 "\n" WHITESPACE@25..26 "\n"
USE_ITEM@26..33 USE@26..33
USE_KW@26..29 "use" USE_KW@26..29 "use"
WHITESPACE@29..30 " " WHITESPACE@29..30 " "
USE_TREE@30..32 USE_TREE@30..32
@ -33,7 +33,7 @@ SOURCE_FILE@0..81
R_CURLY@31..32 "}" R_CURLY@31..32 "}"
SEMICOLON@32..33 ";" SEMICOLON@32..33 ";"
WHITESPACE@33..34 "\n" WHITESPACE@33..34 "\n"
USE_ITEM@34..45 USE@34..45
USE_KW@34..37 "use" USE_KW@34..37 "use"
WHITESPACE@37..38 " " WHITESPACE@37..38 " "
USE_TREE@38..44 USE_TREE@38..44
@ -45,7 +45,7 @@ SOURCE_FILE@0..81
STAR@43..44 "*" STAR@43..44 "*"
SEMICOLON@44..45 ";" SEMICOLON@44..45 ";"
WHITESPACE@45..46 "\n" WHITESPACE@45..46 "\n"
USE_ITEM@46..58 USE@46..58
USE_KW@46..49 "use" USE_KW@46..49 "use"
WHITESPACE@49..50 " " WHITESPACE@49..50 " "
USE_TREE@50..57 USE_TREE@50..57
@ -59,7 +59,7 @@ SOURCE_FILE@0..81
R_CURLY@56..57 "}" R_CURLY@56..57 "}"
SEMICOLON@57..58 ";" SEMICOLON@57..58 ";"
WHITESPACE@58..59 "\n" WHITESPACE@58..59 "\n"
USE_ITEM@59..80 USE@59..80
USE_KW@59..62 "use" USE_KW@59..62 "use"
WHITESPACE@62..63 " " WHITESPACE@62..63 " "
USE_TREE@63..79 USE_TREE@63..79

View file

@ -1,5 +1,5 @@
SOURCE_FILE@0..55 SOURCE_FILE@0..55
USE_ITEM@0..15 USE@0..15
USE_KW@0..3 "use" USE_KW@0..3 "use"
WHITESPACE@3..4 " " WHITESPACE@3..4 " "
USE_TREE@4..14 USE_TREE@4..14
@ -15,7 +15,7 @@ SOURCE_FILE@0..55
IDENT@11..14 "bar" IDENT@11..14 "bar"
SEMICOLON@14..15 ";" SEMICOLON@14..15 ";"
WHITESPACE@15..16 "\n" WHITESPACE@15..16 "\n"
USE_ITEM@16..54 USE@16..54
USE_KW@16..19 "use" USE_KW@16..19 "use"
WHITESPACE@19..20 " " WHITESPACE@19..20 " "
USE_TREE@20..53 USE_TREE@20..53

View file

@ -78,7 +78,7 @@ SOURCE_FILE@0..3813
STRING@399..404 "\"128\"" STRING@399..404 "\"128\""
R_BRACK@404..405 "]" R_BRACK@404..405 "]"
WHITESPACE@405..407 "\n\n" WHITESPACE@405..407 "\n\n"
USE_ITEM@407..427 USE@407..427
USE_KW@407..410 "use" USE_KW@407..410 "use"
WHITESPACE@410..411 " " WHITESPACE@410..411 " "
USE_TREE@411..426 USE_TREE@411..426
@ -98,7 +98,7 @@ SOURCE_FILE@0..3813
IDENT@422..426 "Cell" IDENT@422..426 "Cell"
SEMICOLON@426..427 ";" SEMICOLON@426..427 ";"
WHITESPACE@427..428 "\n" WHITESPACE@427..428 "\n"
USE_ITEM@428..447 USE@428..447
USE_KW@428..431 "use" USE_KW@428..431 "use"
WHITESPACE@431..432 " " WHITESPACE@431..432 " "
USE_TREE@432..446 USE_TREE@432..446

View file

@ -100,7 +100,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
"RET_TYPE", "RET_TYPE",
"EXTERN_CRATE", "EXTERN_CRATE",
"MODULE", "MODULE",
"USE_ITEM", "USE",
"STATIC_DEF", "STATIC_DEF",
"CONST_DEF", "CONST_DEF",
"TRAIT_DEF", "TRAIT_DEF",

View file

@ -543,6 +543,10 @@ fn lower_enum(grammar: &Grammar, rule: &Rule) -> Option<Vec<String>> {
} }
fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) { fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) {
if lower_comma_list(acc, grammar, rule) {
return;
}
match rule { match rule {
Rule::Node(node) => { Rule::Node(node) => {
let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand }; let field = Field::Node { name: grammar[*node].name.clone(), src: FieldSrc::Shorthand };
@ -595,6 +599,37 @@ fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) {
} }
} }
// (T (',' T)* ','?)?
fn lower_comma_list(acc: &mut Vec<Field>, grammar: &Grammar, rule: &Rule) -> bool {
let rule = match rule {
Rule::Opt(it) => it,
_ => return false,
};
let rule = match &**rule {
Rule::Seq(it) => it,
_ => return false,
};
let (node, repeat, trailing_comma) = match rule.as_slice() {
[Rule::Node(node), Rule::Rep(repeat), Rule::Opt(trailing_comma)] => {
(node, repeat, trailing_comma)
}
_ => return false,
};
let repeat = match &**repeat {
Rule::Seq(it) => it,
_ => return false,
};
match repeat.as_slice() {
[comma, Rule::Node(n)] if comma == &**trailing_comma && n == node => (),
_ => return false,
}
let name = grammar[*node].name.clone();
let label = pluralize(&to_lower_snake_case(&name));
let field = Field::Node { name: label.clone(), src: FieldSrc::Many(name) };
acc.push(field);
true
}
fn deduplicate_fields(ast: &mut AstSrc) { fn deduplicate_fields(ast: &mut AstSrc) {
for node in &mut ast.nodes { for node in &mut ast.nodes {
let mut i = 0; let mut i = 0;

View file

@ -17,7 +17,7 @@ Item =
| TraitDef | TraitDef
| TypeAliasDef | TypeAliasDef
| UnionDef | UnionDef
| UseItem | Use
Module = Module =
Attr* Visibility? 'mod' Name Attr* Visibility? 'mod' Name
@ -29,6 +29,19 @@ ItemList =
ExternCrate = ExternCrate =
Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';' Attr* Visibility? 'extern' 'crate' (NameRef | 'self') Rename? ';'
Rename =
'as' (Name | '_')
Use =
Attr* Visibility? 'use' UseTree ';'
UseTree =
(Path? '::')? ('*' | UseTreeList )
| Path Rename?
UseTreeList =
'{' (UseTree (',' UseTree)* ','?)? '}'
FnDef = FnDef =
Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList? Attr* Visibility? Abi? 'const' 'default' 'async' 'unsafe' 'fn' Name TypeParamList?
ParamList RetType? ParamList RetType?
@ -395,18 +408,6 @@ Param =
Attr* Pat (':' ascribed_type:TypeRef) Attr* Pat (':' ascribed_type:TypeRef)
| '...' | '...'
UseItem =
Attr* Visibility? 'use' UseTree ';'
UseTree =
Path ('::' ('*' | UseTreeList)) Rename?
UseTreeList =
'{' UseTree* '}'
Rename =
'as' Name
Path = Path =
(qualifier:Path '::')? segment:PathSegment (qualifier:Path '::')? segment:PathSegment