Add DotDotPat to AST

This is modeled on `PlaceholderPat`.
This commit is contained in:
Dylan MacKenzie 2019-09-14 17:05:12 -07:00
parent 211171ffe6
commit 426112c97e
4 changed files with 40 additions and 2 deletions

View File

@ -573,6 +573,7 @@ where
}
// FIXME: implement
ast::Pat::DotDotPat(_) => Pat::Missing,
ast::Pat::BoxPat(_) => Pat::Missing,
ast::Pat::LiteralPat(_) => Pat::Missing,
ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing,

View File

@ -152,6 +152,7 @@ pub enum SyntaxKind {
BOX_PAT,
BIND_PAT,
PLACEHOLDER_PAT,
DOT_DOT_PAT,
PATH_PAT,
RECORD_PAT,
RECORD_FIELD_PAT_LIST,

View File

@ -532,6 +532,29 @@ impl AstNode for ContinueExpr {
}
impl ContinueExpr {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DotDotPat {
pub(crate) syntax: SyntaxNode,
}
impl AstNode for DotDotPat {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
DOT_DOT_PAT => 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 DotDotPat {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct DynTraitType {
pub(crate) syntax: SyntaxNode,
}
@ -2128,6 +2151,7 @@ pub enum Pat {
BoxPat(BoxPat),
BindPat(BindPat),
PlaceholderPat(PlaceholderPat),
DotDotPat(DotDotPat),
PathPat(PathPat),
RecordPat(RecordPat),
TupleStructPat(TupleStructPat),
@ -2156,6 +2180,11 @@ impl From<PlaceholderPat> for Pat {
Pat::PlaceholderPat(node)
}
}
impl From<DotDotPat> for Pat {
fn from(node: DotDotPat) -> Pat {
Pat::DotDotPat(node)
}
}
impl From<PathPat> for Pat {
fn from(node: PathPat) -> Pat {
Pat::PathPat(node)
@ -2194,8 +2223,10 @@ impl From<LiteralPat> for Pat {
impl AstNode for Pat {
fn can_cast(kind: SyntaxKind) -> bool {
match kind {
REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | PATH_PAT | RECORD_PAT
| TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => true,
REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT
| RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => {
true
}
_ => false,
}
}
@ -2205,6 +2236,7 @@ impl AstNode for Pat {
BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
BIND_PAT => Pat::BindPat(BindPat { syntax }),
PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }),
DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }),
PATH_PAT => Pat::PathPat(PathPat { syntax }),
RECORD_PAT => Pat::RecordPat(RecordPat { syntax }),
TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }),
@ -2222,6 +2254,7 @@ impl AstNode for Pat {
Pat::BoxPat(it) => &it.syntax,
Pat::BindPat(it) => &it.syntax,
Pat::PlaceholderPat(it) => &it.syntax,
Pat::DotDotPat(it) => &it.syntax,
Pat::PathPat(it) => &it.syntax,
Pat::RecordPat(it) => &it.syntax,
Pat::TupleStructPat(it) => &it.syntax,

View File

@ -161,6 +161,7 @@ Grammar(
"BOX_PAT",
"BIND_PAT",
"PLACEHOLDER_PAT",
"DOT_DOT_PAT",
"PATH_PAT",
"RECORD_PAT",
"RECORD_FIELD_PAT_LIST",
@ -532,6 +533,7 @@ Grammar(
traits: ["NameOwner"]
),
"PlaceholderPat": (),
"DotDotPat": (),
"PathPat": ( options: [ "Path" ] ),
"RecordPat": ( options: ["RecordFieldPatList", "Path"] ),
"RecordFieldPatList": (
@ -559,6 +561,7 @@ Grammar(
"BoxPat",
"BindPat",
"PlaceholderPat",
"DotDotPat",
"PathPat",
"RecordPat",
"TupleStructPat",