aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r--crates/libsyntax2/src/grammar/items/mod.rs7
-rw-r--r--crates/libsyntax2/src/lib.rs4
-rw-r--r--crates/libsyntax2/src/parser_api.rs4
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0007_stray_curly_in_file.txt6
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt2
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.rs4
-rw-r--r--crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.txt47
-rw-r--r--crates/libsyntax2/tests/test/main.rs1
8 files changed, 67 insertions, 8 deletions
diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs
index 32d0778c4..a285892df 100644
--- a/crates/libsyntax2/src/grammar/items/mod.rs
+++ b/crates/libsyntax2/src/grammar/items/mod.rs
@@ -43,7 +43,12 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF
43 m.abandon(p); 43 m.abandon(p);
44 if p.at(L_CURLY) { 44 if p.at(L_CURLY) {
45 error_block(p, "expected an item"); 45 error_block(p, "expected an item");
46 } else if !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) { 46 } else if p.at(R_CURLY) && !stop_on_r_curly {
47 let e = p.start();
48 p.error("unmatched `}`");
49 p.bump();
50 e.complete(p, ERROR);
51 } else if !p.at(EOF) && !p.at(R_CURLY) {
47 p.err_and_bump("expected an item"); 52 p.err_and_bump("expected an item");
48 } else { 53 } else {
49 p.error("expected an item"); 54 p.error("expected an item");
diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs
index 9ba9970c9..93057dd6a 100644
--- a/crates/libsyntax2/src/lib.rs
+++ b/crates/libsyntax2/src/lib.rs
@@ -127,12 +127,12 @@ fn validate_block_structure(root: SyntaxNodeRef) {
127 assert_eq!( 127 assert_eq!(
128 node.parent(), 128 node.parent(),
129 pair.parent(), 129 pair.parent(),
130 "unpaired curleys:\n{}", 130 "\nunpaired curleys:\n{}",
131 utils::dump_tree(root), 131 utils::dump_tree(root),
132 ); 132 );
133 assert!( 133 assert!(
134 node.next_sibling().is_none() && pair.prev_sibling().is_none(), 134 node.next_sibling().is_none() && pair.prev_sibling().is_none(),
135 "floating curlys at {:?}\nfile:\n{}\nerror:\n{}\n", 135 "\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n",
136 node, 136 node,
137 root.text(), 137 root.text(),
138 node.text(), 138 node.text(),
diff --git a/crates/libsyntax2/src/parser_api.rs b/crates/libsyntax2/src/parser_api.rs
index bb34fe973..0a3b29b70 100644
--- a/crates/libsyntax2/src/parser_api.rs
+++ b/crates/libsyntax2/src/parser_api.rs
@@ -141,7 +141,9 @@ impl<'t> Parser<'t> {
141 pub(crate) fn err_and_bump(&mut self, message: &str) { 141 pub(crate) fn err_and_bump(&mut self, message: &str) {
142 let m = self.start(); 142 let m = self.start();
143 self.error(message); 143 self.error(message);
144 self.bump(); 144 if !self.at(SyntaxKind::L_CURLY) && !self.at(SyntaxKind::R_CURLY) {
145 self.bump();
146 }
145 m.complete(self, ERROR); 147 m.complete(self, ERROR);
146 } 148 }
147} 149}
diff --git a/crates/libsyntax2/tests/data/parser/err/0007_stray_curly_in_file.txt b/crates/libsyntax2/tests/data/parser/err/0007_stray_curly_in_file.txt
index 81e82f7e2..802c69b31 100644
--- a/crates/libsyntax2/tests/data/parser/err/0007_stray_curly_in_file.txt
+++ b/crates/libsyntax2/tests/data/parser/err/0007_stray_curly_in_file.txt
@@ -1,7 +1,7 @@
1ROOT@[0; 31) 1ROOT@[0; 31)
2 ERROR@[0; 1) 2 ERROR@[0; 1)
3 R_CURLY@[0; 1) 3 R_CURLY@[0; 1)
4 err: `expected an item` 4 err: `unmatched `}``
5 WHITESPACE@[1; 3) 5 WHITESPACE@[1; 3)
6 STRUCT_DEF@[3; 12) 6 STRUCT_DEF@[3; 12)
7 STRUCT_KW@[3; 9) 7 STRUCT_KW@[3; 9)
@@ -10,7 +10,7 @@ ROOT@[0; 31)
10 IDENT@[10; 11) "S" 10 IDENT@[10; 11) "S"
11 SEMI@[11; 12) 11 SEMI@[11; 12)
12 WHITESPACE@[12; 14) 12 WHITESPACE@[12; 14)
13 err: `expected an item` 13 err: `unmatched `}``
14 ERROR@[14; 15) 14 ERROR@[14; 15)
15 R_CURLY@[14; 15) 15 R_CURLY@[14; 15)
16 WHITESPACE@[15; 17) 16 WHITESPACE@[15; 17)
@@ -26,7 +26,7 @@ ROOT@[0; 31)
26 L_CURLY@[25; 26) 26 L_CURLY@[25; 26)
27 R_CURLY@[26; 27) 27 R_CURLY@[26; 27)
28 WHITESPACE@[27; 29) 28 WHITESPACE@[27; 29)
29 err: `expected an item` 29 err: `unmatched `}``
30 ERROR@[29; 30) 30 ERROR@[29; 30)
31 R_CURLY@[29; 30) 31 R_CURLY@[29; 30)
32 WHITESPACE@[30; 31) 32 WHITESPACE@[30; 31)
diff --git a/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt b/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt
index dbc19abea..5f736a978 100644
--- a/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt
+++ b/crates/libsyntax2/tests/data/parser/err/0015_curly_in_params.txt
@@ -9,7 +9,7 @@ ROOT@[0; 14)
9 err: `expected value parameter` 9 err: `expected value parameter`
10 err: `expected R_PAREN` 10 err: `expected R_PAREN`
11 err: `expected a block` 11 err: `expected a block`
12 err: `expected an item` 12 err: `unmatched `}``
13 ERROR@[7; 8) 13 ERROR@[7; 8)
14 R_CURLY@[7; 8) 14 R_CURLY@[7; 8)
15 err: `expected an item` 15 err: `expected an item`
diff --git a/crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.rs b/crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.rs
new file mode 100644
index 000000000..17bd49777
--- /dev/null
+++ b/crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.rs
@@ -0,0 +1,4 @@
1fn foo(foo: i32) {
2 let bar = 92;
3 1 +
4}
diff --git a/crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.txt b/crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.txt
new file mode 100644
index 000000000..db9a2f175
--- /dev/null
+++ b/crates/libsyntax2/tests/data/parser/err/0017_incomplete_binexpr.txt
@@ -0,0 +1,47 @@
1ROOT@[0; 47)
2 FN_DEF@[0; 46)
3 FN_KW@[0; 2)
4 WHITESPACE@[2; 3)
5 NAME@[3; 6)
6 IDENT@[3; 6) "foo"
7 PARAM_LIST@[6; 16)
8 L_PAREN@[6; 7)
9 PARAM@[7; 15)
10 BIND_PAT@[7; 10)
11 NAME@[7; 10)
12 IDENT@[7; 10) "foo"
13 COLON@[10; 11)
14 WHITESPACE@[11; 12)
15 PATH_TYPE@[12; 15)
16 PATH@[12; 15)
17 PATH_SEGMENT@[12; 15)
18 NAME_REF@[12; 15)
19 IDENT@[12; 15) "i32"
20 R_PAREN@[15; 16)
21 WHITESPACE@[16; 17)
22 BLOCK@[17; 46)
23 L_CURLY@[17; 18)
24 WHITESPACE@[18; 23)
25 LET_STMT@[23; 36)
26 LET_KW@[23; 26)
27 WHITESPACE@[26; 27)
28 BIND_PAT@[27; 30)
29 NAME@[27; 30)
30 IDENT@[27; 30) "bar"
31 WHITESPACE@[30; 31)
32 EQ@[31; 32)
33 WHITESPACE@[32; 33)
34 LITERAL@[33; 35)
35 INT_NUMBER@[33; 35) "92"
36 SEMI@[35; 36)
37 WHITESPACE@[36; 41)
38 BIN_EXPR@[41; 45)
39 LITERAL@[41; 42)
40 INT_NUMBER@[41; 42) "1"
41 WHITESPACE@[42; 43)
42 PLUS@[43; 44)
43 WHITESPACE@[44; 45)
44 err: `expected expression`
45 ERROR@[45; 45)
46 R_CURLY@[45; 46)
47 WHITESPACE@[46; 47)
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs
index 596f32216..9958c7ece 100644
--- a/crates/libsyntax2/tests/test/main.rs
+++ b/crates/libsyntax2/tests/test/main.rs
@@ -26,6 +26,7 @@ fn lexer_tests() {
26#[test] 26#[test]
27fn parser_tests() { 27fn parser_tests() {
28 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| { 28 dir_tests(&["parser/inline", "parser/ok", "parser/err"], |text| {
29 eprintln!("\n{}\n", text);
29 let file = File::parse(text); 30 let file = File::parse(text);
30 dump_tree(file.syntax()) 31 dump_tree(file.syntax())
31 }) 32 })