Added ArrayExprKind,

changed the  display for fixed array types,
Added Array Enum to ra_hir/expr
This commit is contained in:
Lenard Pratt
2019-04-04 23:29:21 +01:00
parent 2d73c909fe
commit e175921932
5 changed files with 76 additions and 31 deletions

View File

@@ -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

View File

@@ -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,