aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_parser')
-rw-r--r--crates/ra_parser/src/grammar.rs1
-rw-r--r--crates/ra_parser/src/grammar/attributes.rs21
-rw-r--r--crates/ra_parser/src/grammar/expressions.rs38
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs12
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
-rw-r--r--crates/ra_parser/src/grammar/items/consts.rs2
-rw-r--r--crates/ra_parser/src/grammar/items/nominal.rs2
-rw-r--r--crates/ra_parser/src/grammar/items/traits.rs2
-rw-r--r--crates/ra_parser/src/grammar/items/use_item.rs2
-rw-r--r--crates/ra_parser/src/grammar/params.rs2
-rw-r--r--crates/ra_parser/src/grammar/paths.rs2
-rw-r--r--crates/ra_parser/src/grammar/patterns.rs2
-rw-r--r--crates/ra_parser/src/grammar/type_args.rs2
-rw-r--r--crates/ra_parser/src/grammar/type_params.rs2
-rw-r--r--crates/ra_parser/src/grammar/types.rs2
-rw-r--r--crates/ra_parser/src/parser.rs2
-rw-r--r--crates/ra_parser/src/syntax_kind.rs2
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs2
-rw-r--r--crates/ra_parser/src/token_set.rs2
19 files changed, 87 insertions, 15 deletions
diff --git a/crates/ra_parser/src/grammar.rs b/crates/ra_parser/src/grammar.rs
index e2355aff9..6e9e212b7 100644
--- a/crates/ra_parser/src/grammar.rs
+++ b/crates/ra_parser/src/grammar.rs
@@ -135,7 +135,6 @@ pub(crate) mod fragments {
135 135
136 m.complete(p, MACRO_STMTS); 136 m.complete(p, MACRO_STMTS);
137 } 137 }
138
139} 138}
140 139
141pub(crate) fn reparser( 140pub(crate) fn reparser(
diff --git a/crates/ra_parser/src/grammar/attributes.rs b/crates/ra_parser/src/grammar/attributes.rs
index 1cfd301b5..f3158ade3 100644
--- a/crates/ra_parser/src/grammar/attributes.rs
+++ b/crates/ra_parser/src/grammar/attributes.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) fn inner_attributes(p: &mut Parser) { 5pub(super) fn inner_attributes(p: &mut Parser) {
@@ -22,8 +24,23 @@ fn attribute(p: &mut Parser, inner: bool) {
22 p.bump(T![!]); 24 p.bump(T![!]);
23 } 25 }
24 26
25 if p.at(T!['[']) { 27 if p.eat(T!['[']) {
26 items::token_tree(p); 28 paths::use_path(p);
29
30 match p.current() {
31 T![=] => {
32 p.bump(T![=]);
33 if expressions::literal(p).is_none() {
34 p.error("expected literal");
35 }
36 }
37 T!['('] | T!['['] | T!['{'] => items::token_tree(p),
38 _ => {}
39 }
40
41 if !p.eat(T![']']) {
42 p.error("expected `]`");
43 }
27 } else { 44 } else {
28 p.error("expected `[`"); 45 p.error("expected `[`");
29 } 46 }
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs
index 80b085280..45f2e3de4 100644
--- a/crates/ra_parser/src/grammar/expressions.rs
+++ b/crates/ra_parser/src/grammar/expressions.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1mod atom; 3mod atom;
2 4
3pub(crate) use self::atom::match_arm_list; 5pub(crate) use self::atom::match_arm_list;
@@ -248,6 +250,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) {
248 T![!] if p.at(T![!=]) => (5, T![!=]), 250 T![!] if p.at(T![!=]) => (5, T![!=]),
249 T![-] if p.at(T![-=]) => (1, T![-=]), 251 T![-] if p.at(T![-=]) => (1, T![-=]),
250 T![-] => (10, T![-]), 252 T![-] => (10, T![-]),
253 T![as] => (12, T![as]),
251 254
252 _ => NOT_AN_OP 255 _ => NOT_AN_OP
253 } 256 }
@@ -276,6 +279,14 @@ fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> (Option<CompletedMarker>,
276 if op_bp < bp { 279 if op_bp < bp {
277 break; 280 break;
278 } 281 }
282 // test as_precedence
283 // fn foo() {
284 // let _ = &1 as *const i32;
285 // }
286 if p.at(T![as]) {
287 lhs = cast_expr(p, lhs);
288 continue;
289 }
279 let m = lhs.precede(p); 290 let m = lhs.precede(p);
280 p.bump(op); 291 p.bump(op);
281 292
@@ -333,9 +344,16 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<(CompletedMarker, BlockLike)>
333 // } 344 // }
334 // 345 //
335 let (lhs, blocklike) = atom::atom_expr(p, r)?; 346 let (lhs, blocklike) = atom::atom_expr(p, r)?;
336 return Some(postfix_expr(p, lhs, blocklike, !(r.prefer_stmt && blocklike.is_block()))); 347 return Some(postfix_expr(
348 p,
349 lhs,
350 blocklike,
351 !(r.prefer_stmt && blocklike.is_block()),
352 r.forbid_structs,
353 ));
337 } 354 }
338 }; 355 };
356 // parse the interior of the unary expression
339 expr_bp(p, r, 255); 357 expr_bp(p, r, 255);
340 Some((m.complete(p, kind), BlockLike::NotBlock)) 358 Some((m.complete(p, kind), BlockLike::NotBlock))
341} 359}
@@ -348,6 +366,7 @@ fn postfix_expr(
348 // `while true {break}; ();` 366 // `while true {break}; ();`
349 mut block_like: BlockLike, 367 mut block_like: BlockLike,
350 mut allow_calls: bool, 368 mut allow_calls: bool,
369 forbid_structs: bool,
351) -> (CompletedMarker, BlockLike) { 370) -> (CompletedMarker, BlockLike) {
352 loop { 371 loop {
353 lhs = match p.current() { 372 lhs = match p.current() {
@@ -361,7 +380,7 @@ fn postfix_expr(
361 // } 380 // }
362 T!['('] if allow_calls => call_expr(p, lhs), 381 T!['('] if allow_calls => call_expr(p, lhs),
363 T!['['] if allow_calls => index_expr(p, lhs), 382 T!['['] if allow_calls => index_expr(p, lhs),
364 T![.] => match postfix_dot_expr(p, lhs) { 383 T![.] => match postfix_dot_expr(p, lhs, forbid_structs) {
365 Ok(it) => it, 384 Ok(it) => it,
366 Err(it) => { 385 Err(it) => {
367 lhs = it; 386 lhs = it;
@@ -369,7 +388,6 @@ fn postfix_expr(
369 } 388 }
370 }, 389 },
371 T![?] => try_expr(p, lhs), 390 T![?] => try_expr(p, lhs),
372 T![as] => cast_expr(p, lhs),
373 _ => break, 391 _ => break,
374 }; 392 };
375 allow_calls = true; 393 allow_calls = true;
@@ -380,6 +398,7 @@ fn postfix_expr(
380 fn postfix_dot_expr( 398 fn postfix_dot_expr(
381 p: &mut Parser, 399 p: &mut Parser,
382 lhs: CompletedMarker, 400 lhs: CompletedMarker,
401 forbid_structs: bool,
383 ) -> Result<CompletedMarker, CompletedMarker> { 402 ) -> Result<CompletedMarker, CompletedMarker> {
384 assert!(p.at(T![.])); 403 assert!(p.at(T![.]));
385 if p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth_at(2, T![::])) { 404 if p.nth(1) == IDENT && (p.nth(2) == T!['('] || p.nth_at(2, T![::])) {
@@ -400,10 +419,17 @@ fn postfix_expr(
400 } 419 }
401 420
402 // test postfix_range 421 // test postfix_range
403 // fn foo() { let x = 1..; } 422 // fn foo() {
404 for &(op, la) in [(T![..=], 3), (T![..], 2)].iter() { 423 // let x = 1..;
424 // match 1.. { _ => () };
425 // match a.b()..S { _ => () };
426 // }
427 for &(op, la) in &[(T![..=], 3), (T![..], 2)] {
405 if p.at(op) { 428 if p.at(op) {
406 return if EXPR_FIRST.contains(p.nth(la)) { 429 let next_token = p.nth(la);
430 let has_trailing_expression =
431 !(forbid_structs && next_token == T!['{']) && EXPR_FIRST.contains(next_token);
432 return if has_trailing_expression {
407 Err(lhs) 433 Err(lhs)
408 } else { 434 } else {
409 let m = lhs.precede(p); 435 let m = lhs.precede(p);
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index 457f42a26..7454005c4 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3// test expr_literals 5// test expr_literals
@@ -119,11 +121,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar
119 // break; 121 // break;
120 // } 122 // }
121 // } 123 // }
122 if r.forbid_structs { 124 block_expr(p, None)
123 return None;
124 } else {
125 block_expr(p, None)
126 }
127 } 125 }
128 T![return] => return_expr(p), 126 T![return] => return_expr(p),
129 T![continue] => continue_expr(p), 127 T![continue] => continue_expr(p),
@@ -259,6 +257,7 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
259// if true {} else {}; 257// if true {} else {};
260// if true {} else if false {} else {}; 258// if true {} else if false {} else {};
261// if S {}; 259// if S {};
260// if { true } { } else { };
262// } 261// }
263fn if_expr(p: &mut Parser) -> CompletedMarker { 262fn if_expr(p: &mut Parser) -> CompletedMarker {
264 assert!(p.at(T![if])); 263 assert!(p.at(T![if]));
@@ -307,6 +306,7 @@ fn loop_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
307// fn foo() { 306// fn foo() {
308// while true {}; 307// while true {};
309// while let Some(x) = it.next() {}; 308// while let Some(x) = it.next() {};
309// while { true } {};
310// } 310// }
311fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker { 311fn while_expr(p: &mut Parser, m: Option<Marker>) -> CompletedMarker {
312 assert!(p.at(T![while])); 312 assert!(p.at(T![while]));
@@ -354,6 +354,8 @@ fn cond(p: &mut Parser) {
354// fn foo() { 354// fn foo() {
355// match () { }; 355// match () { };
356// match S {}; 356// match S {};
357// match { } { _ => () };
358// match { S {} } {};
357// } 359// }
358fn match_expr(p: &mut Parser) -> CompletedMarker { 360fn match_expr(p: &mut Parser) -> CompletedMarker {
359 assert!(p.at(T![match])); 361 assert!(p.at(T![match]));
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 4c67a5c2e..85f7eeb00 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1mod consts; 3mod consts;
2mod nominal; 4mod nominal;
3mod traits; 5mod traits;
diff --git a/crates/ra_parser/src/grammar/items/consts.rs b/crates/ra_parser/src/grammar/items/consts.rs
index 310260689..742a7e056 100644
--- a/crates/ra_parser/src/grammar/items/consts.rs
+++ b/crates/ra_parser/src/grammar/items/consts.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) fn static_def(p: &mut Parser, m: Marker) { 5pub(super) fn static_def(p: &mut Parser, m: Marker) {
diff --git a/crates/ra_parser/src/grammar/items/nominal.rs b/crates/ra_parser/src/grammar/items/nominal.rs
index bede3b692..9d8fb8486 100644
--- a/crates/ra_parser/src/grammar/items/nominal.rs
+++ b/crates/ra_parser/src/grammar/items/nominal.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) { 5pub(super) fn struct_def(p: &mut Parser, m: Marker, kind: SyntaxKind) {
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs
index 3742fd197..2c560e824 100644
--- a/crates/ra_parser/src/grammar/items/traits.rs
+++ b/crates/ra_parser/src/grammar/items/traits.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3// test trait_item 5// test trait_item
diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs
index 63ac37e9e..e3b991c8c 100644
--- a/crates/ra_parser/src/grammar/items/use_item.rs
+++ b/crates/ra_parser/src/grammar/items/use_item.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) fn use_item(p: &mut Parser, m: Marker) { 5pub(super) fn use_item(p: &mut Parser, m: Marker) {
diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs
index efc329243..c10b53316 100644
--- a/crates/ra_parser/src/grammar/params.rs
+++ b/crates/ra_parser/src/grammar/params.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3// test param_list 5// test param_list
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs
index 24b65128e..ca8e075a1 100644
--- a/crates/ra_parser/src/grammar/paths.rs
+++ b/crates/ra_parser/src/grammar/paths.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) const PATH_FIRST: TokenSet = 5pub(super) const PATH_FIRST: TokenSet =
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs
index aa9a6d18e..f5d12278c 100644
--- a/crates/ra_parser/src/grammar/patterns.rs
+++ b/crates/ra_parser/src/grammar/patterns.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST 5pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST
diff --git a/crates/ra_parser/src/grammar/type_args.rs b/crates/ra_parser/src/grammar/type_args.rs
index 8e97fe03c..7256c2697 100644
--- a/crates/ra_parser/src/grammar/type_args.rs
+++ b/crates/ra_parser/src/grammar/type_args.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) { 5pub(super) fn opt_type_arg_list(p: &mut Parser, colon_colon_required: bool) {
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs
index 7071c70ea..34406b5bd 100644
--- a/crates/ra_parser/src/grammar/type_params.rs
+++ b/crates/ra_parser/src/grammar/type_params.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) fn opt_type_param_list(p: &mut Parser) { 5pub(super) fn opt_type_param_list(p: &mut Parser) {
diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs
index 4e3522d48..d4ca94fca 100644
--- a/crates/ra_parser/src/grammar/types.rs
+++ b/crates/ra_parser/src/grammar/types.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use super::*; 3use super::*;
2 4
3pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![ 5pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs
index f8fba6860..dafd5247b 100644
--- a/crates/ra_parser/src/parser.rs
+++ b/crates/ra_parser/src/parser.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use std::cell::Cell; 3use std::cell::Cell;
2 4
3use drop_bomb::DropBomb; 5use drop_bomb::DropBomb;
diff --git a/crates/ra_parser/src/syntax_kind.rs b/crates/ra_parser/src/syntax_kind.rs
index 3efcfa403..8d6bd057b 100644
--- a/crates/ra_parser/src/syntax_kind.rs
+++ b/crates/ra_parser/src/syntax_kind.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1#[macro_use] 3#[macro_use]
2mod generated; 4mod generated;
3 5
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs
index 8b43d93fe..96b5bce88 100644
--- a/crates/ra_parser/src/syntax_kind/generated.rs
+++ b/crates/ra_parser/src/syntax_kind/generated.rs
@@ -1,4 +1,4 @@
1// Generated file, do not edit by hand, see `crate/ra_tools/src/codegen` 1//! Generated file, do not edit by hand, see `crate/ra_tools/src/codegen`
2 2
3#![allow(bad_style, missing_docs, unreachable_pub)] 3#![allow(bad_style, missing_docs, unreachable_pub)]
4#[doc = r" The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`."] 4#[doc = r" The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`."]
diff --git a/crates/ra_parser/src/token_set.rs b/crates/ra_parser/src/token_set.rs
index 79121b35f..6dc061889 100644
--- a/crates/ra_parser/src/token_set.rs
+++ b/crates/ra_parser/src/token_set.rs
@@ -1,3 +1,5 @@
1//! FIXME: write short doc here
2
1use crate::SyntaxKind; 3use crate::SyntaxKind;
2 4
3/// A bit-set of `SyntaxKind`s 5/// A bit-set of `SyntaxKind`s