aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
authorLenard Pratt <[email protected]>2019-04-04 23:29:21 +0100
committerLenard Pratt <[email protected]>2019-04-07 13:23:14 +0100
commite175921932615cb97eaa5cfd11d940cbd1473cac (patch)
tree14830570c216a7536848b652ded69fdea48ad9c7 /crates/ra_syntax/src
parent2d73c909fe03c799b488aa0f97a588e13bbd7006 (diff)
Added ArrayExprKind,
changed the display for fixed array types, Added Array Enum to ra_hir/expr
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs4
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs22
2 files changed, 24 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index a06a6375d..970b89825 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -17,8 +17,8 @@ pub use self::{
17 generated::*, 17 generated::*,
18 traits::*, 18 traits::*,
19 tokens::*, 19 tokens::*,
20 extensions::{PathSegmentKind, StructKind, FieldKind, SelfParamKind}, 20 extensions::{PathSegmentKind, StructKind, SelfParamKind},
21 expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind}, 21 expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind,ArrayExprKind},
22}; 22};
23 23
24/// The main trait to go from untyped `SyntaxNode` to a typed ast. The 24/// The main trait to go from untyped `SyntaxNode` to a typed ast. The
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 1d8313810..d21ec80c3 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -193,6 +193,28 @@ impl ast::BinExpr {
193 } 193 }
194} 194}
195 195
196pub enum ArrayExprKind<'a> {
197 Repeat { initializer: Option<&'a ast::Expr>, repeat: Option<&'a ast::Expr> },
198 ElementList(AstChildren<'a, ast::Expr>),
199}
200
201impl ast::ArrayExpr {
202 pub fn kind(&self) -> ArrayExprKind {
203 if self.is_repeat() {
204 ArrayExprKind::Repeat {
205 initializer: children(self).nth(0),
206 repeat: children(self).nth(2),
207 }
208 } else {
209 ArrayExprKind::ElementList(children(self))
210 }
211 }
212
213 fn is_repeat(&self) -> bool {
214 self.syntax().children_with_tokens().any(|it| it.kind() == SEMI)
215 }
216}
217
196#[derive(Clone, Debug, PartialEq, Eq, Hash)] 218#[derive(Clone, Debug, PartialEq, Eq, Hash)]
197pub enum LiteralKind { 219pub enum LiteralKind {
198 String, 220 String,