Rename LambdaExpr -> ClosureExpr

This commit is contained in:
Aleksey Kladov 2020-07-31 17:08:58 +02:00
parent bfcee63e75
commit 633aace411
19 changed files with 59 additions and 54 deletions

View file

@ -1,7 +1,7 @@
use ra_syntax::{
ast::{self, AstNode},
SyntaxKind::{
BLOCK_EXPR, BREAK_EXPR, COMMENT, LAMBDA_EXPR, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
BLOCK_EXPR, BREAK_EXPR, CLOSURE_EXPR, COMMENT, LOOP_EXPR, MATCH_ARM, PATH_EXPR, RETURN_EXPR,
},
SyntaxNode,
};
@ -148,7 +148,7 @@ impl Anchor {
}
if let Some(parent) = node.parent() {
if parent.kind() == MATCH_ARM || parent.kind() == LAMBDA_EXPR {
if parent.kind() == MATCH_ARM || parent.kind() == CLOSURE_EXPR {
return Some(Anchor::WrapInBlock(node));
}
}

View file

@ -473,7 +473,7 @@ impl ExprCollector<'_> {
self.alloc_expr(Expr::Missing, syntax_ptr)
}
}
ast::Expr::LambdaExpr(e) => {
ast::Expr::ClosureExpr(e) => {
let mut args = Vec::new();
let mut arg_types = Vec::new();
if let Some(pl) = e.param_list() {

View file

@ -379,7 +379,7 @@ fn to_fragment_kind(db: &dyn AstDatabase, id: MacroCallId) -> FragmentKind {
FOR_EXPR => FragmentKind::Expr,
PATH_EXPR => FragmentKind::Expr,
LAMBDA_EXPR => FragmentKind::Expr,
CLOSURE_EXPR => FragmentKind::Expr,
CONDITION => FragmentKind::Expr,
BREAK_EXPR => FragmentKind::Expr,
RETURN_EXPR => FragmentKind::Expr,

View file

@ -134,7 +134,7 @@ pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {
NodeOrToken::Token(token) => token.parent(),
};
for node in leaf.ancestors() {
if node.kind() == FN || node.kind() == LAMBDA_EXPR {
if node.kind() == FN || node.kind() == CLOSURE_EXPR {
break;
}
let loop_body = match_ast! {

View file

@ -250,7 +250,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
p.error("expected expression");
}
}
m.complete(p, LAMBDA_EXPR)
m.complete(p, CLOSURE_EXPR)
}
// test if_expr

View file

@ -173,7 +173,7 @@ pub enum SyntaxKind {
ARRAY_EXPR,
PAREN_EXPR,
PATH_EXPR,
LAMBDA_EXPR,
CLOSURE_EXPR,
IF_EXPR,
WHILE_EXPR,
CONDITION,

View file

@ -582,9 +582,7 @@ pub struct BinExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for BinExpr {}
impl BinExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
}
impl BinExpr {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BoxExpr {
pub(crate) syntax: SyntaxNode,
@ -680,9 +678,7 @@ impl ast::AttrsOwner for IfExpr {}
impl IfExpr {
pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) }
pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) }
pub fn else_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![else]) }
pub fn if_expr(&self) -> Option<IfExpr> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct IndexExpr {
@ -690,7 +686,6 @@ pub struct IndexExpr {
}
impl ast::AttrsOwner for IndexExpr {}
impl IndexExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) }
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
}
@ -704,11 +699,11 @@ impl Label {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LambdaExpr {
pub struct ClosureExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for LambdaExpr {}
impl LambdaExpr {
impl ast::AttrsOwner for ClosureExpr {}
impl ClosureExpr {
pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
@ -778,9 +773,7 @@ pub struct RangeExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for RangeExpr {}
impl RangeExpr {
pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) }
}
impl RangeExpr {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RecordExpr {
pub(crate) syntax: SyntaxNode,
@ -1351,7 +1344,7 @@ pub enum Expr {
IfExpr(IfExpr),
IndexExpr(IndexExpr),
Label(Label),
LambdaExpr(LambdaExpr),
ClosureExpr(ClosureExpr),
Literal(Literal),
LoopExpr(LoopExpr),
MacroCall(MacroCall),
@ -2101,8 +2094,8 @@ impl AstNode for Label {
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for LambdaExpr {
fn can_cast(kind: SyntaxKind) -> bool { kind == LAMBDA_EXPR }
impl AstNode for ClosureExpr {
fn can_cast(kind: SyntaxKind) -> bool { kind == CLOSURE_EXPR }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
@ -3114,8 +3107,8 @@ impl From<IndexExpr> for Expr {
impl From<Label> for Expr {
fn from(node: Label) -> Expr { Expr::Label(node) }
}
impl From<LambdaExpr> for Expr {
fn from(node: LambdaExpr) -> Expr { Expr::LambdaExpr(node) }
impl From<ClosureExpr> for Expr {
fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) }
}
impl From<Literal> for Expr {
fn from(node: Literal) -> Expr { Expr::Literal(node) }
@ -3167,7 +3160,7 @@ impl AstNode for Expr {
match kind {
ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR
| CAST_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR | IF_EXPR
| INDEX_EXPR | LABEL | LAMBDA_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR
| INDEX_EXPR | LABEL | CLOSURE_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR
| METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR
| RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true,
_ => false,
@ -3190,7 +3183,7 @@ impl AstNode for Expr {
IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
LABEL => Expr::Label(Label { syntax }),
LAMBDA_EXPR => Expr::LambdaExpr(LambdaExpr { syntax }),
CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }),
LITERAL => Expr::Literal(Literal { syntax }),
LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
@ -3227,7 +3220,7 @@ impl AstNode for Expr {
Expr::IfExpr(it) => &it.syntax,
Expr::IndexExpr(it) => &it.syntax,
Expr::Label(it) => &it.syntax,
Expr::LambdaExpr(it) => &it.syntax,
Expr::ClosureExpr(it) => &it.syntax,
Expr::Literal(it) => &it.syntax,
Expr::LoopExpr(it) => &it.syntax,
Expr::MacroCall(it) => &it.syntax,
@ -3757,7 +3750,7 @@ impl std::fmt::Display for Label {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for LambdaExpr {
impl std::fmt::Display for ClosureExpr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}

View file

@ -12,7 +12,7 @@ SOURCE_FILE@0..42
L_CURLY@10..11 "{"
WHITESPACE@11..16 "\n "
EXPR_STMT@16..24
LAMBDA_EXPR@16..24
CLOSURE_EXPR@16..24
PARAM_LIST@16..18
PIPE@16..17 "|"
PIPE@17..18 "|"

View file

@ -117,7 +117,7 @@ SOURCE_FILE@0..389
WHITESPACE@140..141
EQ@141..142
WHITESPACE@142..143
LAMBDA_EXPR@143..389
CLOSURE_EXPR@143..389
PARAM_LIST@143..388
PIPE@143..144
PARAM@144..159

View file

@ -49,7 +49,7 @@ SOURCE_FILE@0..83
IDENT@48..51 "map"
ARG_LIST@51..57
L_PAREN@51..52 "("
LAMBDA_EXPR@52..56
CLOSURE_EXPR@52..56
PARAM_LIST@52..56
PIPE@52..53 "|"
PARAM@53..55

View file

@ -12,7 +12,7 @@ SOURCE_FILE@0..134
L_CURLY@9..10 "{"
WHITESPACE@10..15 "\n "
EXPR_STMT@15..21
LAMBDA_EXPR@15..20
CLOSURE_EXPR@15..20
PARAM_LIST@15..17
PIPE@15..16 "|"
PIPE@16..17 "|"
@ -23,7 +23,7 @@ SOURCE_FILE@0..134
SEMICOLON@20..21 ";"
WHITESPACE@21..26 "\n "
EXPR_STMT@26..43
LAMBDA_EXPR@26..42
CLOSURE_EXPR@26..42
PARAM_LIST@26..28
PIPE@26..27 "|"
PIPE@27..28 "|"
@ -47,7 +47,7 @@ SOURCE_FILE@0..134
SEMICOLON@42..43 ";"
WHITESPACE@43..48 "\n "
EXPR_STMT@48..54
LAMBDA_EXPR@48..53
CLOSURE_EXPR@48..53
PARAM_LIST@48..51
PIPE@48..49 "|"
PARAM@49..50
@ -64,7 +64,7 @@ SOURCE_FILE@0..134
SEMICOLON@53..54 ";"
WHITESPACE@54..59 "\n "
EXPR_STMT@59..76
LAMBDA_EXPR@59..75
CLOSURE_EXPR@59..75
MOVE_KW@59..63 "move"
WHITESPACE@63..64 " "
PARAM_LIST@64..73
@ -91,7 +91,7 @@ SOURCE_FILE@0..134
SEMICOLON@75..76 ";"
WHITESPACE@76..81 "\n "
EXPR_STMT@81..93
LAMBDA_EXPR@81..92
CLOSURE_EXPR@81..92
ASYNC_KW@81..86 "async"
WHITESPACE@86..87 " "
PARAM_LIST@87..89
@ -104,7 +104,7 @@ SOURCE_FILE@0..134
SEMICOLON@92..93 ";"
WHITESPACE@93..98 "\n "
EXPR_STMT@98..109
LAMBDA_EXPR@98..108
CLOSURE_EXPR@98..108
MOVE_KW@98..102 "move"
WHITESPACE@102..103 " "
PARAM_LIST@103..105
@ -117,7 +117,7 @@ SOURCE_FILE@0..134
SEMICOLON@108..109 ";"
WHITESPACE@109..114 "\n "
EXPR_STMT@114..131
LAMBDA_EXPR@114..130
CLOSURE_EXPR@114..130
ASYNC_KW@114..119 "async"
WHITESPACE@119..120 " "
MOVE_KW@120..124 "move"

View file

@ -105,7 +105,7 @@ SOURCE_FILE@0..135
WHITESPACE@117..118 " "
EQ@118..119 "="
WHITESPACE@119..120 " "
LAMBDA_EXPR@120..131
CLOSURE_EXPR@120..131
ATTR@120..127
POUND@120..121 "#"
L_BRACK@121..122 "["

View file

@ -20,7 +20,7 @@ SOURCE_FILE@0..63
WHITESPACE@22..23 " "
EQ@23..24 "="
WHITESPACE@24..25 " "
LAMBDA_EXPR@25..59
CLOSURE_EXPR@25..59
PARAM_LIST@25..56
PIPE@25..26 "|"
PARAM@26..29

View file

@ -13,7 +13,7 @@ SOURCE_FILE@0..34
WHITESPACE@11..12 " "
EXPR_STMT@12..31
CALL_EXPR@12..30
LAMBDA_EXPR@12..28
CLOSURE_EXPR@12..28
PARAM_LIST@12..14
PIPE@12..13 "|"
PIPE@13..14 "|"

View file

@ -351,7 +351,7 @@ SOURCE_FILE@0..3813
WHITESPACE@766..767 " "
BLOCK_EXPR@767..777
L_CURLY@767..768 "{"
LAMBDA_EXPR@768..776
CLOSURE_EXPR@768..776
PARAM_LIST@768..770
PIPE@768..769 "|"
PIPE@769..770 "|"
@ -1628,7 +1628,7 @@ SOURCE_FILE@0..3813
CALL_EXPR@2950..2995
PAREN_EXPR@2950..2971
L_PAREN@2950..2951 "("
LAMBDA_EXPR@2951..2970
CLOSURE_EXPR@2951..2970
PARAM_LIST@2951..2968
PIPE@2951..2952 "|"
PARAM@2952..2962

View file

@ -52,7 +52,7 @@ SOURCE_FILE@0..166
IDENT@134..146 "catch_unwind"
ARG_LIST@146..162
L_PAREN@146..147 "("
LAMBDA_EXPR@147..161
CLOSURE_EXPR@147..161
MOVE_KW@147..151 "move"
WHITESPACE@151..152 " "
PARAM_LIST@152..154

View file

@ -144,7 +144,7 @@ pub(crate) const KINDS_SRC: KindsSrc = KindsSrc {
"ARRAY_EXPR",
"PAREN_EXPR",
"PATH_EXPR",
"LAMBDA_EXPR",
"CLOSURE_EXPR",
"IF_EXPR",
"WHILE_EXPR",
"CONDITION",

View file

@ -579,7 +579,19 @@ fn lower_rule(acc: &mut Vec<Field>, grammar: &Grammar, label: Option<&String>, r
}
Rule::Labeled { label: l, rule } => {
assert!(label.is_none());
if l == "op" {
let manually_implemented = matches!(
l.as_str(),
"lhs"
| "rhs"
| "then_branch"
| "else_branch"
| "start"
| "end"
| "op"
| "index"
| "base"
);
if manually_implemented {
return;
}
lower_rule(acc, grammar, Some(l), rule);

View file

@ -222,7 +222,7 @@ Expr =
| IfExpr
| IndexExpr
| Label
| LambdaExpr
| ClosureExpr
| Literal
| LoopExpr
| MacroCall
@ -266,14 +266,14 @@ PrefixExpr =
BinExpr =
Attr*
Expr
lhs:Expr
op:(
'||' | '&&'
| '==' | '!=' | '<=' | '>=' | '<' | '>'
| '+' | '*' | '-' | '/' | '%' | '<<' | '>>' | '^' | '|' | '&'
| '=' | '+=' | '/=' | '*=' | '%=' | '>>=' | '<<=' | '-=' | '|=' | '&=' | '^='
)
Expr
rhs:Expr
CastExpr =
Attr* Expr 'as' Type
@ -288,7 +288,7 @@ ArrayExpr =
) ']'
IndexExpr =
Attr* Expr '[' Expr ']'
Attr* base:Expr '[' index:Expr ']'
TupleExpr =
Attr* '(' Attr* (Expr (',' Expr)* ','?)? ')'
@ -318,13 +318,13 @@ MethodCallExpr =
FieldExpr =
Attr* Expr '.' NameRef
LambdaExpr =
ClosureExpr =
Attr* 'static'? 'async'? 'move'? ParamList RetType?
body:Expr
IfExpr =
Attr* 'if' Condition BlockExpr
('else' (IfExpr | BlockExpr))?
Attr* 'if' Condition then_branch:BlockExpr
('else' else_branch:(IfExpr | BlockExpr))?
Condition =
'let' Pat '=' Expr
@ -352,7 +352,7 @@ ContinueExpr =
Attr* 'continue' 'lifetime'?
RangeExpr =
Attr* Expr? op:('..' | '..=') Expr?
Attr* start:Expr? op:('..' | '..=') end:Expr?
MatchExpr =
Attr* 'match' Expr MatchArmList