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 ++++++++++++++++++++++ 2 files changed, 27 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 (limited to 'crates/ra_syntax/test_data/parser/err') 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 -- cgit v1.2.3 From a68aefdc463af054e7e98293c06b751c135911d5 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Fri, 15 Nov 2019 01:04:37 -0800 Subject: Move inclusive range check to validation --- .../parser/err/0038_endless_inclusive_range.rs | 1 + .../parser/err/0038_endless_inclusive_range.txt | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'crates/ra_syntax/test_data/parser/err') 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 index ecd25afaf..0b4ed7a2b 100644 --- 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 @@ -1,3 +1,4 @@ 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 index 3efe98164..749d53609 100644 --- 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 @@ -1,5 +1,5 @@ -SOURCE_FILE@[0; 24) - FN_DEF@[0; 23) +SOURCE_FILE@[0; 33) + FN_DEF@[0; 32) FN_KW@[0; 2) "fn" WHITESPACE@[2; 3) " " NAME@[3; 7) @@ -8,8 +8,8 @@ SOURCE_FILE@[0; 24) L_PAREN@[7; 8) "(" R_PAREN@[8; 9) ")" WHITESPACE@[9; 10) " " - BLOCK_EXPR@[10; 23) - BLOCK@[10; 23) + BLOCK_EXPR@[10; 32) + BLOCK@[10; 32) L_CURLY@[10; 11) "{" WHITESPACE@[11; 16) "\n " EXPR_STMT@[16; 21) @@ -18,7 +18,13 @@ SOURCE_FILE@[0; 24) 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 + WHITESPACE@[21; 26) "\n " + EXPR_STMT@[26; 30) + RANGE_EXPR@[26; 29) + DOTDOTEQ@[26; 29) "..=" + SEMI@[29; 30) ";" + WHITESPACE@[30; 31) "\n" + R_CURLY@[31; 32) "}" + WHITESPACE@[32; 33) "\n" +error [17; 20): An inclusive range must have an end expression +error [26; 29): An inclusive range must have an end expression -- cgit v1.2.3 From 5645c153e0379874d1f44ab149c3ec9257812692 Mon Sep 17 00:00:00 2001 From: Geoffry Song Date: Fri, 15 Nov 2019 12:05:29 -0800 Subject: Attempt to implement typed accessors --- crates/ra_syntax/test_data/parser/err/0038_endless_inclusive_range.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_syntax/test_data/parser/err') 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 index 749d53609..3810b9680 100644 --- 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 @@ -26,5 +26,5 @@ SOURCE_FILE@[0; 33) WHITESPACE@[30; 31) "\n" R_CURLY@[31; 32) "}" WHITESPACE@[32; 33) "\n" -error [17; 20): An inclusive range must have an end expression +error [16; 20): An inclusive range must have an end expression error [26; 29): An inclusive range must have an end expression -- cgit v1.2.3