Parse const generics

Fixes #1574
Fixes #2281
This commit is contained in:
roblabla
2019-12-22 00:38:23 +00:00
parent 90f3b31efc
commit b04d4a88d1
6 changed files with 71 additions and 0 deletions

View File

@@ -551,6 +551,36 @@ impl ConstDef {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ConstParam {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for ConstParam {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
CONST_PARAM => true,
_ => false,
}
}
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode {
&self.syntax
}
}
impl ast::NameOwner for ConstParam {}
impl ast::AttrsOwner for ConstParam {}
impl ast::TypeAscriptionOwner for ConstParam {}
impl ConstParam {
pub fn default_val(&self) -> Option<Expr> {
AstChildren::new(&self.syntax).next()
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ContinueExpr {
pub(crate) syntax: SyntaxNode,
}

View File

@@ -243,6 +243,7 @@ Grammar(
"TYPE_PARAM_LIST",
"LIFETIME_PARAM",
"TYPE_PARAM",
"CONST_PARAM",
"TYPE_ARG_LIST",
"LIFETIME_ARG",
"TYPE_ARG",
@@ -602,6 +603,10 @@ Grammar(
options: [("default_type", "TypeRef")],
traits: ["NameOwner", "AttrsOwner", "TypeBoundsOwner"],
),
"ConstParam": (
options: [("default_val", "Expr")],
traits: ["NameOwner", "AttrsOwner", "TypeAscriptionOwner"],
),
"LifetimeParam": (
traits: ["AttrsOwner"],
),