Add MacroType
syntax
This commit is contained in:
parent
9daba961f2
commit
872bf09381
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -1839,9 +1839,9 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ungrammar"
|
name = "ungrammar"
|
||||||
version = "1.9.0"
|
version = "1.9.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b137a875a3b942539dd04bd37d193649f5d67e11407186f5b9d63ae0332b1a93"
|
checksum = "58a02e2041a872d56354e843e8e86e6b946fc8e7dc32982fcdc335e29eb4cc8b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicase"
|
name = "unicase"
|
||||||
|
@ -159,6 +159,8 @@ pub(crate) fn from_ast(ctx: &LowerCtx, node: ast::Type) -> Self {
|
|||||||
ast::Type::DynTraitType(inner) => {
|
ast::Type::DynTraitType(inner) => {
|
||||||
TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
|
TypeRef::DynTrait(type_bounds_from_ast(ctx, inner.type_bound_list()))
|
||||||
}
|
}
|
||||||
|
// FIXME: Macros in type position are not yet supported.
|
||||||
|
ast::Type::MacroType(_) => TypeRef::Error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +143,7 @@ pub enum SyntaxKind {
|
|||||||
MACRO_DEF,
|
MACRO_DEF,
|
||||||
PAREN_TYPE,
|
PAREN_TYPE,
|
||||||
TUPLE_TYPE,
|
TUPLE_TYPE,
|
||||||
|
MACRO_TYPE,
|
||||||
NEVER_TYPE,
|
NEVER_TYPE,
|
||||||
PATH_TYPE,
|
PATH_TYPE,
|
||||||
PTR_TYPE,
|
PTR_TYPE,
|
||||||
|
@ -1072,6 +1072,13 @@ impl InferType {
|
|||||||
pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
|
pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) }
|
||||||
}
|
}
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
|
pub struct MacroType {
|
||||||
|
pub(crate) syntax: SyntaxNode,
|
||||||
|
}
|
||||||
|
impl MacroType {
|
||||||
|
pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) }
|
||||||
|
}
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct NeverType {
|
pub struct NeverType {
|
||||||
pub(crate) syntax: SyntaxNode,
|
pub(crate) syntax: SyntaxNode,
|
||||||
}
|
}
|
||||||
@ -1300,6 +1307,7 @@ pub enum Type {
|
|||||||
ForType(ForType),
|
ForType(ForType),
|
||||||
ImplTraitType(ImplTraitType),
|
ImplTraitType(ImplTraitType),
|
||||||
InferType(InferType),
|
InferType(InferType),
|
||||||
|
MacroType(MacroType),
|
||||||
NeverType(NeverType),
|
NeverType(NeverType),
|
||||||
ParenType(ParenType),
|
ParenType(ParenType),
|
||||||
PathType(PathType),
|
PathType(PathType),
|
||||||
@ -2558,6 +2566,17 @@ fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|||||||
}
|
}
|
||||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||||
}
|
}
|
||||||
|
impl AstNode for MacroType {
|
||||||
|
fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_TYPE }
|
||||||
|
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 NeverType {
|
impl AstNode for NeverType {
|
||||||
fn can_cast(kind: SyntaxKind) -> bool { kind == NEVER_TYPE }
|
fn can_cast(kind: SyntaxKind) -> bool { kind == NEVER_TYPE }
|
||||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||||
@ -2889,6 +2908,9 @@ fn from(node: ImplTraitType) -> Type { Type::ImplTraitType(node) }
|
|||||||
impl From<InferType> for Type {
|
impl From<InferType> for Type {
|
||||||
fn from(node: InferType) -> Type { Type::InferType(node) }
|
fn from(node: InferType) -> Type { Type::InferType(node) }
|
||||||
}
|
}
|
||||||
|
impl From<MacroType> for Type {
|
||||||
|
fn from(node: MacroType) -> Type { Type::MacroType(node) }
|
||||||
|
}
|
||||||
impl From<NeverType> for Type {
|
impl From<NeverType> for Type {
|
||||||
fn from(node: NeverType) -> Type { Type::NeverType(node) }
|
fn from(node: NeverType) -> Type { Type::NeverType(node) }
|
||||||
}
|
}
|
||||||
@ -2914,8 +2936,8 @@ impl AstNode for Type {
|
|||||||
fn can_cast(kind: SyntaxKind) -> bool {
|
fn can_cast(kind: SyntaxKind) -> bool {
|
||||||
match kind {
|
match kind {
|
||||||
ARRAY_TYPE | DYN_TRAIT_TYPE | FN_PTR_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | INFER_TYPE
|
ARRAY_TYPE | DYN_TRAIT_TYPE | FN_PTR_TYPE | FOR_TYPE | IMPL_TRAIT_TYPE | INFER_TYPE
|
||||||
| NEVER_TYPE | PAREN_TYPE | PATH_TYPE | PTR_TYPE | REF_TYPE | SLICE_TYPE
|
| MACRO_TYPE | NEVER_TYPE | PAREN_TYPE | PATH_TYPE | PTR_TYPE | REF_TYPE
|
||||||
| TUPLE_TYPE => true,
|
| SLICE_TYPE | TUPLE_TYPE => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2927,6 +2949,7 @@ fn cast(syntax: SyntaxNode) -> Option<Self> {
|
|||||||
FOR_TYPE => Type::ForType(ForType { syntax }),
|
FOR_TYPE => Type::ForType(ForType { syntax }),
|
||||||
IMPL_TRAIT_TYPE => Type::ImplTraitType(ImplTraitType { syntax }),
|
IMPL_TRAIT_TYPE => Type::ImplTraitType(ImplTraitType { syntax }),
|
||||||
INFER_TYPE => Type::InferType(InferType { syntax }),
|
INFER_TYPE => Type::InferType(InferType { syntax }),
|
||||||
|
MACRO_TYPE => Type::MacroType(MacroType { syntax }),
|
||||||
NEVER_TYPE => Type::NeverType(NeverType { syntax }),
|
NEVER_TYPE => Type::NeverType(NeverType { syntax }),
|
||||||
PAREN_TYPE => Type::ParenType(ParenType { syntax }),
|
PAREN_TYPE => Type::ParenType(ParenType { syntax }),
|
||||||
PATH_TYPE => Type::PathType(PathType { syntax }),
|
PATH_TYPE => Type::PathType(PathType { syntax }),
|
||||||
@ -2946,6 +2969,7 @@ fn syntax(&self) -> &SyntaxNode {
|
|||||||
Type::ForType(it) => &it.syntax,
|
Type::ForType(it) => &it.syntax,
|
||||||
Type::ImplTraitType(it) => &it.syntax,
|
Type::ImplTraitType(it) => &it.syntax,
|
||||||
Type::InferType(it) => &it.syntax,
|
Type::InferType(it) => &it.syntax,
|
||||||
|
Type::MacroType(it) => &it.syntax,
|
||||||
Type::NeverType(it) => &it.syntax,
|
Type::NeverType(it) => &it.syntax,
|
||||||
Type::ParenType(it) => &it.syntax,
|
Type::ParenType(it) => &it.syntax,
|
||||||
Type::PathType(it) => &it.syntax,
|
Type::PathType(it) => &it.syntax,
|
||||||
@ -4082,6 +4106,11 @@ 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
impl std::fmt::Display for MacroType {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
std::fmt::Display::fmt(self.syntax(), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
impl std::fmt::Display for NeverType {
|
impl std::fmt::Display for NeverType {
|
||||||
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)
|
||||||
|
@ -104,6 +104,7 @@ pub(crate) struct KindsSrc<'a> {
|
|||||||
"MACRO_DEF",
|
"MACRO_DEF",
|
||||||
"PAREN_TYPE",
|
"PAREN_TYPE",
|
||||||
"TUPLE_TYPE",
|
"TUPLE_TYPE",
|
||||||
|
"MACRO_TYPE",
|
||||||
"NEVER_TYPE",
|
"NEVER_TYPE",
|
||||||
"PATH_TYPE",
|
"PATH_TYPE",
|
||||||
"PTR_TYPE",
|
"PTR_TYPE",
|
||||||
|
Loading…
Reference in New Issue
Block a user