aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorMatthew Jasper <[email protected]>2020-02-09 18:57:01 +0000
committerMatthew Jasper <[email protected]>2020-02-09 22:06:15 +0000
commit8c8d0bb34f5495e0f260b5aaf3685ecb98406f32 (patch)
tree26df75871f23bb30fbef81fbc3c75beedaf20ab5 /crates/ra_syntax/src/ast
parent1b9b13b4b4a75b5531c3f046ce6bf72d681f2732 (diff)
Add or- and parenthesized-patterns
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs81
1 files changed, 75 insertions, 6 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 435135f92..8d640642d 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1759,8 +1759,8 @@ impl AstNode for MatchArm {
1759} 1759}
1760impl ast::AttrsOwner for MatchArm {} 1760impl ast::AttrsOwner for MatchArm {}
1761impl MatchArm { 1761impl MatchArm {
1762 pub fn pats(&self) -> AstChildren<Pat> { 1762 pub fn pat(&self) -> Option<Pat> {
1763 AstChildren::new(&self.syntax) 1763 AstChildren::new(&self.syntax).next()
1764 } 1764 }
1765 pub fn guard(&self) -> Option<MatchGuard> { 1765 pub fn guard(&self) -> Option<MatchGuard> {
1766 AstChildren::new(&self.syntax).next() 1766 AstChildren::new(&self.syntax).next()
@@ -1887,6 +1887,60 @@ impl RecordField {
1887 } 1887 }
1888} 1888}
1889#[derive(Debug, Clone, PartialEq, Eq, Hash)] 1889#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1890pub struct OrPat {
1891 pub(crate) syntax: SyntaxNode,
1892}
1893impl AstNode for OrPat {
1894 fn can_cast(kind: SyntaxKind) -> bool {
1895 match kind {
1896 OR_PAT => true,
1897 _ => false,
1898 }
1899 }
1900 fn cast(syntax: SyntaxNode) -> Option<Self> {
1901 if Self::can_cast(syntax.kind()) {
1902 Some(Self { syntax })
1903 } else {
1904 None
1905 }
1906 }
1907 fn syntax(&self) -> &SyntaxNode {
1908 &self.syntax
1909 }
1910}
1911impl OrPat {
1912 pub fn pats(&self) -> AstChildren<Pat> {
1913 AstChildren::new(&self.syntax)
1914 }
1915}
1916#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1917pub struct ParenPat {
1918 pub(crate) syntax: SyntaxNode,
1919}
1920impl AstNode for ParenPat {
1921 fn can_cast(kind: SyntaxKind) -> bool {
1922 match kind {
1923 PAREN_PAT => true,
1924 _ => false,
1925 }
1926 }
1927 fn cast(syntax: SyntaxNode) -> Option<Self> {
1928 if Self::can_cast(syntax.kind()) {
1929 Some(Self { syntax })
1930 } else {
1931 None
1932 }
1933 }
1934 fn syntax(&self) -> &SyntaxNode {
1935 &self.syntax
1936 }
1937}
1938impl ParenPat {
1939 pub fn pat(&self) -> Option<Pat> {
1940 AstChildren::new(&self.syntax).next()
1941 }
1942}
1943#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1890pub struct RefPat { 1944pub struct RefPat {
1891 pub(crate) syntax: SyntaxNode, 1945 pub(crate) syntax: SyntaxNode,
1892} 1946}
@@ -3900,6 +3954,8 @@ impl AstNode for Expr {
3900} 3954}
3901#[derive(Debug, Clone, PartialEq, Eq, Hash)] 3955#[derive(Debug, Clone, PartialEq, Eq, Hash)]
3902pub enum Pat { 3956pub enum Pat {
3957 OrPat(OrPat),
3958 ParenPat(ParenPat),
3903 RefPat(RefPat), 3959 RefPat(RefPat),
3904 BoxPat(BoxPat), 3960 BoxPat(BoxPat),
3905 BindPat(BindPat), 3961 BindPat(BindPat),
@@ -3913,6 +3969,16 @@ pub enum Pat {
3913 RangePat(RangePat), 3969 RangePat(RangePat),
3914 LiteralPat(LiteralPat), 3970 LiteralPat(LiteralPat),
3915} 3971}
3972impl From<OrPat> for Pat {
3973 fn from(node: OrPat) -> Pat {
3974 Pat::OrPat(node)
3975 }
3976}
3977impl From<ParenPat> for Pat {
3978 fn from(node: ParenPat) -> Pat {
3979 Pat::ParenPat(node)
3980 }
3981}
3916impl From<RefPat> for Pat { 3982impl From<RefPat> for Pat {
3917 fn from(node: RefPat) -> Pat { 3983 fn from(node: RefPat) -> Pat {
3918 Pat::RefPat(node) 3984 Pat::RefPat(node)
@@ -3976,15 +4042,16 @@ impl From<LiteralPat> for Pat {
3976impl AstNode for Pat { 4042impl AstNode for Pat {
3977 fn can_cast(kind: SyntaxKind) -> bool { 4043 fn can_cast(kind: SyntaxKind) -> bool {
3978 match kind { 4044 match kind {
3979 REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | PATH_PAT 4045 OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT
3980 | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | LITERAL_PAT => { 4046 | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT
3981 true 4047 | LITERAL_PAT => true,
3982 }
3983 _ => false, 4048 _ => false,
3984 } 4049 }
3985 } 4050 }
3986 fn cast(syntax: SyntaxNode) -> Option<Self> { 4051 fn cast(syntax: SyntaxNode) -> Option<Self> {
3987 let res = match syntax.kind() { 4052 let res = match syntax.kind() {
4053 OR_PAT => Pat::OrPat(OrPat { syntax }),
4054 PAREN_PAT => Pat::ParenPat(ParenPat { syntax }),
3988 REF_PAT => Pat::RefPat(RefPat { syntax }), 4055 REF_PAT => Pat::RefPat(RefPat { syntax }),
3989 BOX_PAT => Pat::BoxPat(BoxPat { syntax }), 4056 BOX_PAT => Pat::BoxPat(BoxPat { syntax }),
3990 BIND_PAT => Pat::BindPat(BindPat { syntax }), 4057 BIND_PAT => Pat::BindPat(BindPat { syntax }),
@@ -4003,6 +4070,8 @@ impl AstNode for Pat {
4003 } 4070 }
4004 fn syntax(&self) -> &SyntaxNode { 4071 fn syntax(&self) -> &SyntaxNode {
4005 match self { 4072 match self {
4073 Pat::OrPat(it) => &it.syntax,
4074 Pat::ParenPat(it) => &it.syntax,
4006 Pat::RefPat(it) => &it.syntax, 4075 Pat::RefPat(it) => &it.syntax,
4007 Pat::BoxPat(it) => &it.syntax, 4076 Pat::BoxPat(it) => &it.syntax,
4008 Pat::BindPat(it) => &it.syntax, 4077 Pat::BindPat(it) => &it.syntax,