273: Add a test to ensure that we can parse each file r=matklad a=DJMcNab

Note that this has a non-spurious failure in ra_analysis/src/mock_analysis.

Probably fixes #195.

If my understanding is correct, fixes #214 and fixes #225.

Co-authored-by: DJMcNab <36049421+djmcnab@users.noreply.github.com>
This commit is contained in:
bors[bot] 2018-12-19 21:22:00 +00:00
commit ef1e107df1
14 changed files with 496 additions and 234 deletions

View File

@ -64,6 +64,20 @@ pub(crate) fn block(p: &mut Parser) {
if p.at(R_CURLY) {
m.abandon(p);
} else {
// test no_semi_after_block
// fn foo() {
// if true {}
// loop {}
// match () {}
// while true {}
// for _ in () {}
// {}
// {}
// macro_rules! test {
// () => {}
// }
// test!{}
// }
if is_blocklike {
p.eat(SEMI);
} else {
@ -143,7 +157,7 @@ fn current_op(p: &Parser) -> (u8, Op) {
let bp = match p.current() {
EQ => 1,
DOTDOT => 2,
DOTDOT | DOTDOTEQ => 2,
EQEQ | NEQ | L_ANGLE | R_ANGLE => 5,
PIPE => 6,
CARET => 7,
@ -158,13 +172,13 @@ fn current_op(p: &Parser) -> (u8, Op) {
// Parses expression with binding power of at least bp.
fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike {
let mut lhs = match lhs(p, r) {
Some(lhs) => {
Some((lhs, blocklike)) => {
// test stmt_bin_expr_ambiguity
// fn foo() {
// let _ = {1} & 2;
// {1} &2;
// }
if r.prefer_stmt && is_block(lhs.kind()) {
if r.prefer_stmt && blocklike.is_block() {
return BlockLike::Block;
}
lhs
@ -173,7 +187,7 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike {
};
loop {
let is_range = p.current() == DOTDOT;
let is_range = p.current() == DOTDOT || p.current() == DOTDOTEQ;
let (op_bp, op) = current_op(p);
if op_bp < bp {
break;
@ -191,29 +205,12 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike {
BlockLike::NotBlock
}
// test no_semi_after_block
// fn foo() {
// if true {}
// loop {}
// match () {}
// while true {}
// for _ in () {}
// {}
// {}
// }
fn is_block(kind: SyntaxKind) -> bool {
match kind {
IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR => true,
_ => false,
}
}
const LHS_FIRST: TokenSet = token_set_union![
token_set![AMP, STAR, EXCL, DOTDOT, MINUS],
atom::ATOM_EXPR_FIRST,
];
fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
let m;
let kind = match p.current() {
// test ref_expr
@ -246,19 +243,28 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
if p.at_ts(EXPR_FIRST) {
expr_bp(p, r, 2);
}
return Some(m.complete(p, RANGE_EXPR));
return Some((m.complete(p, RANGE_EXPR), BlockLike::NotBlock));
}
_ => {
let lhs = atom::atom_expr(p, r)?;
return Some(postfix_expr(p, r, lhs));
let (lhs, blocklike) = atom::atom_expr(p, r)?;
return Some((
postfix_expr(p, lhs, !(r.prefer_stmt && blocklike.is_block())),
blocklike,
));
}
};
expr_bp(p, r, 255);
Some(m.complete(p, kind))
Some((m.complete(p, kind), BlockLike::NotBlock))
}
fn postfix_expr(p: &mut Parser, r: Restrictions, mut lhs: CompletedMarker) -> CompletedMarker {
let mut allow_calls = !r.prefer_stmt || !is_block(lhs.kind());
fn postfix_expr(
p: &mut Parser,
mut lhs: CompletedMarker,
// Calls are disallowed if the type is a block and we prefer statements because the call cannot be disambiguated from a tuple
// E.g. `while true {break}();` is parsed as
// `while true {break}; ();`
mut allow_calls: bool,
) -> CompletedMarker {
loop {
lhs = match p.current() {
// test stmt_postfix_expr_ambiguity
@ -406,20 +412,20 @@ fn arg_list(p: &mut Parser) {
// let _ = ::a::<b>;
// let _ = format!();
// }
fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) {
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
let m = p.start();
paths::expr_path(p);
match p.current() {
L_CURLY if !r.forbid_structs => {
named_field_list(p);
m.complete(p, STRUCT_LIT)
(m.complete(p, STRUCT_LIT), BlockLike::Block)
}
EXCL => {
items::macro_call_after_excl(p);
m.complete(p, MACRO_CALL)
let block_like = items::macro_call_after_excl(p);
return (m.complete(p, MACRO_CALL), block_like);
}
_ => m.complete(p, PATH_EXPR),
_ => (m.complete(p, PATH_EXPR), BlockLike::NotBlock),
}
}

View File

@ -61,9 +61,9 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)> {
if let Some(m) = literal(p) {
return Some(m);
return Some((m, BlockLike::NotBlock));
}
if paths::is_path_start(p) || p.at(L_ANGLE) {
return Some(path_expr(p, r));
@ -114,7 +114,11 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMark
return None;
}
};
Some(done)
let blocklike = match done.kind() {
IF_EXPR | WHILE_EXPR | FOR_EXPR | LOOP_EXPR | MATCH_EXPR | BLOCK_EXPR => BlockLike::Block,
_ => BlockLike::NotBlock,
};
Some((done, blocklike))
}
// test tuple_expr
@ -349,6 +353,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
// fn foo() {
// match () {
// _ => (),
// _ if Test>{field: 0} => (),
// X | Y if Z => (),
// | X | Y if Z => (),
// | X => (),
@ -362,7 +367,7 @@ fn match_arm(p: &mut Parser) -> BlockLike {
patterns::pattern(p);
}
if p.eat(IF_KW) {
expr_no_struct(p);
expr(p);
}
p.expect(FAT_ARROW);
let ret = expr_stmt(p);

View File

@ -14,9 +14,13 @@ pub(super) fn pattern_r(p: &mut Parser, recovery_set: TokenSet) {
if let Some(lhs) = atom_pat(p, recovery_set) {
// test range_pat
// fn main() {
// match 92 { 0 ... 100 => () }
// match 92 {
// 0 ... 100 => (),
// 101 ..= 200 => (),
// 200 .. 301=> (),
// }
// }
if p.at(DOTDOTDOT) {
if p.at(DOTDOTDOT) || p.at(DOTDOTEQ) || p.at(DOTDOT) {
let m = lhs.precede(p);
p.bump();
atom_pat(p, recovery_set);

View File

@ -36,7 +36,7 @@ pub(crate) fn at(&self, kind: SyntaxKind) -> bool {
self.current() == kind
}
/// Checks if the current token is `kind`.
/// Checks if the current token is in `kinds`.
pub(crate) fn at_ts(&self, kinds: TokenSet) -> bool {
kinds.contains(self.current())
}

View File

@ -1,6 +1,7 @@
fn foo() {
match () {
_ => (),
_ if Test>{field: 0} => (),
X | Y if Z => (),
| X | Y if Z => (),
| X => (),

View File

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 125)
FN_DEF@[0; 124)
SOURCE_FILE@[0; 161)
FN_DEF@[0; 160)
FN_KW@[0; 2)
WHITESPACE@[2; 3)
NAME@[3; 6)
@ -8,18 +8,18 @@ SOURCE_FILE@[0; 125)
L_PAREN@[6; 7)
R_PAREN@[7; 8)
WHITESPACE@[8; 9)
BLOCK@[9; 124)
BLOCK@[9; 160)
L_CURLY@[9; 10)
WHITESPACE@[10; 15)
EXPR_STMT@[15; 122)
MATCH_EXPR@[15; 121)
EXPR_STMT@[15; 158)
MATCH_EXPR@[15; 157)
MATCH_KW@[15; 20)
WHITESPACE@[20; 21)
TUPLE_EXPR@[21; 23)
L_PAREN@[21; 22)
R_PAREN@[22; 23)
WHITESPACE@[23; 24)
MATCH_ARM_LIST@[24; 121)
MATCH_ARM_LIST@[24; 157)
L_CURLY@[24; 25)
WHITESPACE@[25; 34)
MATCH_ARM@[34; 41)
@ -33,76 +33,116 @@ SOURCE_FILE@[0; 125)
R_PAREN@[40; 41)
COMMA@[41; 42)
WHITESPACE@[42; 51)
MATCH_ARM@[51; 67)
BIND_PAT@[51; 52)
NAME@[51; 52)
IDENT@[51; 52) "X"
MATCH_ARM@[51; 77)
PLACEHOLDER_PAT@[51; 52)
UNDERSCORE@[51; 52)
WHITESPACE@[52; 53)
PIPE@[53; 54)
WHITESPACE@[54; 55)
BIND_PAT@[55; 56)
NAME@[55; 56)
IDENT@[55; 56) "Y"
WHITESPACE@[56; 57)
IF_KW@[57; 59)
WHITESPACE@[59; 60)
PATH_EXPR@[60; 61)
PATH@[60; 61)
PATH_SEGMENT@[60; 61)
NAME_REF@[60; 61)
IDENT@[60; 61) "Z"
WHITESPACE@[61; 62)
FAT_ARROW@[62; 64)
WHITESPACE@[64; 65)
TUPLE_EXPR@[65; 67)
L_PAREN@[65; 66)
R_PAREN@[66; 67)
COMMA@[67; 68)
WHITESPACE@[68; 77)
MATCH_ARM@[77; 95)
PIPE@[77; 78)
WHITESPACE@[78; 79)
BIND_PAT@[79; 80)
NAME@[79; 80)
IDENT@[79; 80) "X"
WHITESPACE@[80; 81)
PIPE@[81; 82)
WHITESPACE@[82; 83)
BIND_PAT@[83; 84)
NAME@[83; 84)
IDENT@[83; 84) "Y"
WHITESPACE@[84; 85)
IF_KW@[85; 87)
WHITESPACE@[87; 88)
PATH_EXPR@[88; 89)
PATH@[88; 89)
PATH_SEGMENT@[88; 89)
NAME_REF@[88; 89)
IDENT@[88; 89) "Z"
WHITESPACE@[89; 90)
FAT_ARROW@[90; 92)
IF_KW@[53; 55)
WHITESPACE@[55; 56)
BIN_EXPR@[56; 71)
PATH_EXPR@[56; 60)
PATH@[56; 60)
PATH_SEGMENT@[56; 60)
NAME_REF@[56; 60)
IDENT@[56; 60) "Test"
R_ANGLE@[60; 61)
BLOCK_EXPR@[61; 71)
BLOCK@[61; 71)
L_CURLY@[61; 62)
EXPR_STMT@[62; 67)
PATH_EXPR@[62; 67)
PATH@[62; 67)
PATH_SEGMENT@[62; 67)
NAME_REF@[62; 67)
IDENT@[62; 67) "field"
err: `expected SEMI`
err: `expected expression`
EXPR_STMT@[67; 68)
ERROR@[67; 68)
COLON@[67; 68)
err: `expected SEMI`
WHITESPACE@[68; 69)
LITERAL@[69; 70)
INT_NUMBER@[69; 70) "0"
R_CURLY@[70; 71)
WHITESPACE@[71; 72)
FAT_ARROW@[72; 74)
WHITESPACE@[74; 75)
TUPLE_EXPR@[75; 77)
L_PAREN@[75; 76)
R_PAREN@[76; 77)
COMMA@[77; 78)
WHITESPACE@[78; 87)
MATCH_ARM@[87; 103)
BIND_PAT@[87; 88)
NAME@[87; 88)
IDENT@[87; 88) "X"
WHITESPACE@[88; 89)
PIPE@[89; 90)
WHITESPACE@[90; 91)
BIND_PAT@[91; 92)
NAME@[91; 92)
IDENT@[91; 92) "Y"
WHITESPACE@[92; 93)
TUPLE_EXPR@[93; 95)
L_PAREN@[93; 94)
R_PAREN@[94; 95)
COMMA@[95; 96)
WHITESPACE@[96; 105)
MATCH_ARM@[105; 114)
PIPE@[105; 106)
WHITESPACE@[106; 107)
BIND_PAT@[107; 108)
NAME@[107; 108)
IDENT@[107; 108) "X"
WHITESPACE@[108; 109)
FAT_ARROW@[109; 111)
WHITESPACE@[111; 112)
TUPLE_EXPR@[112; 114)
L_PAREN@[112; 113)
R_PAREN@[113; 114)
COMMA@[114; 115)
WHITESPACE@[115; 120)
R_CURLY@[120; 121)
SEMI@[121; 122)
WHITESPACE@[122; 123)
R_CURLY@[123; 124)
WHITESPACE@[124; 125)
IF_KW@[93; 95)
WHITESPACE@[95; 96)
PATH_EXPR@[96; 97)
PATH@[96; 97)
PATH_SEGMENT@[96; 97)
NAME_REF@[96; 97)
IDENT@[96; 97) "Z"
WHITESPACE@[97; 98)
FAT_ARROW@[98; 100)
WHITESPACE@[100; 101)
TUPLE_EXPR@[101; 103)
L_PAREN@[101; 102)
R_PAREN@[102; 103)
COMMA@[103; 104)
WHITESPACE@[104; 113)
MATCH_ARM@[113; 131)
PIPE@[113; 114)
WHITESPACE@[114; 115)
BIND_PAT@[115; 116)
NAME@[115; 116)
IDENT@[115; 116) "X"
WHITESPACE@[116; 117)
PIPE@[117; 118)
WHITESPACE@[118; 119)
BIND_PAT@[119; 120)
NAME@[119; 120)
IDENT@[119; 120) "Y"
WHITESPACE@[120; 121)
IF_KW@[121; 123)
WHITESPACE@[123; 124)
PATH_EXPR@[124; 125)
PATH@[124; 125)
PATH_SEGMENT@[124; 125)
NAME_REF@[124; 125)
IDENT@[124; 125) "Z"
WHITESPACE@[125; 126)
FAT_ARROW@[126; 128)
WHITESPACE@[128; 129)
TUPLE_EXPR@[129; 131)
L_PAREN@[129; 130)
R_PAREN@[130; 131)
COMMA@[131; 132)
WHITESPACE@[132; 141)
MATCH_ARM@[141; 150)
PIPE@[141; 142)
WHITESPACE@[142; 143)
BIND_PAT@[143; 144)
NAME@[143; 144)
IDENT@[143; 144) "X"
WHITESPACE@[144; 145)
FAT_ARROW@[145; 147)
WHITESPACE@[147; 148)
TUPLE_EXPR@[148; 150)
L_PAREN@[148; 149)
R_PAREN@[149; 150)
COMMA@[150; 151)
WHITESPACE@[151; 156)
R_CURLY@[156; 157)
SEMI@[157; 158)
WHITESPACE@[158; 159)
R_CURLY@[159; 160)
WHITESPACE@[160; 161)

View File

@ -6,4 +6,8 @@ fn foo() {
for _ in () {}
{}
{}
macro_rules! test {
() => {}
}
test!{}
}

View File

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 107)
FN_DEF@[0; 106)
SOURCE_FILE@[0; 167)
FN_DEF@[0; 166)
FN_KW@[0; 2)
WHITESPACE@[2; 3)
NAME@[3; 6)
@ -8,7 +8,7 @@ SOURCE_FILE@[0; 107)
L_PAREN@[6; 7)
R_PAREN@[7; 8)
WHITESPACE@[8; 9)
BLOCK@[9; 106)
BLOCK@[9; 166)
L_CURLY@[9; 10)
WHITESPACE@[10; 15)
EXPR_STMT@[15; 25)
@ -78,10 +78,46 @@ SOURCE_FILE@[0; 107)
L_CURLY@[95; 96)
R_CURLY@[96; 97)
WHITESPACE@[97; 102)
BLOCK_EXPR@[102; 104)
BLOCK@[102; 104)
L_CURLY@[102; 103)
R_CURLY@[103; 104)
WHITESPACE@[104; 105)
R_CURLY@[105; 106)
WHITESPACE@[106; 107)
EXPR_STMT@[102; 104)
BLOCK_EXPR@[102; 104)
BLOCK@[102; 104)
L_CURLY@[102; 103)
R_CURLY@[103; 104)
WHITESPACE@[104; 109)
EXPR_STMT@[109; 152)
MACRO_CALL@[109; 152)
PATH@[109; 120)
PATH_SEGMENT@[109; 120)
NAME_REF@[109; 120)
IDENT@[109; 120) "macro_rules"
EXCL@[120; 121)
WHITESPACE@[121; 122)
IDENT@[122; 126) "test"
WHITESPACE@[126; 127)
TOKEN_TREE@[127; 152)
L_CURLY@[127; 128)
WHITESPACE@[128; 138)
TOKEN_TREE@[138; 140)
L_PAREN@[138; 139)
R_PAREN@[139; 140)
WHITESPACE@[140; 141)
FAT_ARROW@[141; 143)
WHITESPACE@[143; 144)
TOKEN_TREE@[144; 146)
L_CURLY@[144; 145)
R_CURLY@[145; 146)
WHITESPACE@[146; 151)
R_CURLY@[151; 152)
WHITESPACE@[152; 157)
MACRO_CALL@[157; 164)
PATH@[157; 161)
PATH_SEGMENT@[157; 161)
NAME_REF@[157; 161)
IDENT@[157; 161) "test"
EXCL@[161; 162)
TOKEN_TREE@[162; 164)
L_CURLY@[162; 163)
R_CURLY@[163; 164)
WHITESPACE@[164; 165)
R_CURLY@[165; 166)
WHITESPACE@[166; 167)

View File

@ -1,3 +1,7 @@
fn main() {
match 92 { 0 ... 100 => () }
match 92 {
0 ... 100 => (),
101 ..= 200 => (),
200 .. 301=> (),
}
}

View File

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 47)
FN_DEF@[0; 46)
SOURCE_FILE@[0; 112)
FN_DEF@[0; 111)
FN_KW@[0; 2)
WHITESPACE@[2; 3)
NAME@[3; 7)
@ -8,35 +8,69 @@ SOURCE_FILE@[0; 47)
L_PAREN@[7; 8)
R_PAREN@[8; 9)
WHITESPACE@[9; 10)
BLOCK@[10; 46)
BLOCK@[10; 111)
L_CURLY@[10; 11)
WHITESPACE@[11; 16)
MATCH_EXPR@[16; 44)
MATCH_EXPR@[16; 109)
MATCH_KW@[16; 21)
WHITESPACE@[21; 22)
LITERAL@[22; 24)
INT_NUMBER@[22; 24) "92"
WHITESPACE@[24; 25)
MATCH_ARM_LIST@[25; 44)
MATCH_ARM_LIST@[25; 109)
L_CURLY@[25; 26)
WHITESPACE@[26; 27)
MATCH_ARM@[27; 42)
RANGE_PAT@[27; 36)
LITERAL@[27; 28)
INT_NUMBER@[27; 28) "0"
WHITESPACE@[28; 29)
DOTDOTDOT@[29; 32)
WHITESPACE@[32; 33)
LITERAL@[33; 36)
INT_NUMBER@[33; 36) "100"
WHITESPACE@[36; 37)
FAT_ARROW@[37; 39)
WHITESPACE@[39; 40)
TUPLE_EXPR@[40; 42)
L_PAREN@[40; 41)
R_PAREN@[41; 42)
WHITESPACE@[42; 43)
R_CURLY@[43; 44)
WHITESPACE@[44; 45)
R_CURLY@[45; 46)
WHITESPACE@[46; 47)
WHITESPACE@[26; 35)
MATCH_ARM@[35; 50)
RANGE_PAT@[35; 44)
LITERAL@[35; 36)
INT_NUMBER@[35; 36) "0"
WHITESPACE@[36; 37)
DOTDOTDOT@[37; 40)
WHITESPACE@[40; 41)
LITERAL@[41; 44)
INT_NUMBER@[41; 44) "100"
WHITESPACE@[44; 45)
FAT_ARROW@[45; 47)
WHITESPACE@[47; 48)
TUPLE_EXPR@[48; 50)
L_PAREN@[48; 49)
R_PAREN@[49; 50)
COMMA@[50; 51)
WHITESPACE@[51; 60)
MATCH_ARM@[60; 77)
RANGE_PAT@[60; 71)
LITERAL@[60; 63)
INT_NUMBER@[60; 63) "101"
WHITESPACE@[63; 64)
DOTDOTEQ@[64; 67)
WHITESPACE@[67; 68)
LITERAL@[68; 71)
INT_NUMBER@[68; 71) "200"
WHITESPACE@[71; 72)
FAT_ARROW@[72; 74)
WHITESPACE@[74; 75)
TUPLE_EXPR@[75; 77)
L_PAREN@[75; 76)
R_PAREN@[76; 77)
COMMA@[77; 78)
WHITESPACE@[78; 87)
MATCH_ARM@[87; 102)
RANGE_PAT@[87; 97)
LITERAL@[87; 90)
INT_NUMBER@[87; 90) "200"
WHITESPACE@[90; 91)
DOTDOT@[91; 93)
WHITESPACE@[93; 94)
LITERAL@[94; 97)
INT_NUMBER@[94; 97) "301"
FAT_ARROW@[97; 99)
WHITESPACE@[99; 100)
TUPLE_EXPR@[100; 102)
L_PAREN@[100; 101)
R_PAREN@[101; 102)
COMMA@[102; 103)
WHITESPACE@[103; 108)
R_CURLY@[108; 109)
WHITESPACE@[109; 110)
R_CURLY@[110; 111)
WHITESPACE@[111; 112)

View File

@ -3,4 +3,9 @@ fn foo() {
..z = 2;
x = false..1 == 1;
let x = 1..;
..=1 + 1;
..=z = 2;
x = false..=1 == 1;
let x = 1..;
}

View File

@ -1,5 +1,5 @@
SOURCE_FILE@[0; 79)
FN_DEF@[0; 78)
SOURCE_FILE@[0; 153)
FN_DEF@[0; 152)
FN_KW@[0; 2)
WHITESPACE@[2; 3)
NAME@[3; 6)
@ -8,7 +8,7 @@ SOURCE_FILE@[0; 79)
L_PAREN@[6; 7)
R_PAREN@[7; 8)
WHITESPACE@[8; 9)
BLOCK@[9; 78)
BLOCK@[9; 152)
L_CURLY@[9; 10)
WHITESPACE@[10; 15)
EXPR_STMT@[15; 23)
@ -78,6 +78,80 @@ SOURCE_FILE@[0; 79)
INT_NUMBER@[72; 73) "1"
DOTDOT@[73; 75)
SEMI@[75; 76)
WHITESPACE@[76; 77)
R_CURLY@[77; 78)
WHITESPACE@[78; 79)
WHITESPACE@[76; 86)
err: `expected expression`
EXPR_STMT@[86; 89)
ERROR@[86; 89)
DOTDOTEQ@[86; 89)
err: `expected SEMI`
EXPR_STMT@[89; 95)
BIN_EXPR@[89; 94)
LITERAL@[89; 90)
INT_NUMBER@[89; 90) "1"
WHITESPACE@[90; 91)
PLUS@[91; 92)
WHITESPACE@[92; 93)
LITERAL@[93; 94)
INT_NUMBER@[93; 94) "1"
SEMI@[94; 95)
WHITESPACE@[95; 100)
err: `expected expression`
EXPR_STMT@[100; 103)
ERROR@[100; 103)
DOTDOTEQ@[100; 103)
err: `expected SEMI`
EXPR_STMT@[103; 109)
BIN_EXPR@[103; 108)
PATH_EXPR@[103; 104)
PATH@[103; 104)
PATH_SEGMENT@[103; 104)
NAME_REF@[103; 104)
IDENT@[103; 104) "z"
WHITESPACE@[104; 105)
EQ@[105; 106)
WHITESPACE@[106; 107)
LITERAL@[107; 108)
INT_NUMBER@[107; 108) "2"
SEMI@[108; 109)
WHITESPACE@[109; 114)
EXPR_STMT@[114; 133)
BIN_EXPR@[114; 132)
PATH_EXPR@[114; 115)
PATH@[114; 115)
PATH_SEGMENT@[114; 115)
NAME_REF@[114; 115)
IDENT@[114; 115) "x"
WHITESPACE@[115; 116)
EQ@[116; 117)
WHITESPACE@[117; 118)
RANGE_EXPR@[118; 132)
LITERAL@[118; 123)
FALSE_KW@[118; 123)
DOTDOTEQ@[123; 126)
BIN_EXPR@[126; 132)
LITERAL@[126; 127)
INT_NUMBER@[126; 127) "1"
WHITESPACE@[127; 128)
EQEQ@[128; 130)
WHITESPACE@[130; 131)
LITERAL@[131; 132)
INT_NUMBER@[131; 132) "1"
SEMI@[132; 133)
WHITESPACE@[133; 138)
LET_STMT@[138; 150)
LET_KW@[138; 141)
WHITESPACE@[141; 142)
BIND_PAT@[142; 143)
NAME@[142; 143)
IDENT@[142; 143) "x"
WHITESPACE@[143; 144)
EQ@[144; 145)
WHITESPACE@[145; 146)
RANGE_EXPR@[146; 149)
LITERAL@[146; 147)
INT_NUMBER@[146; 147) "1"
DOTDOT@[147; 149)
SEMI@[149; 150)
WHITESPACE@[150; 151)
R_CURLY@[151; 152)
WHITESPACE@[152; 153)

View File

@ -6,7 +6,7 @@
use std::{
fmt::Write,
fs,
path::{Path, PathBuf},
path::{Path, PathBuf, Component},
};
use ra_syntax::{
@ -37,6 +37,47 @@ fn parser_fuzz_tests() {
}
}
/// Test that Rust-analyzer can parse and validate the rust-analyser
/// TODO: Use this as a benchmark
#[test]
fn self_hosting_parsing() {
use std::ffi::OsStr;
let empty_vec = vec![];
let dir = project_dir().join("crates");
let mut count = 0;
for entry in walkdir::WalkDir::new(dir)
.into_iter()
.filter_entry(|entry| {
!entry
.path()
.components()
// TODO: this more neatly
.any(|component| {
// Get all files which are not in the crates/ra_syntax/tests/data folder
component == Component::Normal(OsStr::new("data"))
})
})
.map(|e| e.unwrap())
.filter(|entry| {
// Get all `.rs ` files
!entry.path().is_dir() && (entry.path().extension() == Some(OsStr::new("rs")))
})
{
count += 1;
let text = read_text(entry.path());
let node = SourceFileNode::parse(&text);
let errors = node.errors();
assert_eq!(
errors, empty_vec,
"There should be no errors in the file {:?}",
entry
);
}
assert!(
count > 30,
"self_hosting_parsing found too few files - is it running in the right directory?"
)
}
/// Read file and normalize newlines.
///
/// `rustc` seems to always normalize `\r\n` newlines to `\n`:
@ -49,7 +90,9 @@ fn parser_fuzz_tests() {
///
/// so this should always be correct.
fn read_text(path: &Path) -> String {
fs::read_to_string(path).unwrap().replace("\r\n", "\n")
fs::read_to_string(path)
.expect(&format!("File at {:?} should be valid", path))
.replace("\r\n", "\n")
}
pub fn dir_tests<F>(paths: &[&str], f: F)

View File

@ -17,9 +17,9 @@
"dev": true
},
"ajv": {
"version": "6.6.1",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.1.tgz",
"integrity": "sha512-ZoJjft5B+EJBjUyu9C9Hc0OZyPZSSlOF+plzouTrg6UlA8f+e/n8NIgBFG/9tppJtpPWfthHakK7juJdNDODww==",
"version": "6.6.2",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.6.2.tgz",
"integrity": "sha512-FBHEW6Jf5TB9MGBgUUA9XHkTbjXYfAUjY43ACMfmdMRHniyoMHjHjzD50OK8LGDWQwp4rWEsIq5kEqq7rvIM1g==",
"dev": true,
"requires": {
"fast-deep-equal": "2.0.1",
@ -193,12 +193,6 @@
"strip-ansi": "3.0.1",
"supports-color": "2.0.0"
}
},
"supports-color": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
}
}
},
@ -298,12 +292,6 @@
"color-convert": "1.9.3"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
@ -409,9 +397,9 @@
}
},
"commander": {
"version": "2.18.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.18.0.tgz",
"integrity": "sha512-6CYPa+JP2ftfRU2qkDK+UTVeQYosOg/2GbcjIcKPHfinyOLPVGXu/ovN86RP49Re5ndJK1N0kuiidFFuepc4ZQ==",
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.19.0.tgz",
"integrity": "sha512-6tvAOO+D6OENvRAh524Dh9jcfKTYDQAqvqezbCW82xj5X0pSrcpxtvRKHLG0yBY6SD7PSDrJaj+0AiOcKVd1Xg==",
"dev": true
},
"concat-map": {
@ -437,7 +425,7 @@
},
"css-select": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz",
"resolved": "http://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz",
"integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=",
"dev": true,
"requires": {
@ -473,7 +461,7 @@
},
"deep-assign": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/deep-assign/-/deep-assign-1.0.0.tgz",
"resolved": "http://registry.npmjs.org/deep-assign/-/deep-assign-1.0.0.tgz",
"integrity": "sha1-sJJ0O+hCfcYh6gBnzex+cN0Z83s=",
"dev": true,
"requires": {
@ -502,9 +490,9 @@
"dev": true
},
"diff": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz",
"integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==",
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==",
"dev": true
},
"dom-serializer": {
@ -519,7 +507,7 @@
"dependencies": {
"domelementtype": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz",
"resolved": "http://registry.npmjs.org/domelementtype/-/domelementtype-1.1.3.tgz",
"integrity": "sha1-vSh3PiZCiBrsUVRJJCmcXNgiGFs=",
"dev": true
}
@ -928,13 +916,13 @@
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"dev": true
},
"through2": {
"version": "0.6.5",
"resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz",
"resolved": "http://registry.npmjs.org/through2/-/through2-0.6.5.tgz",
"integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=",
"dev": true,
"requires": {
@ -1078,7 +1066,7 @@
"integrity": "sha512-sNvOCzEQNr/qrvJgc3UG/kD4QtlHycrzwS+6mfTrrSq97BvaYcPZZI1ZSqGSPR73Cxn4LKTD4PttRwfU7jWq5g==",
"dev": true,
"requires": {
"ajv": "6.6.1",
"ajv": "6.6.2",
"har-schema": "2.0.0"
}
},
@ -1101,9 +1089,9 @@
}
},
"has-flag": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"has-symbols": {
@ -1129,7 +1117,7 @@
"domutils": "1.5.1",
"entities": "1.1.2",
"inherits": "2.0.3",
"readable-stream": "3.0.6"
"readable-stream": "3.1.0"
}
},
"http-signature": {
@ -1160,9 +1148,9 @@
"dev": true
},
"is": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/is/-/is-3.2.1.tgz",
"integrity": "sha1-0Kwq1V63sL7JJqUmb2xmKqqD3KU=",
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz",
"integrity": "sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg==",
"dev": true
},
"is-absolute": {
@ -1331,7 +1319,7 @@
},
"kind-of": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz",
"resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz",
"integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=",
"dev": true
},
@ -1488,6 +1476,12 @@
"integrity": "sha512-b0553uYA5YAEGgyYIGYROzKQ7X5RAqedkfjiZxwi0kL1g3bOaBNNZfYkzt/CL0umgD5wc9Jec2FbB98CjkMRvQ==",
"dev": true
},
"diff": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.3.1.tgz",
"integrity": "sha512-MKPHZDMB0o6yHyDryUOScqZibp914ksXwAMYMTHj6KO8UeKsRYNJD3oNCKjTqZon+V488P7N/HzXF8t7ZR95ww==",
"dev": true
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
@ -1501,6 +1495,21 @@
"once": "1.4.0",
"path-is-absolute": "1.0.1"
}
},
"has-flag": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-2.0.0.tgz",
"integrity": "sha1-6CB68cx7MNRGzHC3NLXovhj4jVE=",
"dev": true
},
"supports-color": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
"integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
"dev": true,
"requires": {
"has-flag": "2.0.0"
}
}
}
},
@ -1535,7 +1544,7 @@
"dev": true,
"requires": {
"has": "1.0.3",
"is": "3.2.1"
"is": "3.3.0"
}
},
"normalize-path": {
@ -1635,13 +1644,13 @@
},
"os-homedir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
"resolved": "http://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz",
"integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=",
"dev": true
},
"os-tmpdir": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"resolved": "http://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
"integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=",
"dev": true
},
@ -1657,11 +1666,11 @@
},
"parse-semver": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/parse-semver/-/parse-semver-1.1.1.tgz",
"resolved": "http://registry.npmjs.org/parse-semver/-/parse-semver-1.1.1.tgz",
"integrity": "sha1-mkr9bfBj3Egm+T+6SpnPIj9mbLg=",
"dev": true,
"requires": {
"semver": "5.5.1"
"semver": "5.6.0"
}
},
"parse5": {
@ -1681,7 +1690,7 @@
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
"dev": true
},
@ -1738,9 +1747,9 @@
"dev": true
},
"psl": {
"version": "1.1.29",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.29.tgz",
"integrity": "sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==",
"version": "1.1.31",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz",
"integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==",
"dev": true
},
"pump": {
@ -1807,9 +1816,9 @@
}
},
"readable-stream": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.0.6.tgz",
"integrity": "sha512-9E1oLoOWfhSXHGv6QlwXJim7uNzd9EVlWK+21tCU9Ju/kR0/p2AZYPz4qSchgO8PlLIH4FpZYfzwS+rEksZjIg==",
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.1.0.tgz",
"integrity": "sha512-vpydAvIJvPODZNagCPuHG87O9JNPtvFEtjHHRVwNVsVVRBqemvPJkc2SYbxJsiZXawJdtZNmkmnsPuE3IgsG0A==",
"dev": true,
"requires": {
"inherits": "2.0.3",
@ -1885,9 +1894,9 @@
"dev": true
},
"resolve": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz",
"integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==",
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.9.0.tgz",
"integrity": "sha512-TZNye00tI67lwYvzxCxHGjwTNlUV70io54/Ed4j6PscB8xVfuBJpRenI/o6dVk0cY0PYTY27AgCoGGxRnYuItQ==",
"dev": true,
"requires": {
"path-parse": "1.0.6"
@ -1924,9 +1933,9 @@
"dev": true
},
"semver": {
"version": "5.5.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz",
"integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw=="
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg=="
},
"source-map": {
"version": "0.6.1",
@ -1955,7 +1964,7 @@
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"resolved": "http://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
},
@ -2057,17 +2066,14 @@
}
},
"supports-color": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz",
"integrity": "sha512-rKC3+DyXWgK0ZLKwmRsrkyHVZAjNkfzeehuFWdGGcqGDTZFH73+RH6S/RDAAxl9GusSjZSUWYLmT9N5pzXFOXQ==",
"dev": true,
"requires": {
"has-flag": "2.0.0"
}
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
},
"tar": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
"resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz",
"integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=",
"dev": true,
"requires": {
@ -2162,7 +2168,7 @@
"integrity": "sha512-Q5srk/4vDM54WJsJio3XNn6K2sCG+CQ8G5Wz6bZhRZoAe/+TxjWB/GlFAnYEbkYVlON9FMk/fE3h2RLpPXo4lQ==",
"dev": true,
"requires": {
"psl": "1.1.29",
"psl": "1.1.31",
"punycode": "1.4.1"
},
"dependencies": {
@ -2189,13 +2195,13 @@
"babel-code-frame": "6.26.0",
"builtin-modules": "1.1.1",
"chalk": "2.4.1",
"commander": "2.18.0",
"diff": "3.3.1",
"commander": "2.19.0",
"diff": "3.5.0",
"glob": "7.1.3",
"js-yaml": "3.12.0",
"minimatch": "3.0.4",
"resolve": "1.8.1",
"semver": "5.5.1",
"resolve": "1.9.0",
"semver": "5.6.0",
"tslib": "1.9.3",
"tsutils": "2.29.0"
}
@ -2248,7 +2254,7 @@
"dependencies": {
"underscore": {
"version": "1.8.3",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
"resolved": "http://registry.npmjs.org/underscore/-/underscore-1.8.3.tgz",
"integrity": "sha1-Tz+1OxBuYJf8+ctBCfKl6b36UCI=",
"dev": true
}
@ -2489,7 +2495,7 @@
"dev": true,
"requires": {
"cheerio": "1.0.0-rc.2",
"commander": "2.18.0",
"commander": "2.19.0",
"denodeify": "1.2.1",
"glob": "7.1.3",
"lodash": "4.17.11",
@ -2499,7 +2505,7 @@
"osenv": "0.1.5",
"parse-semver": "1.1.1",
"read": "1.0.7",
"semver": "5.5.1",
"semver": "5.6.0",
"tmp": "0.0.29",
"url-join": "1.1.0",
"vso-node-api": "6.1.2-preview",
@ -2522,7 +2528,7 @@
"gulp-vinyl-zip": "2.1.2",
"mocha": "4.1.0",
"request": "2.88.0",
"semver": "5.5.1",
"semver": "5.6.0",
"source-map-support": "0.5.9",
"url-parse": "1.4.4",
"vinyl-fs": "3.0.3",
@ -2539,7 +2545,7 @@
"resolved": "https://registry.npmjs.org/vscode-languageclient/-/vscode-languageclient-5.2.1.tgz",
"integrity": "sha512-7jrS/9WnV0ruqPamN1nE7qCxn0phkH5LjSgSp9h6qoJGoeAKzwKz/PF6M+iGA/aklx4GLZg1prddhEPQtuXI1Q==",
"requires": {
"semver": "5.5.1",
"semver": "5.6.0",
"vscode-languageserver-protocol": "3.14.1"
}
},