From e175921932615cb97eaa5cfd11d940cbd1473cac Mon Sep 17 00:00:00 2001 From: Lenard Pratt Date: Thu, 4 Apr 2019 23:29:21 +0100 Subject: Added ArrayExprKind, changed the display for fixed array types, Added Array Enum to ra_hir/expr --- crates/ra_syntax/src/ast/expr_extensions.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'crates/ra_syntax/src/ast') 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 { } } +pub enum ArrayExprKind<'a> { + Repeat { initializer: Option<&'a ast::Expr>, repeat: Option<&'a ast::Expr> }, + ElementList(AstChildren<'a, ast::Expr>), +} + +impl ast::ArrayExpr { + pub fn kind(&self) -> ArrayExprKind { + if self.is_repeat() { + ArrayExprKind::Repeat { + initializer: children(self).nth(0), + repeat: children(self).nth(2), + } + } else { + ArrayExprKind::ElementList(children(self)) + } + } + + fn is_repeat(&self) -> bool { + self.syntax().children_with_tokens().any(|it| it.kind() == SEMI) + } +} + #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum LiteralKind { String, -- cgit v1.2.3