From 989cebc99c02acd427f01724c4fa77d81691e886 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Fri, 15 Nov 2019 00:08:43 -0800 Subject: Fix parsing of "postfix" range expressions. Right now they are handled in `postfix_dot_expr`, but that doesn't allow it to correctly handle precedence. Integrate it more tightly with the Pratt parser instead. Also includes a drive-by fix for parsing `match .. {}`. Fixes #2242. --- .../parser/err/0038_endless_inclusive_range.rs | 3 ++ .../parser/err/0038_endless_inclusive_range.txt | 24 ++++++++++ .../ra_syntax/test_data/parser/ok/0060_as_range.rs | 4 ++ .../test_data/parser/ok/0060_as_range.txt | 56 ++++++++++++++++++++++ .../test_data/parser/ok/0061_match_full_range.rs | 4 ++ .../test_data/parser/ok/0061_match_full_range.txt | 27 +++++++++++ 6 files changed, 118 insertions(+) create mode 100644 crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rs create mode 100644 crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.txt create mode 100644 crates/ra_syntax/test_data/parser/ok/0060_as_range.rs create mode 100644 crates/ra_syntax/test_data/parser/ok/0060_as_range.txt create mode 100644 crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rs create mode 100644 crates/ra_syntax/test_data/parser/ok/0061_match_full_range.txt (limited to 'crates/ra_syntax') diff --git a/crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rs b/crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rs new file mode 100644 index 000000000..ecd25afaf --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.rs @@ -0,0 +1,3 @@ +fn main() { + 0..=; +} diff --git a/crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.txt b/crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.txt new file mode 100644 index 000000000..3efe98164 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.txt @@ -0,0 +1,24 @@ +SOURCE_FILE@[0; 24) + FN_DEF@[0; 23) + FN_KW@[0; 2) "fn" + WHITESPACE@[2; 3) " " + NAME@[3; 7) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 9) + L_PAREN@[7; 8) "(" + R_PAREN@[8; 9) ")" + WHITESPACE@[9; 10) " " + BLOCK_EXPR@[10; 23) + BLOCK@[10; 23) + L_CURLY@[10; 11) "{" + WHITESPACE@[11; 16) "\n " + EXPR_STMT@[16; 21) + RANGE_EXPR@[16; 20) + LITERAL@[16; 17) + INT_NUMBER@[16; 17) "0" + DOTDOTEQ@[17; 20) "..=" + SEMI@[20; 21) ";" + WHITESPACE@[21; 22) "\n" + R_CURLY@[22; 23) "}" + WHITESPACE@[23; 24) "\n" +error 20: expected expression to end inclusive range diff --git a/crates/ra_syntax/test_data/parser/ok/0060_as_range.rs b/crates/ra_syntax/test_data/parser/ok/0060_as_range.rs new file mode 100644 index 000000000..f063ffadb --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0060_as_range.rs @@ -0,0 +1,4 @@ +fn main() { + 0 as usize ..; + 1 + 2 as usize ..; +} diff --git a/crates/ra_syntax/test_data/parser/ok/0060_as_range.txt b/crates/ra_syntax/test_data/parser/ok/0060_as_range.txt new file mode 100644 index 000000000..ad0c4a3fe --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0060_as_range.txt @@ -0,0 +1,56 @@ +SOURCE_FILE@[0; 56) + FN_DEF@[0; 55) + FN_KW@[0; 2) "fn" + WHITESPACE@[2; 3) " " + NAME@[3; 7) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 9) + L_PAREN@[7; 8) "(" + R_PAREN@[8; 9) ")" + WHITESPACE@[9; 10) " " + BLOCK_EXPR@[10; 55) + BLOCK@[10; 55) + L_CURLY@[10; 11) "{" + WHITESPACE@[11; 16) "\n " + EXPR_STMT@[16; 30) + RANGE_EXPR@[16; 29) + CAST_EXPR@[16; 26) + LITERAL@[16; 17) + INT_NUMBER@[16; 17) "0" + WHITESPACE@[17; 18) " " + AS_KW@[18; 20) "as" + WHITESPACE@[20; 21) " " + PATH_TYPE@[21; 26) + PATH@[21; 26) + PATH_SEGMENT@[21; 26) + NAME_REF@[21; 26) + IDENT@[21; 26) "usize" + WHITESPACE@[26; 27) " " + DOTDOT@[27; 29) ".." + SEMI@[29; 30) ";" + WHITESPACE@[30; 35) "\n " + EXPR_STMT@[35; 53) + RANGE_EXPR@[35; 52) + BIN_EXPR@[35; 49) + LITERAL@[35; 36) + INT_NUMBER@[35; 36) "1" + WHITESPACE@[36; 37) " " + PLUS@[37; 38) "+" + WHITESPACE@[38; 39) " " + CAST_EXPR@[39; 49) + LITERAL@[39; 40) + INT_NUMBER@[39; 40) "2" + WHITESPACE@[40; 41) " " + AS_KW@[41; 43) "as" + WHITESPACE@[43; 44) " " + PATH_TYPE@[44; 49) + PATH@[44; 49) + PATH_SEGMENT@[44; 49) + NAME_REF@[44; 49) + IDENT@[44; 49) "usize" + WHITESPACE@[49; 50) " " + DOTDOT@[50; 52) ".." + SEMI@[52; 53) ";" + WHITESPACE@[53; 54) "\n" + R_CURLY@[54; 55) "}" + WHITESPACE@[55; 56) "\n" diff --git a/crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rs b/crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rs new file mode 100644 index 000000000..2c4ed11e1 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0061_match_full_range.rs @@ -0,0 +1,4 @@ +fn main() { + match .. { + } +} diff --git a/crates/ra_syntax/test_data/parser/ok/0061_match_full_range.txt b/crates/ra_syntax/test_data/parser/ok/0061_match_full_range.txt new file mode 100644 index 000000000..bdfac9b76 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/ok/0061_match_full_range.txt @@ -0,0 +1,27 @@ +SOURCE_FILE@[0; 35) + FN_DEF@[0; 34) + FN_KW@[0; 2) "fn" + WHITESPACE@[2; 3) " " + NAME@[3; 7) + IDENT@[3; 7) "main" + PARAM_LIST@[7; 9) + L_PAREN@[7; 8) "(" + R_PAREN@[8; 9) ")" + WHITESPACE@[9; 10) " " + BLOCK_EXPR@[10; 34) + BLOCK@[10; 34) + L_CURLY@[10; 11) "{" + WHITESPACE@[11; 16) "\n " + MATCH_EXPR@[16; 32) + MATCH_KW@[16; 21) "match" + WHITESPACE@[21; 22) " " + RANGE_EXPR@[22; 24) + DOTDOT@[22; 24) ".." + WHITESPACE@[24; 25) " " + MATCH_ARM_LIST@[25; 32) + L_CURLY@[25; 26) "{" + WHITESPACE@[26; 31) "\n " + R_CURLY@[31; 32) "}" + WHITESPACE@[32; 33) "\n" + R_CURLY@[33; 34) "}" + WHITESPACE@[34; 35) "\n" -- cgit v1.2.3