From e919db3731968ae7a6877530d2cb645b0495d5fd Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 4 Aug 2018 13:17:24 +0300 Subject: refine item parsing --- .../data/parser/err/0001_item_recovery_in_file.txt | 4 +-- tests/data/parser/err/0002_duplicate_shebang.txt | 2 +- tests/data/parser/err/0003_C++_semicolon.txt | 6 ++-- .../data/parser/err/0004_use_path_bad_segment.txt | 5 ++- tests/data/parser/err/0007_stray_curly_in_file.txt | 6 ++-- tests/data/parser/err/0008_item_block_recovery.txt | 8 ++--- .../err/0009_broken_struct_type_parameter.txt | 8 ++--- tests/data/parser/err/0011_extern_struct.rs | 1 + tests/data/parser/err/0011_extern_struct.txt | 13 +++++++ tests/data/parser/inline/0006_extern_struct.rs | 1 - tests/data/parser/inline/0006_extern_struct.txt | 12 ------- .../parser/inline/0013_unsafe_block_in_mod.txt | 8 +++-- .../parser/inline/0023_array_type_missing_semi.txt | 7 ++-- .../inline/0029_fn_pointer_type_missing_fn.txt | 7 ++-- tests/data/parser/inline/0068_pub_expr.rs | 1 + tests/data/parser/inline/0068_pub_expr.txt | 25 ++++++++++++++ tests/data/parser/ok/0025_extern_fn_in_block.rs | 3 ++ tests/data/parser/ok/0025_extern_fn_in_block.txt | 31 +++++++++++++++++ tests/data/parser/ok/0026_const_fn_in_block.rs | 3 ++ tests/data/parser/ok/0026_const_fn_in_block.txt | 30 ++++++++++++++++ tests/data/parser/ok/0027_unsafe_fn_in_block.rs | 4 +++ tests/data/parser/ok/0027_unsafe_fn_in_block.txt | 40 ++++++++++++++++++++++ tests/testutils/src/lib.rs | 1 + 23 files changed, 182 insertions(+), 44 deletions(-) create mode 100644 tests/data/parser/err/0011_extern_struct.rs create mode 100644 tests/data/parser/err/0011_extern_struct.txt delete mode 100644 tests/data/parser/inline/0006_extern_struct.rs delete mode 100644 tests/data/parser/inline/0006_extern_struct.txt create mode 100644 tests/data/parser/inline/0068_pub_expr.rs create mode 100644 tests/data/parser/inline/0068_pub_expr.txt create mode 100644 tests/data/parser/ok/0025_extern_fn_in_block.rs create mode 100644 tests/data/parser/ok/0025_extern_fn_in_block.txt create mode 100644 tests/data/parser/ok/0026_const_fn_in_block.rs create mode 100644 tests/data/parser/ok/0026_const_fn_in_block.txt create mode 100644 tests/data/parser/ok/0027_unsafe_fn_in_block.rs create mode 100644 tests/data/parser/ok/0027_unsafe_fn_in_block.txt (limited to 'tests') diff --git a/tests/data/parser/err/0001_item_recovery_in_file.txt b/tests/data/parser/err/0001_item_recovery_in_file.txt index f35b97b48..49612ac73 100644 --- a/tests/data/parser/err/0001_item_recovery_in_file.txt +++ b/tests/data/parser/err/0001_item_recovery_in_file.txt @@ -1,9 +1,9 @@ FILE@[0; 21) ERROR@[0; 3) IF_KW@[0; 2) - err: `expected item` + err: `expected an item` WHITESPACE@[2; 3) - err: `expected item` + err: `expected an item` ERROR@[3; 10) MATCH_KW@[3; 8) WHITESPACE@[8; 10) diff --git a/tests/data/parser/err/0002_duplicate_shebang.txt b/tests/data/parser/err/0002_duplicate_shebang.txt index 1a4b37da8..ef0ddb09a 100644 --- a/tests/data/parser/err/0002_duplicate_shebang.txt +++ b/tests/data/parser/err/0002_duplicate_shebang.txt @@ -1,6 +1,6 @@ FILE@[0; 42) SHEBANG@[0; 20) - err: `expected item` + err: `expected an item` ERROR@[20; 42) WHITESPACE@[20; 21) SHEBANG@[21; 41) diff --git a/tests/data/parser/err/0003_C++_semicolon.txt b/tests/data/parser/err/0003_C++_semicolon.txt index dc3cf6c73..0a2dad70d 100644 --- a/tests/data/parser/err/0003_C++_semicolon.txt +++ b/tests/data/parser/err/0003_C++_semicolon.txt @@ -1,5 +1,5 @@ FILE@[0; 40) - STRUCT_ITEM@[0; 39) + STRUCT_ITEM@[0; 40) STRUCT_KW@[0; 6) NAME@[6; 9) WHITESPACE@[6; 7) @@ -34,5 +34,5 @@ FILE@[0; 40) R_CURLY@[38; 39) err: `expected item, found `;` consider removing this semicolon` - ERROR@[39; 40) - SEMI@[39; 40) + ERROR@[39; 40) + SEMI@[39; 40) diff --git a/tests/data/parser/err/0004_use_path_bad_segment.txt b/tests/data/parser/err/0004_use_path_bad_segment.txt index 6eb6123ec..9b827d862 100644 --- a/tests/data/parser/err/0004_use_path_bad_segment.txt +++ b/tests/data/parser/err/0004_use_path_bad_segment.txt @@ -11,11 +11,10 @@ FILE@[0; 12) COLONCOLON@[7; 9) err: `expected identifier` err: `expected SEMI` - err: `expected item` + err: `expected an item` PATH_SEGMENT@[9; 9) ERROR@[9; 11) INT_NUMBER@[9; 11) "92" - err: `expected item, found `;` -consider removing this semicolon` + err: `expected an item` ERROR@[11; 12) SEMI@[11; 12) diff --git a/tests/data/parser/err/0007_stray_curly_in_file.txt b/tests/data/parser/err/0007_stray_curly_in_file.txt index 9758a969f..473fe17cb 100644 --- a/tests/data/parser/err/0007_stray_curly_in_file.txt +++ b/tests/data/parser/err/0007_stray_curly_in_file.txt @@ -1,7 +1,7 @@ FILE@[0; 31) ERROR@[0; 3) R_CURLY@[0; 1) - err: `expected item` + err: `expected an item` WHITESPACE@[1; 3) STRUCT_ITEM@[3; 14) STRUCT_KW@[3; 9) @@ -10,7 +10,7 @@ FILE@[0; 31) IDENT@[10; 11) "S" SEMI@[11; 12) WHITESPACE@[12; 14) - err: `expected item` + err: `expected an item` ERROR@[14; 17) R_CURLY@[14; 15) WHITESPACE@[15; 17) @@ -26,7 +26,7 @@ FILE@[0; 31) L_CURLY@[25; 26) R_CURLY@[26; 27) WHITESPACE@[27; 29) - err: `expected item` + err: `expected an item` ERROR@[29; 31) R_CURLY@[29; 30) WHITESPACE@[30; 31) diff --git a/tests/data/parser/err/0008_item_block_recovery.txt b/tests/data/parser/err/0008_item_block_recovery.txt index 5bc62b6e1..80253d8af 100644 --- a/tests/data/parser/err/0008_item_block_recovery.txt +++ b/tests/data/parser/err/0008_item_block_recovery.txt @@ -13,17 +13,17 @@ FILE@[0; 95) WHITESPACE@[10; 11) R_CURLY@[11; 12) WHITESPACE@[12; 14) - err: `expected item` + err: `expected an item` ERROR@[14; 17) IDENT@[14; 17) "bar" - err: `expected item` + err: `expected an item` ERROR@[17; 18) L_PAREN@[17; 18) - err: `expected item` + err: `expected an item` ERROR@[18; 20) R_PAREN@[18; 19) WHITESPACE@[19; 20) - err: `expected item` + err: `expected an item` ERROR@[20; 82) L_CURLY@[20; 21) WHITESPACE@[21; 26) diff --git a/tests/data/parser/err/0009_broken_struct_type_parameter.txt b/tests/data/parser/err/0009_broken_struct_type_parameter.txt index 700fc550f..72e5b36e5 100644 --- a/tests/data/parser/err/0009_broken_struct_type_parameter.txt +++ b/tests/data/parser/err/0009_broken_struct_type_parameter.txt @@ -13,18 +13,18 @@ FILE@[0; 43) err: `expected COMMA` err: `expected R_ANGLE` err: `expected `;`, `{`, or `(`` - err: `expected item` + err: `expected an item` ERROR@[12; 14) PLUS@[12; 13) WHITESPACE@[13; 14) - err: `expected item` + err: `expected an item` ERROR@[14; 15) INT_NUMBER@[14; 15) "2" - err: `expected item` + err: `expected an item` ERROR@[15; 17) R_ANGLE@[15; 16) WHITESPACE@[16; 17) - err: `expected item` + err: `expected an item` ERROR@[17; 33) L_CURLY@[17; 18) WHITESPACE@[18; 23) diff --git a/tests/data/parser/err/0011_extern_struct.rs b/tests/data/parser/err/0011_extern_struct.rs new file mode 100644 index 000000000..c1bd0a2d1 --- /dev/null +++ b/tests/data/parser/err/0011_extern_struct.rs @@ -0,0 +1 @@ +extern struct Foo; diff --git a/tests/data/parser/err/0011_extern_struct.txt b/tests/data/parser/err/0011_extern_struct.txt new file mode 100644 index 000000000..288f3469b --- /dev/null +++ b/tests/data/parser/err/0011_extern_struct.txt @@ -0,0 +1,13 @@ +FILE@[0; 19) + ERROR@[0; 7) + ABI@[0; 7) + EXTERN_KW@[0; 6) + WHITESPACE@[6; 7) + err: `expected fn, trait or impl` + STRUCT_ITEM@[7; 19) + STRUCT_KW@[7; 13) + NAME@[13; 17) + WHITESPACE@[13; 14) + IDENT@[14; 17) "Foo" + SEMI@[17; 18) + WHITESPACE@[18; 19) diff --git a/tests/data/parser/inline/0006_extern_struct.rs b/tests/data/parser/inline/0006_extern_struct.rs deleted file mode 100644 index c1bd0a2d1..000000000 --- a/tests/data/parser/inline/0006_extern_struct.rs +++ /dev/null @@ -1 +0,0 @@ -extern struct Foo; diff --git a/tests/data/parser/inline/0006_extern_struct.txt b/tests/data/parser/inline/0006_extern_struct.txt deleted file mode 100644 index f310e1225..000000000 --- a/tests/data/parser/inline/0006_extern_struct.txt +++ /dev/null @@ -1,12 +0,0 @@ -FILE@[0; 19) - ABI@[0; 7) - EXTERN_KW@[0; 6) - WHITESPACE@[6; 7) - err: `expected `fn` or `{`` - STRUCT_ITEM@[7; 19) - STRUCT_KW@[7; 13) - NAME@[13; 17) - WHITESPACE@[13; 14) - IDENT@[14; 17) "Foo" - SEMI@[17; 18) - WHITESPACE@[18; 19) diff --git a/tests/data/parser/inline/0013_unsafe_block_in_mod.txt b/tests/data/parser/inline/0013_unsafe_block_in_mod.txt index e5581d615..142838692 100644 --- a/tests/data/parser/inline/0013_unsafe_block_in_mod.txt +++ b/tests/data/parser/inline/0013_unsafe_block_in_mod.txt @@ -11,10 +11,12 @@ FILE@[0; 33) L_CURLY@[8; 9) R_CURLY@[9; 10) WHITESPACE@[10; 11) - UNSAFE_KW@[11; 17) - err: `expected `trait`, `impl` or `fn`` - ERROR@[17; 22) + err: `expected an item` + ERROR@[11; 18) + UNSAFE_KW@[11; 17) WHITESPACE@[17; 18) + err: `expected an item` + ERROR@[18; 22) L_CURLY@[18; 19) WHITESPACE@[19; 20) R_CURLY@[20; 21) diff --git a/tests/data/parser/inline/0023_array_type_missing_semi.txt b/tests/data/parser/inline/0023_array_type_missing_semi.txt index f3e9ffe4a..aa600eab4 100644 --- a/tests/data/parser/inline/0023_array_type_missing_semi.txt +++ b/tests/data/parser/inline/0023_array_type_missing_semi.txt @@ -15,14 +15,13 @@ FILE@[0; 18) WHITESPACE@[12; 13) err: `expected `;` or `]`` err: `expected SEMI` - err: `expected item` + err: `expected an item` ERROR@[13; 15) INT_NUMBER@[13; 15) "92" - err: `expected item` + err: `expected an item` ERROR@[15; 16) R_BRACK@[15; 16) - err: `expected item, found `;` -consider removing this semicolon` + err: `expected an item` ERROR@[16; 18) SEMI@[16; 17) WHITESPACE@[17; 18) diff --git a/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt b/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt index c99714ed4..82632b7bf 100644 --- a/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt +++ b/tests/data/parser/inline/0029_fn_pointer_type_missing_fn.txt @@ -11,14 +11,13 @@ FILE@[0; 20) err: `expected `fn`` err: `expected SEMI` WHITESPACE@[15; 16) - err: `expected item` + err: `expected an item` ERROR@[16; 17) L_PAREN@[16; 17) - err: `expected item` + err: `expected an item` ERROR@[17; 18) R_PAREN@[17; 18) - err: `expected item, found `;` -consider removing this semicolon` + err: `expected an item` ERROR@[18; 20) SEMI@[18; 19) WHITESPACE@[19; 20) diff --git a/tests/data/parser/inline/0068_pub_expr.rs b/tests/data/parser/inline/0068_pub_expr.rs new file mode 100644 index 000000000..d9d99d2d3 --- /dev/null +++ b/tests/data/parser/inline/0068_pub_expr.rs @@ -0,0 +1 @@ +fn foo() { pub 92; } //FIXME diff --git a/tests/data/parser/inline/0068_pub_expr.txt b/tests/data/parser/inline/0068_pub_expr.txt new file mode 100644 index 000000000..09cf9b262 --- /dev/null +++ b/tests/data/parser/inline/0068_pub_expr.txt @@ -0,0 +1,25 @@ +FILE@[0; 29) + FN_ITEM@[0; 29) + FN_KW@[0; 2) + NAME@[2; 6) + WHITESPACE@[2; 3) + IDENT@[3; 6) "foo" + PARAM_LIST@[6; 9) + L_PAREN@[6; 7) + R_PAREN@[7; 8) + WHITESPACE@[8; 9) + BLOCK_EXPR@[9; 29) + L_CURLY@[9; 10) + EXPR_STMT@[10; 19) + VISIBILITY@[10; 15) + WHITESPACE@[10; 11) + PUB_KW@[11; 14) + WHITESPACE@[14; 15) + LITERAL@[15; 17) + INT_NUMBER@[15; 17) "92" + SEMI@[17; 18) + WHITESPACE@[18; 19) + R_CURLY@[19; 20) + WHITESPACE@[20; 21) + COMMENT@[21; 28) + WHITESPACE@[28; 29) diff --git a/tests/data/parser/ok/0025_extern_fn_in_block.rs b/tests/data/parser/ok/0025_extern_fn_in_block.rs new file mode 100644 index 000000000..289809809 --- /dev/null +++ b/tests/data/parser/ok/0025_extern_fn_in_block.rs @@ -0,0 +1,3 @@ +fn main() { + extern fn f() {} +} diff --git a/tests/data/parser/ok/0025_extern_fn_in_block.txt b/tests/data/parser/ok/0025_extern_fn_in_block.txt new file mode 100644 index 000000000..0623740aa --- /dev/null +++ b/tests/data/parser/ok/0025_extern_fn_in_block.txt @@ -0,0 +1,31 @@ +FILE@[0; 35) + FN_ITEM@[0; 35) + FN_KW@[0; 2) + NAME@[2; 7) + WHITESPACE@[2; 3) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 10) + L_PAREN@[7; 8) + R_PAREN@[8; 9) + WHITESPACE@[9; 10) + BLOCK_EXPR@[10; 35) + L_CURLY@[10; 11) + FN_ITEM@[11; 33) + ABI@[11; 23) + WHITESPACE@[11; 16) + EXTERN_KW@[16; 22) + WHITESPACE@[22; 23) + FN_KW@[23; 25) + NAME@[25; 27) + WHITESPACE@[25; 26) + IDENT@[26; 27) "f" + PARAM_LIST@[27; 30) + L_PAREN@[27; 28) + R_PAREN@[28; 29) + WHITESPACE@[29; 30) + BLOCK_EXPR@[30; 33) + L_CURLY@[30; 31) + R_CURLY@[31; 32) + WHITESPACE@[32; 33) + R_CURLY@[33; 34) + WHITESPACE@[34; 35) diff --git a/tests/data/parser/ok/0026_const_fn_in_block.rs b/tests/data/parser/ok/0026_const_fn_in_block.rs new file mode 100644 index 000000000..7641a3d28 --- /dev/null +++ b/tests/data/parser/ok/0026_const_fn_in_block.rs @@ -0,0 +1,3 @@ +fn main() { + const fn f() {} +} diff --git a/tests/data/parser/ok/0026_const_fn_in_block.txt b/tests/data/parser/ok/0026_const_fn_in_block.txt new file mode 100644 index 000000000..329c65846 --- /dev/null +++ b/tests/data/parser/ok/0026_const_fn_in_block.txt @@ -0,0 +1,30 @@ +FILE@[0; 34) + FN_ITEM@[0; 34) + FN_KW@[0; 2) + NAME@[2; 7) + WHITESPACE@[2; 3) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 10) + L_PAREN@[7; 8) + R_PAREN@[8; 9) + WHITESPACE@[9; 10) + BLOCK_EXPR@[10; 34) + L_CURLY@[10; 11) + FN_ITEM@[11; 32) + WHITESPACE@[11; 16) + CONST_KW@[16; 21) + WHITESPACE@[21; 22) + FN_KW@[22; 24) + NAME@[24; 26) + WHITESPACE@[24; 25) + IDENT@[25; 26) "f" + PARAM_LIST@[26; 29) + L_PAREN@[26; 27) + R_PAREN@[27; 28) + WHITESPACE@[28; 29) + BLOCK_EXPR@[29; 32) + L_CURLY@[29; 30) + R_CURLY@[30; 31) + WHITESPACE@[31; 32) + R_CURLY@[32; 33) + WHITESPACE@[33; 34) diff --git a/tests/data/parser/ok/0027_unsafe_fn_in_block.rs b/tests/data/parser/ok/0027_unsafe_fn_in_block.rs new file mode 100644 index 000000000..f3c5ff938 --- /dev/null +++ b/tests/data/parser/ok/0027_unsafe_fn_in_block.rs @@ -0,0 +1,4 @@ +fn main() { + unsafe fn f() {} + unsafe { 92 } +} diff --git a/tests/data/parser/ok/0027_unsafe_fn_in_block.txt b/tests/data/parser/ok/0027_unsafe_fn_in_block.txt new file mode 100644 index 000000000..9982d0308 --- /dev/null +++ b/tests/data/parser/ok/0027_unsafe_fn_in_block.txt @@ -0,0 +1,40 @@ +FILE@[0; 53) + FN_ITEM@[0; 53) + FN_KW@[0; 2) + NAME@[2; 7) + WHITESPACE@[2; 3) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 10) + L_PAREN@[7; 8) + R_PAREN@[8; 9) + WHITESPACE@[9; 10) + BLOCK_EXPR@[10; 53) + L_CURLY@[10; 11) + FN_ITEM@[11; 37) + WHITESPACE@[11; 16) + UNSAFE_KW@[16; 22) + WHITESPACE@[22; 23) + FN_KW@[23; 25) + NAME@[25; 27) + WHITESPACE@[25; 26) + IDENT@[26; 27) "f" + PARAM_LIST@[27; 30) + L_PAREN@[27; 28) + R_PAREN@[28; 29) + WHITESPACE@[29; 30) + BLOCK_EXPR@[30; 37) + L_CURLY@[30; 31) + R_CURLY@[31; 32) + WHITESPACE@[32; 37) + BLOCK_EXPR@[37; 51) + UNSAFE_KW@[37; 43) + WHITESPACE@[43; 44) + L_CURLY@[44; 45) + LITERAL@[45; 49) + WHITESPACE@[45; 46) + INT_NUMBER@[46; 48) "92" + WHITESPACE@[48; 49) + R_CURLY@[49; 50) + WHITESPACE@[50; 51) + R_CURLY@[51; 52) + WHITESPACE@[52; 53) diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs index deeb707d3..39c821661 100644 --- a/tests/testutils/src/lib.rs +++ b/tests/testutils/src/lib.rs @@ -90,6 +90,7 @@ fn print_difference(expected: &str, actual: &str, path: &Path) { return; } let changeset = Changeset::new(actual, expected, "\n"); + println!("Expected:\n{}\n\nActual:\n{}\n", expected, actual); print!("{}", changeset); println!("file: {}\n", path.display()); panic!("Comparison failed") -- cgit v1.2.3