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.rs | 4 ++-- crates/ra_syntax/src/ast/expr_extensions.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'crates/ra_syntax') 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::{ generated::*, traits::*, tokens::*, - extensions::{PathSegmentKind, StructKind, FieldKind, SelfParamKind}, - expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind}, + extensions::{PathSegmentKind, StructKind, SelfParamKind}, + expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind,ArrayExprKind}, }; /// 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 { } } +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