2018-08-04 13:58:22 +00:00
|
|
|
use super::*;
|
|
|
|
|
|
|
|
// test expr_literals
|
|
|
|
// fn foo() {
|
|
|
|
// let _ = true;
|
|
|
|
// let _ = false;
|
|
|
|
// let _ = 1;
|
|
|
|
// let _ = 2.0;
|
|
|
|
// let _ = b'a';
|
|
|
|
// let _ = 'b';
|
|
|
|
// let _ = "c";
|
|
|
|
// let _ = r"d";
|
|
|
|
// let _ = b"e";
|
|
|
|
// let _ = br"f";
|
|
|
|
// }
|
2018-10-15 21:44:23 +00:00
|
|
|
pub(crate) const LITERAL_FIRST: TokenSet = token_set![
|
|
|
|
TRUE_KW,
|
|
|
|
FALSE_KW,
|
|
|
|
INT_NUMBER,
|
|
|
|
FLOAT_NUMBER,
|
|
|
|
BYTE,
|
|
|
|
CHAR,
|
|
|
|
STRING,
|
|
|
|
RAW_STRING,
|
|
|
|
BYTE_STRING,
|
|
|
|
RAW_BYTE_STRING
|
|
|
|
];
|
2018-08-04 13:58:22 +00:00
|
|
|
|
|
|
|
pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
2018-09-08 07:38:53 +00:00
|
|
|
if !p.at_ts(LITERAL_FIRST) {
|
2018-08-04 13:58:22 +00:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
|
|
|
Some(m.complete(p, LITERAL))
|
|
|
|
}
|
|
|
|
|
2018-12-20 11:35:02 +00:00
|
|
|
// E.g. for after the break in `if break {}`, this should not match
|
2019-01-24 22:01:49 +00:00
|
|
|
pub(super) const ATOM_EXPR_FIRST: TokenSet =
|
|
|
|
LITERAL_FIRST.union(paths::PATH_FIRST).union(token_set![
|
|
|
|
L_PAREN,
|
|
|
|
L_CURLY,
|
|
|
|
L_BRACK,
|
|
|
|
PIPE,
|
|
|
|
MOVE_KW,
|
|
|
|
IF_KW,
|
|
|
|
WHILE_KW,
|
|
|
|
MATCH_KW,
|
|
|
|
UNSAFE_KW,
|
|
|
|
RETURN_KW,
|
|
|
|
BREAK_KW,
|
|
|
|
CONTINUE_KW,
|
|
|
|
LIFETIME,
|
2019-04-01 10:58:36 +00:00
|
|
|
ASYNC_KW,
|
2019-06-06 11:36:16 +00:00
|
|
|
TRY_KW,
|
2019-01-24 22:01:49 +00:00
|
|
|
]);
|
2018-08-04 13:58:22 +00:00
|
|
|
|
2018-10-15 21:44:23 +00:00
|
|
|
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
|
2018-08-28 08:12:42 +00:00
|
|
|
|
2018-12-19 20:55:24 +00:00
|
|
|
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
|
2018-10-16 15:51:58 +00:00
|
|
|
if let Some(m) = literal(p) {
|
2018-12-19 20:55:24 +00:00
|
|
|
return Some((m, BlockLike::NotBlock));
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
if paths::is_path_start(p) || p.at(T![<]) {
|
2018-12-19 20:55:24 +00:00
|
|
|
return Some(path_expr(p, r));
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
let la = p.nth(1);
|
|
|
|
let done = match p.current() {
|
2019-05-15 12:35:47 +00:00
|
|
|
T!['('] => tuple_expr(p),
|
|
|
|
T!['['] => array_expr(p),
|
|
|
|
T![|] => lambda_expr(p),
|
|
|
|
T![move] if la == T![|] => lambda_expr(p),
|
|
|
|
T![async] if la == T![|] || (la == T![move] && p.nth(2) == T![|]) => lambda_expr(p),
|
|
|
|
T![if] => if_expr(p),
|
2018-08-24 08:45:14 +00:00
|
|
|
|
2019-05-15 12:35:47 +00:00
|
|
|
T![loop] => loop_expr(p, None),
|
2019-06-18 15:50:57 +00:00
|
|
|
T![box] => box_expr(p, None),
|
2019-05-15 12:35:47 +00:00
|
|
|
T![for] => for_expr(p, None),
|
|
|
|
T![while] => while_expr(p, None),
|
2019-06-06 12:26:54 +00:00
|
|
|
T![try] => try_block_expr(p, None),
|
2019-05-15 12:35:47 +00:00
|
|
|
LIFETIME if la == T![:] => {
|
2018-08-24 08:45:14 +00:00
|
|
|
let m = p.start();
|
|
|
|
label(p);
|
|
|
|
match p.current() {
|
2019-05-15 12:35:47 +00:00
|
|
|
T![loop] => loop_expr(p, Some(m)),
|
|
|
|
T![for] => for_expr(p, Some(m)),
|
|
|
|
T![while] => while_expr(p, Some(m)),
|
|
|
|
T!['{'] => block_expr(p, Some(m)),
|
2018-08-24 08:45:14 +00:00
|
|
|
_ => {
|
2018-12-20 16:45:54 +00:00
|
|
|
// test_err misplaced_label_err
|
2018-09-08 06:18:42 +00:00
|
|
|
// fn main() {
|
|
|
|
// 'loop: impl
|
|
|
|
// }
|
2018-08-24 08:45:14 +00:00
|
|
|
p.error("expected a loop");
|
2018-09-08 06:18:42 +00:00
|
|
|
m.complete(p, ERROR);
|
2018-12-19 20:55:24 +00:00
|
|
|
return None;
|
2018-08-24 08:45:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
T![async] if la == T!['{'] || (la == T![move] && p.nth(2) == T!['{']) => {
|
2019-03-09 23:40:22 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
2019-05-15 12:35:47 +00:00
|
|
|
p.eat(T![move]);
|
2019-03-09 23:40:22 +00:00
|
|
|
block_expr(p, Some(m))
|
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
T![match] => match_expr(p),
|
|
|
|
T![unsafe] if la == T!['{'] => {
|
2018-09-08 06:18:42 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
|
|
|
block_expr(p, Some(m))
|
2018-10-15 21:44:23 +00:00
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
T!['{'] => block_expr(p, None),
|
|
|
|
T![return] => return_expr(p),
|
|
|
|
T![continue] => continue_expr(p),
|
|
|
|
T![break] => break_expr(p, r),
|
2018-08-04 13:58:22 +00:00
|
|
|
_ => {
|
2018-08-28 08:12:42 +00:00
|
|
|
p.err_recover("expected expression", EXPR_RECOVERY_SET);
|
2018-12-19 20:55:24 +00:00
|
|
|
return None;
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
};
|
2018-12-19 20:55:24 +00:00
|
|
|
let blocklike = match done.kind() {
|
2019-06-06 12:26:54 +00:00
|
|
|
IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR | TRY_BLOCK_EXPR => {
|
|
|
|
BlockLike::Block
|
|
|
|
}
|
2018-12-19 20:55:24 +00:00
|
|
|
_ => BlockLike::NotBlock,
|
|
|
|
};
|
|
|
|
Some((done, blocklike))
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 14:19:03 +00:00
|
|
|
// test tuple_expr
|
|
|
|
// fn foo() {
|
|
|
|
// ();
|
|
|
|
// (1);
|
|
|
|
// (1,);
|
|
|
|
// }
|
2018-08-04 13:58:22 +00:00
|
|
|
fn tuple_expr(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T!['(']));
|
2018-08-04 13:58:22 +00:00
|
|
|
let m = p.start();
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T!['(']);
|
2018-08-05 14:19:03 +00:00
|
|
|
|
|
|
|
let mut saw_comma = false;
|
|
|
|
let mut saw_expr = false;
|
2019-05-15 12:35:47 +00:00
|
|
|
while !p.at(EOF) && !p.at(T![')']) {
|
2018-08-05 14:19:03 +00:00
|
|
|
saw_expr = true;
|
2018-09-08 07:38:53 +00:00
|
|
|
if !p.at_ts(EXPR_FIRST) {
|
2018-09-08 07:35:05 +00:00
|
|
|
p.error("expected expression");
|
|
|
|
break;
|
|
|
|
}
|
2018-08-05 14:19:03 +00:00
|
|
|
expr(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
if !p.at(T![')']) {
|
2018-08-05 14:19:03 +00:00
|
|
|
saw_comma = true;
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![,]);
|
2018-08-05 14:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![')']);
|
2019-02-08 11:49:43 +00:00
|
|
|
m.complete(p, if saw_expr && !saw_comma { PAREN_EXPR } else { TUPLE_EXPR })
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 15:24:56 +00:00
|
|
|
// test array_expr
|
|
|
|
// fn foo() {
|
|
|
|
// [];
|
|
|
|
// [1];
|
|
|
|
// [1, 2,];
|
|
|
|
// [1; 2];
|
|
|
|
// }
|
|
|
|
fn array_expr(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T!['[']));
|
2018-08-05 15:24:56 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.eat(T![']']) {
|
2018-08-05 15:24:56 +00:00
|
|
|
return m.complete(p, ARRAY_EXPR);
|
|
|
|
}
|
2019-06-30 07:59:26 +00:00
|
|
|
|
|
|
|
// test first_array_member_attributes
|
|
|
|
// pub const A: &[i64] = &[
|
|
|
|
// #[cfg(test)]
|
|
|
|
// 1,
|
|
|
|
// 2,
|
|
|
|
// ];
|
|
|
|
attributes::outer_attributes(p);
|
|
|
|
|
2018-08-05 15:24:56 +00:00
|
|
|
expr(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.eat(T![;]) {
|
2018-08-05 15:24:56 +00:00
|
|
|
expr(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![']']);
|
2018-08-05 15:24:56 +00:00
|
|
|
return m.complete(p, ARRAY_EXPR);
|
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
while !p.at(EOF) && !p.at(T![']']) {
|
|
|
|
p.expect(T![,]);
|
|
|
|
if p.at(T![']']) {
|
2018-09-08 07:13:32 +00:00
|
|
|
break;
|
2018-08-05 15:24:56 +00:00
|
|
|
}
|
2019-06-30 07:59:26 +00:00
|
|
|
|
|
|
|
// test subsequent_array_member_attributes
|
|
|
|
// pub const A: &[i64] = &[
|
|
|
|
// 1,
|
|
|
|
// #[cfg(test)]
|
|
|
|
// 2,
|
|
|
|
// ];
|
|
|
|
attributes::outer_attributes(p);
|
2018-09-08 07:38:53 +00:00
|
|
|
if !p.at_ts(EXPR_FIRST) {
|
2018-09-08 07:13:32 +00:00
|
|
|
p.error("expected expression");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
expr(p);
|
2018-08-05 15:24:56 +00:00
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![']']);
|
2018-08-05 15:24:56 +00:00
|
|
|
m.complete(p, ARRAY_EXPR)
|
|
|
|
}
|
|
|
|
|
2018-08-04 13:58:22 +00:00
|
|
|
// test lambda_expr
|
|
|
|
// fn foo() {
|
|
|
|
// || ();
|
|
|
|
// || -> i32 { 92 };
|
|
|
|
// |x| x;
|
|
|
|
// move |x: i32,| x;
|
2019-03-31 14:35:22 +00:00
|
|
|
// async || {};
|
|
|
|
// move || {};
|
|
|
|
// async move || {};
|
2018-08-04 13:58:22 +00:00
|
|
|
// }
|
|
|
|
fn lambda_expr(p: &mut Parser) -> CompletedMarker {
|
2019-03-31 14:35:22 +00:00
|
|
|
assert!(
|
2019-05-15 12:35:47 +00:00
|
|
|
p.at(T![|])
|
|
|
|
|| (p.at(T![move]) && p.nth(1) == T![|])
|
|
|
|
|| (p.at(T![async]) && p.nth(1) == T![|])
|
|
|
|
|| (p.at(T![async]) && p.nth(1) == T![move] && p.nth(2) == T![|])
|
2019-03-31 14:35:22 +00:00
|
|
|
);
|
2018-08-04 13:58:22 +00:00
|
|
|
let m = p.start();
|
2019-05-15 12:35:47 +00:00
|
|
|
p.eat(T![async]);
|
|
|
|
p.eat(T![move]);
|
2018-08-04 13:58:22 +00:00
|
|
|
params::param_list_opt_types(p);
|
2018-08-23 23:14:10 +00:00
|
|
|
if opt_fn_ret_type(p) {
|
2019-05-15 12:35:47 +00:00
|
|
|
if !p.at(T!['{']) {
|
2018-08-28 20:59:57 +00:00
|
|
|
p.error("expected `{`");
|
|
|
|
}
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
2018-08-28 20:59:57 +00:00
|
|
|
expr(p);
|
2018-08-04 13:58:22 +00:00
|
|
|
m.complete(p, LAMBDA_EXPR)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test if_expr
|
|
|
|
// fn foo() {
|
|
|
|
// if true {};
|
|
|
|
// if true {} else {};
|
2018-08-04 14:12:00 +00:00
|
|
|
// if true {} else if false {} else {};
|
|
|
|
// if S {};
|
2018-08-04 13:58:22 +00:00
|
|
|
// }
|
|
|
|
fn if_expr(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![if]));
|
2018-08-04 13:58:22 +00:00
|
|
|
let m = p.start();
|
2018-08-04 22:03:22 +00:00
|
|
|
p.bump();
|
|
|
|
cond(p);
|
2018-08-04 13:58:22 +00:00
|
|
|
block(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.at(T![else]) {
|
2018-08-04 13:58:22 +00:00
|
|
|
p.bump();
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.at(T![if]) {
|
2018-08-04 13:58:22 +00:00
|
|
|
if_expr(p);
|
|
|
|
} else {
|
|
|
|
block(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m.complete(p, IF_EXPR)
|
|
|
|
}
|
|
|
|
|
2018-08-24 08:45:14 +00:00
|
|
|
// test label
|
2018-08-04 22:03:22 +00:00
|
|
|
// fn foo() {
|
2018-08-24 08:45:14 +00:00
|
|
|
// 'a: loop {}
|
|
|
|
// 'b: while true {}
|
|
|
|
// 'c: for x in () {}
|
2018-08-04 22:03:22 +00:00
|
|
|
// }
|
2018-08-24 08:45:14 +00:00
|
|
|
fn label(p: &mut Parser) {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(LIFETIME) && p.nth(1) == T![:]);
|
2018-08-04 22:03:22 +00:00
|
|
|
let m = p.start();
|
2018-08-04 13:58:22 +00:00
|
|
|
p.bump();
|
2018-08-24 08:45:14 +00:00
|
|
|
p.bump();
|
|
|
|
m.complete(p, LABEL);
|
2018-08-04 22:03:22 +00:00
|
|
|
}
|
|
|
|
|
2018-08-05 15:16:52 +00:00
|
|
|
// test loop_expr
|
|
|
|
// fn foo() {
|
|
|
|
// loop {};
|
|
|
|
// }
|
2018-08-24 08:45:14 +00:00
|
|
|
fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![loop]));
|
2018-08-24 08:45:14 +00:00
|
|
|
let m = m.unwrap_or_else(|| p.start());
|
2018-08-05 15:16:52 +00:00
|
|
|
p.bump();
|
|
|
|
block(p);
|
|
|
|
m.complete(p, LOOP_EXPR)
|
|
|
|
}
|
|
|
|
|
2018-08-24 08:45:14 +00:00
|
|
|
// test while_expr
|
|
|
|
// fn foo() {
|
|
|
|
// while true {};
|
|
|
|
// while let Some(x) = it.next() {};
|
|
|
|
// }
|
|
|
|
fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![while]));
|
2018-08-24 08:45:14 +00:00
|
|
|
let m = m.unwrap_or_else(|| p.start());
|
|
|
|
p.bump();
|
|
|
|
cond(p);
|
|
|
|
block(p);
|
|
|
|
m.complete(p, WHILE_EXPR)
|
|
|
|
}
|
|
|
|
|
2018-08-05 15:24:56 +00:00
|
|
|
// test for_expr
|
|
|
|
// fn foo() {
|
|
|
|
// for x in [] {};
|
|
|
|
// }
|
2018-08-24 08:45:14 +00:00
|
|
|
fn for_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![for]));
|
2018-08-24 08:45:14 +00:00
|
|
|
let m = m.unwrap_or_else(|| p.start());
|
2018-08-05 15:24:56 +00:00
|
|
|
p.bump();
|
|
|
|
patterns::pattern(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![in]);
|
2018-08-05 15:24:56 +00:00
|
|
|
expr_no_struct(p);
|
|
|
|
block(p);
|
|
|
|
m.complete(p, FOR_EXPR)
|
|
|
|
}
|
|
|
|
|
2018-08-04 22:03:22 +00:00
|
|
|
// test cond
|
|
|
|
// fn foo() { if let Some(_) = None {} }
|
2019-03-04 17:10:14 +00:00
|
|
|
// fn bar() {
|
|
|
|
// if let Some(_) | Some(_) = None {}
|
|
|
|
// if let | Some(_) = None {}
|
|
|
|
// while let Some(_) | Some(_) = None {}
|
|
|
|
// while let | Some(_) = None {}
|
|
|
|
// }
|
2018-08-04 22:03:22 +00:00
|
|
|
fn cond(p: &mut Parser) {
|
2018-08-27 09:22:09 +00:00
|
|
|
let m = p.start();
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.eat(T![let]) {
|
2019-03-05 09:28:53 +00:00
|
|
|
patterns::pattern_list(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![=]);
|
2018-08-04 22:03:22 +00:00
|
|
|
}
|
2018-08-27 09:22:09 +00:00
|
|
|
expr_no_struct(p);
|
|
|
|
m.complete(p, CONDITION);
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test match_expr
|
|
|
|
// fn foo() {
|
|
|
|
// match () { };
|
2018-08-04 14:12:00 +00:00
|
|
|
// match S {};
|
2018-08-04 13:58:22 +00:00
|
|
|
// }
|
|
|
|
fn match_expr(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![match]));
|
2018-08-04 13:58:22 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
2018-08-04 14:12:00 +00:00
|
|
|
expr_no_struct(p);
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.at(T!['{']) {
|
2018-08-24 16:27:30 +00:00
|
|
|
match_arm_list(p);
|
|
|
|
} else {
|
|
|
|
p.error("expected `{`")
|
|
|
|
}
|
|
|
|
m.complete(p, MATCH_EXPR)
|
|
|
|
}
|
|
|
|
|
2018-09-10 18:14:09 +00:00
|
|
|
pub(crate) fn match_arm_list(p: &mut Parser) {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T!['{']));
|
2018-08-24 16:27:30 +00:00
|
|
|
let m = p.start();
|
2019-05-15 12:35:47 +00:00
|
|
|
p.eat(T!['{']);
|
2019-02-17 17:08:34 +00:00
|
|
|
|
|
|
|
// test match_arms_inner_attribute
|
|
|
|
// fn foo() {
|
|
|
|
// match () {
|
|
|
|
// #![doc("Inner attribute")]
|
|
|
|
// #![doc("Can be")]
|
|
|
|
// #![doc("Stacked")]
|
|
|
|
// _ => (),
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
attributes::inner_attributes(p);
|
|
|
|
|
2019-05-15 12:35:47 +00:00
|
|
|
while !p.at(EOF) && !p.at(T!['}']) {
|
|
|
|
if p.at(T!['{']) {
|
2018-08-27 18:10:02 +00:00
|
|
|
error_block(p, "expected match arm");
|
|
|
|
continue;
|
|
|
|
}
|
2019-02-17 17:08:34 +00:00
|
|
|
|
2018-08-07 13:32:09 +00:00
|
|
|
// test match_arms_commas
|
|
|
|
// fn foo() {
|
|
|
|
// match () {
|
|
|
|
// _ => (),
|
|
|
|
// _ => {}
|
|
|
|
// _ => ()
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if match_arm(p).is_block() {
|
2019-05-15 12:35:47 +00:00
|
|
|
p.eat(T![,]);
|
|
|
|
} else if !p.at(T!['}']) {
|
|
|
|
p.expect(T![,]);
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T!['}']);
|
2018-08-24 16:27:30 +00:00
|
|
|
m.complete(p, MATCH_ARM_LIST);
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// test match_arm
|
|
|
|
// fn foo() {
|
|
|
|
// match () {
|
|
|
|
// _ => (),
|
2018-12-20 16:45:54 +00:00
|
|
|
// _ if Test > Test{field: 0} => (),
|
2018-08-04 13:58:22 +00:00
|
|
|
// X | Y if Z => (),
|
2018-10-03 20:47:03 +00:00
|
|
|
// | X | Y if Z => (),
|
|
|
|
// | X => (),
|
2018-08-04 13:58:22 +00:00
|
|
|
// };
|
|
|
|
// }
|
2018-08-07 13:32:09 +00:00
|
|
|
fn match_arm(p: &mut Parser) -> BlockLike {
|
2018-08-04 13:58:22 +00:00
|
|
|
let m = p.start();
|
2019-03-17 11:57:27 +00:00
|
|
|
// test match_arms_outer_attributes
|
|
|
|
// fn foo() {
|
|
|
|
// match () {
|
|
|
|
// #[cfg(feature = "some")]
|
|
|
|
// _ => (),
|
|
|
|
// #[cfg(feature = "other")]
|
|
|
|
// _ => (),
|
|
|
|
// #[cfg(feature = "many")]
|
|
|
|
// #[cfg(feature = "attributes")]
|
|
|
|
// #[cfg(feature = "before")]
|
|
|
|
// _ => (),
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
attributes::outer_attributes(p);
|
|
|
|
|
2019-03-05 09:28:53 +00:00
|
|
|
patterns::pattern_list_r(p, TokenSet::empty());
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.at(T![if]) {
|
2019-01-28 22:06:11 +00:00
|
|
|
match_guard(p);
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
2019-05-15 12:35:47 +00:00
|
|
|
p.expect(T![=>]);
|
2019-03-19 08:24:02 +00:00
|
|
|
let blocklike = expr_stmt(p).1;
|
2018-08-04 13:58:22 +00:00
|
|
|
m.complete(p, MATCH_ARM);
|
2019-03-19 08:24:02 +00:00
|
|
|
blocklike
|
2018-08-04 13:58:22 +00:00
|
|
|
}
|
|
|
|
|
2019-01-28 22:06:11 +00:00
|
|
|
// test match_guard
|
|
|
|
// fn foo() {
|
|
|
|
// match () {
|
|
|
|
// _ if foo => (),
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
fn match_guard(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![if]));
|
2019-01-28 22:06:11 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
|
|
|
expr(p);
|
|
|
|
m.complete(p, MATCH_GUARD)
|
|
|
|
}
|
|
|
|
|
2018-08-04 13:58:22 +00:00
|
|
|
// test block_expr
|
|
|
|
// fn foo() {
|
|
|
|
// {};
|
|
|
|
// unsafe {};
|
2018-09-08 06:18:42 +00:00
|
|
|
// 'label: {};
|
2018-08-04 13:58:22 +00:00
|
|
|
// }
|
2018-09-08 06:18:42 +00:00
|
|
|
fn block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T!['{']));
|
2018-09-08 06:18:42 +00:00
|
|
|
let m = m.unwrap_or_else(|| p.start());
|
2018-08-24 16:27:30 +00:00
|
|
|
block(p);
|
2018-08-04 13:58:22 +00:00
|
|
|
m.complete(p, BLOCK_EXPR)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test return_expr
|
|
|
|
// fn foo() {
|
|
|
|
// return;
|
|
|
|
// return 92;
|
|
|
|
// }
|
|
|
|
fn return_expr(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![return]));
|
2018-08-04 13:58:22 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
2018-09-08 07:38:53 +00:00
|
|
|
if p.at_ts(EXPR_FIRST) {
|
2018-08-04 13:58:22 +00:00
|
|
|
expr(p);
|
|
|
|
}
|
|
|
|
m.complete(p, RETURN_EXPR)
|
|
|
|
}
|
2018-08-24 08:21:13 +00:00
|
|
|
|
|
|
|
// test continue_expr
|
|
|
|
// fn foo() {
|
|
|
|
// loop {
|
|
|
|
// continue;
|
|
|
|
// continue 'l;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
fn continue_expr(p: &mut Parser) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![continue]));
|
2018-08-24 08:21:13 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
|
|
|
p.eat(LIFETIME);
|
|
|
|
m.complete(p, CONTINUE_EXPR)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test break_expr
|
|
|
|
// fn foo() {
|
|
|
|
// loop {
|
|
|
|
// break;
|
|
|
|
// break 'l;
|
|
|
|
// break 92;
|
|
|
|
// break 'l 92;
|
|
|
|
// }
|
|
|
|
// }
|
2018-12-20 11:35:02 +00:00
|
|
|
fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
|
2019-05-15 12:35:47 +00:00
|
|
|
assert!(p.at(T![break]));
|
2018-08-24 08:21:13 +00:00
|
|
|
let m = p.start();
|
|
|
|
p.bump();
|
|
|
|
p.eat(LIFETIME);
|
2018-12-20 11:35:02 +00:00
|
|
|
// test break_ambiguity
|
|
|
|
// fn foo(){
|
|
|
|
// if break {}
|
|
|
|
// while break {}
|
|
|
|
// for i in break {}
|
|
|
|
// match break {}
|
|
|
|
// }
|
2019-05-15 12:35:47 +00:00
|
|
|
if p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(T!['{'])) {
|
2018-08-24 08:21:13 +00:00
|
|
|
expr(p);
|
|
|
|
}
|
|
|
|
m.complete(p, BREAK_EXPR)
|
|
|
|
}
|
2019-06-06 11:36:16 +00:00
|
|
|
|
2019-06-06 12:26:54 +00:00
|
|
|
// test try_block_expr
|
2019-06-06 11:36:16 +00:00
|
|
|
// fn foo() {
|
2019-06-06 12:26:54 +00:00
|
|
|
// let _ = try {};
|
2019-06-06 11:36:16 +00:00
|
|
|
// }
|
2019-06-06 12:26:54 +00:00
|
|
|
fn try_block_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
2019-06-06 11:36:16 +00:00
|
|
|
assert!(p.at(T![try]));
|
|
|
|
let m = m.unwrap_or_else(|| p.start());
|
|
|
|
p.bump();
|
|
|
|
block(p);
|
|
|
|
m.complete(p, TRY_EXPR)
|
|
|
|
}
|
2019-06-18 15:50:57 +00:00
|
|
|
|
|
|
|
// test box_expr
|
|
|
|
// fn foo() {
|
|
|
|
// let x = box 1i32;
|
|
|
|
// }
|
|
|
|
fn box_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
|
|
|
|
assert!(p.at(T![box]));
|
|
|
|
let m = m.unwrap_or_else(|| p.start());
|
|
|
|
p.bump();
|
|
|
|
if p.at_ts(EXPR_FIRST) {
|
|
|
|
expr(p);
|
|
|
|
}
|
|
|
|
m.complete(p, BOX_EXPR)
|
|
|
|
}
|