From 2d73c909fe03c799b488aa0f97a588e13bbd7006 Mon Sep 17 00:00:00 2001 From: Lenard Pratt Date: Wed, 3 Apr 2019 23:23:58 +0100 Subject: Added inference of array length --- crates/ra_syntax/src/ast/generated.rs | 4 ++++ crates/ra_syntax/src/grammar.ron | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 0376c91c8..39b760551 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -108,6 +108,10 @@ impl ArrayExpr { pub fn exprs(&self) -> impl Iterator { super::children(self) } + + pub fn repeat(&self) -> Option<&Expr> { + super::child_opt(self) + } } // ArrayType diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 0a35e25d5..c7116c69b 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -395,7 +395,8 @@ Grammar( collections: [["exprs", "Expr"]] ), "ArrayExpr": ( - collections: [["exprs", "Expr"]] + collections: [["exprs", "Expr"]], + options:[["repeat","Expr"]] ), "ParenExpr": (options: ["Expr"]), "PathExpr": (options: ["Path"]), -- cgit v1.2.3 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/src') 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 From b27fa33a9f459feb442682026670ca8e6001a424 Mon Sep 17 00:00:00 2001 From: Lenard Pratt Date: Fri, 5 Apr 2019 11:19:25 +0100 Subject: updated snapshots --- crates/ra_syntax/src/ast.rs | 2 +- crates/ra_syntax/src/ast/expr_extensions.rs | 2 +- crates/ra_syntax/src/ast/generated.rs | 4 ---- crates/ra_syntax/src/grammar.ron | 3 +-- 4 files changed, 3 insertions(+), 8 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 970b89825..c2ab19d97 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -17,7 +17,7 @@ pub use self::{ generated::*, traits::*, tokens::*, - extensions::{PathSegmentKind, StructKind, SelfParamKind}, + extensions::{PathSegmentKind, StructKind,FieldKind, SelfParamKind}, expr_extensions::{ElseBranch, PrefixOp, BinOp, LiteralKind,ArrayExprKind}, }; diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index d21ec80c3..9484c3b9b 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -203,7 +203,7 @@ impl ast::ArrayExpr { if self.is_repeat() { ArrayExprKind::Repeat { initializer: children(self).nth(0), - repeat: children(self).nth(2), + repeat: children(self).nth(1), } } else { ArrayExprKind::ElementList(children(self)) diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 39b760551..0376c91c8 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs @@ -108,10 +108,6 @@ impl ArrayExpr { pub fn exprs(&self) -> impl Iterator { super::children(self) } - - pub fn repeat(&self) -> Option<&Expr> { - super::child_opt(self) - } } // ArrayType diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index c7116c69b..0a35e25d5 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron @@ -395,8 +395,7 @@ Grammar( collections: [["exprs", "Expr"]] ), "ArrayExpr": ( - collections: [["exprs", "Expr"]], - options:[["repeat","Expr"]] + collections: [["exprs", "Expr"]] ), "ParenExpr": (options: ["Expr"]), "PathExpr": (options: ["Path"]), -- cgit v1.2.3