5607: Finaize item 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 16:39:40 +00:00 committed by GitHub
commit af8132e610
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 90 additions and 82 deletions

View file

@ -557,6 +557,7 @@ impl Ctx {
let statik = self.lower_static(&ast)?; let statik = self.lower_static(&ast)?;
statik.into() statik.into()
} }
ast::ExternItem::MacroCall(_) => return None,
}; };
self.add_attrs(id.into(), attrs); self.add_attrs(id.into(), attrs);
Some(id) Some(id)

View file

@ -453,12 +453,23 @@ impl Variant {
pub struct AssocItemList { pub struct AssocItemList {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
impl ast::AttrsOwner for AssocItemList {}
impl AssocItemList { impl AssocItemList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) }
pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } 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 ExternItemList {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ExternItemList {}
impl ExternItemList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn extern_items(&self) -> AstChildren<ExternItem> { 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 ParenType { pub struct ParenType {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -1254,15 +1265,6 @@ impl ConstArg {
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ExternItemList {
pub(crate) syntax: SyntaxNode,
}
impl ExternItemList {
pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) }
pub fn extern_items(&self) -> AstChildren<ExternItem> { 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 MetaItem { pub struct MetaItem {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -1373,6 +1375,14 @@ pub enum AssocItem {
impl ast::AttrsOwner for AssocItem {} impl ast::AttrsOwner for AssocItem {}
impl ast::NameOwner for AssocItem {} impl ast::NameOwner for AssocItem {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExternItem {
Fn(Fn),
Static(Static),
MacroCall(MacroCall),
}
impl ast::AttrsOwner for ExternItem {}
impl ast::NameOwner for ExternItem {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Stmt { pub enum Stmt {
LetStmt(LetStmt), LetStmt(LetStmt),
ExprStmt(ExprStmt), ExprStmt(ExprStmt),
@ -1384,14 +1394,6 @@ pub enum AttrInput {
TokenTree(TokenTree), TokenTree(TokenTree),
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ExternItem {
Fn(Fn),
Static(Static),
}
impl ast::AttrsOwner for ExternItem {}
impl ast::NameOwner for ExternItem {}
impl ast::VisibilityOwner for ExternItem {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AdtDef { pub enum AdtDef {
Struct(Struct), Struct(Struct),
Enum(Enum), Enum(Enum),
@ -1841,6 +1843,17 @@ impl AstNode for AssocItemList {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for ExternItemList {
fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_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 ParenType { impl AstNode for ParenType {
fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE } fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -2754,17 +2767,6 @@ impl AstNode for ConstArg {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for ExternItemList {
fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_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 MetaItem { impl AstNode for MetaItem {
fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM } fn can_cast(kind: SyntaxKind) -> bool { kind == META_ITEM }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -3290,6 +3292,39 @@ impl AstNode for AssocItem {
} }
} }
} }
impl From<Fn> for ExternItem {
fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
}
impl From<Static> for ExternItem {
fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
}
impl From<MacroCall> for ExternItem {
fn from(node: MacroCall) -> ExternItem { ExternItem::MacroCall(node) }
}
impl AstNode for ExternItem {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FN | STATIC | MACRO_CALL => true,
_ => false,
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
let res = match syntax.kind() {
FN => ExternItem::Fn(Fn { syntax }),
STATIC => ExternItem::Static(Static { syntax }),
MACRO_CALL => ExternItem::MacroCall(MacroCall { syntax }),
_ => return None,
};
Some(res)
}
fn syntax(&self) -> &SyntaxNode {
match self {
ExternItem::Fn(it) => &it.syntax,
ExternItem::Static(it) => &it.syntax,
ExternItem::MacroCall(it) => &it.syntax,
}
}
}
impl From<LetStmt> for Stmt { impl From<LetStmt> for Stmt {
fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) } fn from(node: LetStmt) -> Stmt { Stmt::LetStmt(node) }
} }
@ -3346,34 +3381,6 @@ impl AstNode for AttrInput {
} }
} }
} }
impl From<Fn> for ExternItem {
fn from(node: Fn) -> ExternItem { ExternItem::Fn(node) }
}
impl From<Static> for ExternItem {
fn from(node: Static) -> ExternItem { ExternItem::Static(node) }
}
impl AstNode for ExternItem {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FN | STATIC => true,
_ => false,
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
let res = match syntax.kind() {
FN => ExternItem::Fn(Fn { syntax }),
STATIC => ExternItem::Static(Static { syntax }),
_ => return None,
};
Some(res)
}
fn syntax(&self) -> &SyntaxNode {
match self {
ExternItem::Fn(it) => &it.syntax,
ExternItem::Static(it) => &it.syntax,
}
}
}
impl From<Struct> for AdtDef { impl From<Struct> for AdtDef {
fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) } fn from(node: Struct) -> AdtDef { AdtDef::Struct(node) }
} }
@ -3437,6 +3444,11 @@ impl std::fmt::Display for AssocItem {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for ExternItem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for Stmt { impl std::fmt::Display for Stmt {
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)
@ -3447,11 +3459,6 @@ impl std::fmt::Display for AttrInput {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for ExternItem {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for AdtDef { impl std::fmt::Display for AdtDef {
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)
@ -3657,6 +3664,11 @@ impl std::fmt::Display for AssocItemList {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for ExternItemList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for ParenType { impl std::fmt::Display for ParenType {
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)
@ -4072,11 +4084,6 @@ impl std::fmt::Display for ConstArg {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for ExternItemList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for MetaItem { impl std::fmt::Display for MetaItem {
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

@ -129,7 +129,13 @@ Trait =
AssocItemList AssocItemList
AssocItemList = AssocItemList =
'{' AssocItem* '}' '{' Attr* AssocItem* '}'
AssocItem =
Fn
| TypeAlias
| Const
| MacroCall
Impl = Impl =
Attr* Visibility? Attr* Visibility?
@ -139,6 +145,15 @@ Impl =
) WhereClause? ) WhereClause?
AssocItemList AssocItemList
ExternBlock =
Attr* Abi ExternItemList
ExternItemList =
'{' Attr* ExternItem* '}'
ExternItem =
Fn | Static | MacroCall
ParenType = ParenType =
'(' TypeRef ')' '(' TypeRef ')'
@ -449,12 +464,6 @@ LifetimeArg =
ConstArg = ConstArg =
Literal | BlockExpr BlockExpr Literal | BlockExpr BlockExpr
ExternBlock =
Attr* Abi ExternItemList
ExternItemList =
'{' extern_items:ExternItem* '}'
MetaItem = MetaItem =
Path '=' AttrInput nested_meta_items:MetaItem* Path '=' AttrInput nested_meta_items:MetaItem*
@ -478,15 +487,6 @@ TypeRef =
| ImplTraitType | ImplTraitType
| DynTraitType | DynTraitType
AssocItem =
Fn
| TypeAlias
| Const
| MacroCall
ExternItem =
Fn | Static
AttrInput = AttrInput =
Literal Literal
| TokenTree | TokenTree