aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast.rs2
-rw-r--r--crates/ra_syntax/src/grammar/expressions.rs12
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs20
-rw-r--r--crates/ra_syntax/src/grammar/items.rs4
-rw-r--r--crates/ra_syntax/src/grammar/items/traits.rs2
-rw-r--r--crates/ra_syntax/src/grammar/items/use_item.rs2
-rw-r--r--crates/ra_syntax/src/grammar/type_args.rs2
-rw-r--r--crates/ra_syntax/src/grammar/type_params.rs9
-rw-r--r--crates/ra_syntax/src/grammar/types.rs6
-rw-r--r--crates/ra_syntax/src/lexer.rs2
-rw-r--r--crates/ra_syntax/src/string_lexing/byte.rs2
-rw-r--r--crates/ra_syntax/src/string_lexing/byte_string.rs2
-rw-r--r--crates/ra_syntax/src/string_lexing/char.rs2
-rw-r--r--crates/ra_syntax/src/string_lexing/string.rs2
14 files changed, 44 insertions, 25 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index 91c67119f..f12479fb4 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -284,7 +284,7 @@ impl<'a> IfExpr<'a> {
284 } 284 }
285} 285}
286 286
287#[derive(Debug, Clone, Copy)] 287#[derive(Debug, Clone, Copy, PartialEq, Eq)]
288pub enum PathSegmentKind<'a> { 288pub enum PathSegmentKind<'a> {
289 Name(NameRef<'a>), 289 Name(NameRef<'a>),
290 SelfKw, 290 SelfKw,
diff --git a/crates/ra_syntax/src/grammar/expressions.rs b/crates/ra_syntax/src/grammar/expressions.rs
index 4f8c46ab3..da78d85a2 100644
--- a/crates/ra_syntax/src/grammar/expressions.rs
+++ b/crates/ra_syntax/src/grammar/expressions.rs
@@ -42,9 +42,15 @@ pub(crate) fn block(p: &mut Parser) {
42 } 42 }
43 let m = p.start(); 43 let m = p.start();
44 p.bump(); 44 p.bump();
45
45 while !p.at(EOF) && !p.at(R_CURLY) { 46 while !p.at(EOF) && !p.at(R_CURLY) {
46 match p.current() { 47 match p.current() {
47 LET_KW => let_stmt(p), 48 LET_KW => let_stmt(p),
49 // test nocontentexpr
50 // fn foo(){
51 // ;;;some_expr();;;;{;;;};;;;Ok(())
52 // }
53 SEMI => p.bump(),
48 _ => { 54 _ => {
49 // test block_items 55 // test block_items
50 // fn a() { fn b() {} } 56 // fn a() { fn b() {} }
@@ -206,7 +212,7 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike {
206} 212}
207 213
208const LHS_FIRST: TokenSet = token_set_union![ 214const LHS_FIRST: TokenSet = token_set_union![
209 token_set![AMP, STAR, EXCL, DOTDOT, MINUS], 215 token_set![AMP, STAR, EXCL, DOTDOT, DOTDOTEQ, MINUS],
210 atom::ATOM_EXPR_FIRST, 216 atom::ATOM_EXPR_FIRST,
211]; 217];
212 218
@@ -237,7 +243,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
237 } 243 }
238 // test full_range_expr 244 // test full_range_expr
239 // fn foo() { xs[..]; } 245 // fn foo() { xs[..]; }
240 DOTDOT => { 246 DOTDOT | DOTDOTEQ => {
241 m = p.start(); 247 m = p.start();
242 p.bump(); 248 p.bump();
243 if p.at_ts(EXPR_FIRST) { 249 if p.at_ts(EXPR_FIRST) {
@@ -287,7 +293,7 @@ fn postfix_expr(
287 DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs), 293 DOT if p.nth(1) == INT_NUMBER => field_expr(p, lhs),
288 // test postfix_range 294 // test postfix_range
289 // fn foo() { let x = 1..; } 295 // fn foo() { let x = 1..; }
290 DOTDOT if !EXPR_FIRST.contains(p.nth(1)) => { 296 DOTDOT | DOTDOTEQ if !EXPR_FIRST.contains(p.nth(1)) => {
291 let m = lhs.precede(p); 297 let m = lhs.precede(p);
292 p.bump(); 298 p.bump();
293 m.complete(p, RANGE_EXPR) 299 m.complete(p, RANGE_EXPR)
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs
index cd7d62aff..31b09ac5b 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/grammar/expressions/atom.rs
@@ -35,11 +35,12 @@ pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
35 Some(m.complete(p, LITERAL)) 35 Some(m.complete(p, LITERAL))
36} 36}
37 37
38// E.g. for after the break in `if break {}`, this should not match
38pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![ 39pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![
39 LITERAL_FIRST, 40 LITERAL_FIRST,
40 token_set![ 41 token_set![
41 L_CURLY,
42 L_PAREN, 42 L_PAREN,
43 L_CURLY,
43 L_BRACK, 44 L_BRACK,
44 PIPE, 45 PIPE,
45 MOVE_KW, 46 MOVE_KW,
@@ -88,7 +89,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
88 WHILE_KW => while_expr(p, Some(m)), 89 WHILE_KW => while_expr(p, Some(m)),
89 L_CURLY => block_expr(p, Some(m)), 90 L_CURLY => block_expr(p, Some(m)),
90 _ => { 91 _ => {
91 // test misplaced_label_err 92 // test_err misplaced_label_err
92 // fn main() { 93 // fn main() {
93 // 'loop: impl 94 // 'loop: impl
94 // } 95 // }
@@ -108,7 +109,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
108 L_CURLY => block_expr(p, None), 109 L_CURLY => block_expr(p, None),
109 RETURN_KW => return_expr(p), 110 RETURN_KW => return_expr(p),
110 CONTINUE_KW => continue_expr(p), 111 CONTINUE_KW => continue_expr(p),
111 BREAK_KW => break_expr(p), 112 BREAK_KW => break_expr(p, r),
112 _ => { 113 _ => {
113 p.err_recover("expected expression", EXPR_RECOVERY_SET); 114 p.err_recover("expected expression", EXPR_RECOVERY_SET);
114 return None; 115 return None;
@@ -353,7 +354,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
353// fn foo() { 354// fn foo() {
354// match () { 355// match () {
355// _ => (), 356// _ => (),
356// _ if Test>{field: 0} => (), 357// _ if Test > Test{field: 0} => (),
357// X | Y if Z => (), 358// X | Y if Z => (),
358// | X | Y if Z => (), 359// | X | Y if Z => (),
359// | X => (), 360// | X => (),
@@ -427,12 +428,19 @@ fn continue_expr(p: &mut Parser) -> CompletedMarker {
427// break 'l 92; 428// break 'l 92;
428// } 429// }
429// } 430// }
430fn break_expr(p: &mut Parser) -> CompletedMarker { 431fn break_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
431 assert!(p.at(BREAK_KW)); 432 assert!(p.at(BREAK_KW));
432 let m = p.start(); 433 let m = p.start();
433 p.bump(); 434 p.bump();
434 p.eat(LIFETIME); 435 p.eat(LIFETIME);
435 if p.at_ts(EXPR_FIRST) { 436 // test break_ambiguity
437 // fn foo(){
438 // if break {}
439 // while break {}
440 // for i in break {}
441 // match break {}
442 // }
443 if p.at_ts(EXPR_FIRST) && !(r.forbid_structs && p.at(L_CURLY)) {
436 expr(p); 444 expr(p);
437 } 445 }
438 m.complete(p, BREAK_EXPR) 446 m.complete(p, BREAK_EXPR)
diff --git a/crates/ra_syntax/src/grammar/items.rs b/crates/ra_syntax/src/grammar/items.rs
index 4473c2fab..aa5fe0777 100644
--- a/crates/ra_syntax/src/grammar/items.rs
+++ b/crates/ra_syntax/src/grammar/items.rs
@@ -89,7 +89,7 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
89 // modifiers 89 // modifiers
90 has_mods |= p.eat(CONST_KW); 90 has_mods |= p.eat(CONST_KW);
91 91
92 // test unsafe_block_in_mod 92 // test_err unsafe_block_in_mod
93 // fn foo(){} unsafe { } fn bar(){} 93 // fn foo(){} unsafe { } fn bar(){}
94 if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY { 94 if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY {
95 p.eat(UNSAFE_KW); 95 p.eat(UNSAFE_KW);
@@ -202,7 +202,7 @@ fn items_without_modifiers(p: &mut Parser) -> Option<SyntaxKind> {
202 } 202 }
203 STRUCT_DEF 203 STRUCT_DEF
204 } 204 }
205 IDENT if p.at_contextual_kw("union") => { 205 IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
206 // test union_items 206 // test union_items
207 // union Foo {} 207 // union Foo {}
208 // union Foo { 208 // union Foo {
diff --git a/crates/ra_syntax/src/grammar/items/traits.rs b/crates/ra_syntax/src/grammar/items/traits.rs
index 31258c253..d4da8b2f7 100644
--- a/crates/ra_syntax/src/grammar/items/traits.rs
+++ b/crates/ra_syntax/src/grammar/items/traits.rs
@@ -116,7 +116,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool {
116 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ) 116 && (p.nth(2) == R_ANGLE || p.nth(2) == COMMA || p.nth(2) == COLON || p.nth(2) == EQ)
117} 117}
118 118
119// test impl_type 119// test_err impl_type
120// impl Type {} 120// impl Type {}
121// impl Trait1 for T {} 121// impl Trait1 for T {}
122// impl impl NotType {} 122// impl impl NotType {}
diff --git a/crates/ra_syntax/src/grammar/items/use_item.rs b/crates/ra_syntax/src/grammar/items/use_item.rs
index b3c78f351..5111d37eb 100644
--- a/crates/ra_syntax/src/grammar/items/use_item.rs
+++ b/crates/ra_syntax/src/grammar/items/use_item.rs
@@ -74,7 +74,7 @@ fn use_tree(p: &mut Parser) {
74 // other::path as some_other_name, 74 // other::path as some_other_name,
75 // different::path as different_name, 75 // different::path as different_name,
76 // yet::another::path, 76 // yet::another::path,
77 // running::out::of::synonyms::for::different::* 77 // running::out::of::synonyms::for_::different::*
78 // }; 78 // };
79 opt_alias(p); 79 opt_alias(p);
80 } 80 }
diff --git a/crates/ra_syntax/src/grammar/type_args.rs b/crates/ra_syntax/src/grammar/type_args.rs
index 29ff6e534..f889419c5 100644
--- a/crates/ra_syntax/src/grammar/type_args.rs
+++ b/crates/ra_syntax/src/grammar/type_args.rs
@@ -26,7 +26,7 @@ pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
26} 26}
27 27
28// test type_arg 28// test type_arg
29// type A = B<'static, i32, Item=u64> 29// type A = B<'static, i32, Item=u64>;
30fn type_arg(p: &mut Parser) { 30fn type_arg(p: &mut Parser) {
31 let m = p.start(); 31 let m = p.start();
32 match p.current() { 32 match p.current() {
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs
index f4c98675c..7db25beba 100644
--- a/crates/ra_syntax/src/grammar/type_params.rs
+++ b/crates/ra_syntax/src/grammar/type_params.rs
@@ -96,6 +96,7 @@ pub(super) fn bounds_without_colon(p: &mut Parser) {
96// 'a: 'b + 'c, 96// 'a: 'b + 'c,
97// T: Clone + Copy + 'static, 97// T: Clone + Copy + 'static,
98// Iterator::Item: 'a, 98// Iterator::Item: 'a,
99// <T as Iterator>::Item: 'a
99// {} 100// {}
100pub(super) fn opt_where_clause(p: &mut Parser) { 101pub(super) fn opt_where_clause(p: &mut Parser) {
101 if !p.at(WHERE_KW) { 102 if !p.at(WHERE_KW) {
@@ -104,11 +105,15 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
104 let m = p.start(); 105 let m = p.start();
105 p.bump(); 106 p.bump();
106 loop { 107 loop {
107 if !(paths::is_path_start(p) || p.current() == LIFETIME || p.current() == FOR_KW) { 108 if !(paths::is_path_start(p)
109 || p.current() == LIFETIME
110 || p.current() == FOR_KW
111 || p.current() == L_ANGLE)
112 {
108 break; 113 break;
109 } 114 }
110 where_predicate(p); 115 where_predicate(p);
111 if p.current() != L_CURLY && p.current() != SEMI { 116 if p.current() != L_CURLY && p.current() != SEMI && p.current() != EQ {
112 p.expect(COMMA); 117 p.expect(COMMA);
113 } 118 }
114 } 119 }
diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs
index 811d399d4..a933b986b 100644
--- a/crates/ra_syntax/src/grammar/types.rs
+++ b/crates/ra_syntax/src/grammar/types.rs
@@ -97,7 +97,7 @@ fn pointer_type(p: &mut Parser) {
97 // type C = *mut (); 97 // type C = *mut ();
98 MUT_KW | CONST_KW => p.bump(), 98 MUT_KW | CONST_KW => p.bump(),
99 _ => { 99 _ => {
100 // test pointer_type_no_mutability 100 // test_err pointer_type_no_mutability
101 // type T = *(); 101 // type T = *();
102 p.error( 102 p.error(
103 "expected mut or const in raw pointer type \ 103 "expected mut or const in raw pointer type \
@@ -132,7 +132,7 @@ fn array_or_slice_type(p: &mut Parser) {
132 p.expect(R_BRACK); 132 p.expect(R_BRACK);
133 ARRAY_TYPE 133 ARRAY_TYPE
134 } 134 }
135 // test array_type_missing_semi 135 // test_err array_type_missing_semi
136 // type T = [() 92]; 136 // type T = [() 92];
137 _ => { 137 _ => {
138 p.error("expected `;` or `]`"); 138 p.error("expected `;` or `]`");
@@ -175,7 +175,7 @@ fn fn_pointer_type(p: &mut Parser) {
175 if p.at(EXTERN_KW) { 175 if p.at(EXTERN_KW) {
176 abi(p); 176 abi(p);
177 } 177 }
178 // test fn_pointer_type_missing_fn 178 // test_err fn_pointer_type_missing_fn
179 // type F = unsafe (); 179 // type F = unsafe ();
180 if !p.eat(FN_KW) { 180 if !p.eat(FN_KW) {
181 m.abandon(p); 181 m.abandon(p);
diff --git a/crates/ra_syntax/src/lexer.rs b/crates/ra_syntax/src/lexer.rs
index f388da273..c6acd095e 100644
--- a/crates/ra_syntax/src/lexer.rs
+++ b/crates/ra_syntax/src/lexer.rs
@@ -160,7 +160,7 @@ fn next_token_inner(c: char, ptr: &mut Ptr) -> SyntaxKind {
160 // if we find one, then this is an invalid character literal 160 // if we find one, then this is an invalid character literal
161 if ptr.at('\'') { 161 if ptr.at('\'') {
162 ptr.bump(); 162 ptr.bump();
163 return CHAR; // TODO: error reporting 163 return CHAR;
164 } 164 }
165 LIFETIME 165 LIFETIME
166 } else { 166 } else {
diff --git a/crates/ra_syntax/src/string_lexing/byte.rs b/crates/ra_syntax/src/string_lexing/byte.rs
index 24424349c..b3228d6ca 100644
--- a/crates/ra_syntax/src/string_lexing/byte.rs
+++ b/crates/ra_syntax/src/string_lexing/byte.rs
@@ -40,7 +40,7 @@ impl<'a> Iterator for ByteComponentIterator<'a> {
40 40
41 assert!( 41 assert!(
42 self.parser.peek() == None, 42 self.parser.peek() == None,
43 "byte literal should leave no unparsed input: src = {}, pos = {}, length = {}", 43 "byte literal should leave no unparsed input: src = {:?}, pos = {}, length = {}",
44 self.parser.src, 44 self.parser.src,
45 self.parser.pos, 45 self.parser.pos,
46 self.parser.src.len() 46 self.parser.src.len()
diff --git a/crates/ra_syntax/src/string_lexing/byte_string.rs b/crates/ra_syntax/src/string_lexing/byte_string.rs
index 5b6dda760..a6056159b 100644
--- a/crates/ra_syntax/src/string_lexing/byte_string.rs
+++ b/crates/ra_syntax/src/string_lexing/byte_string.rs
@@ -40,7 +40,7 @@ impl<'a> Iterator for ByteStringComponentIterator<'a> {
40 40
41 assert!( 41 assert!(
42 self.parser.peek() == None, 42 self.parser.peek() == None,
43 "byte string literal should leave no unparsed input: src = {}, pos = {}, length = {}", 43 "byte string literal should leave no unparsed input: src = {:?}, pos = {}, length = {}",
44 self.parser.src, 44 self.parser.src,
45 self.parser.pos, 45 self.parser.pos,
46 self.parser.src.len() 46 self.parser.src.len()
diff --git a/crates/ra_syntax/src/string_lexing/char.rs b/crates/ra_syntax/src/string_lexing/char.rs
index 885c03b14..e01813176 100644
--- a/crates/ra_syntax/src/string_lexing/char.rs
+++ b/crates/ra_syntax/src/string_lexing/char.rs
@@ -35,7 +35,7 @@ impl<'a> Iterator for CharComponentIterator<'a> {
35 35
36 assert!( 36 assert!(
37 self.parser.peek() == None, 37 self.parser.peek() == None,
38 "char literal should leave no unparsed input: src = {}, pos = {}, length = {}", 38 "char literal should leave no unparsed input: src = {:?}, pos = {}, length = {}",
39 self.parser.src, 39 self.parser.src,
40 self.parser.pos, 40 self.parser.pos,
41 self.parser.src.len() 41 self.parser.src.len()
diff --git a/crates/ra_syntax/src/string_lexing/string.rs b/crates/ra_syntax/src/string_lexing/string.rs
index 1b23029c6..d8351e9af 100644
--- a/crates/ra_syntax/src/string_lexing/string.rs
+++ b/crates/ra_syntax/src/string_lexing/string.rs
@@ -35,7 +35,7 @@ impl<'a> Iterator for StringComponentIterator<'a> {
35 35
36 assert!( 36 assert!(
37 self.parser.peek() == None, 37 self.parser.peek() == None,
38 "string literal should leave no unparsed input: src = {}, pos = {}, length = {}", 38 "string literal should leave no unparsed input: src = {:?}, pos = {}, length = {}",
39 self.parser.src, 39 self.parser.src,
40 self.parser.pos, 40 self.parser.pos,
41 self.parser.src.len() 41 self.parser.src.len()