aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/expressions
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-19 10:36:17 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-19 10:36:17 +0000
commit5b6ad0971c050981deb10c56ad2634293f104228 (patch)
tree7f76ce1da6ed9e245f5b4ef14257418c66f59577 /crates/ra_parser/src/grammar/expressions
parent91576afc7e64f11dde2bed14b578e4914d253a6a (diff)
parent4cf179c089aeed381cd67bcd265e76a27f11facd (diff)
Merge #996
996: Allow attributes on top level expressions r=matklad a=pcpthm This PR modifies parser to allow outer attributes on top level expression. Here, top level expression means either - Expression statement e.g. `foo();` - Last expression in a block without semicolon `bar()` in `{ foo(); bar() }`. Except for binary operation expressions and `if` expressions, which are errors (feature gated) in rustc. Attributes on inner expressions like `foo(#[a] 1)` are not implemented. I first tried to implement this by passing `Maker` to expression parsers. However, this implementation couldn't parse `#[attr] foo()` correctly as `CallExpr(Attr(..), PathExpr(..), ArgList(..))` and instead parsed incorrectly as `CallExpr(PathExpr(Attr(..), ..), ArgList(..))` due to the way left recursion is handled. In the end, I introduce `undo_completion` method. Which is not the suggested approach, but it seems not very bad. Fix #759. Co-authored-by: pcpthm <[email protected]>
Diffstat (limited to 'crates/ra_parser/src/grammar/expressions')
-rw-r--r--crates/ra_parser/src/grammar/expressions/atom.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs
index d933288cd..a23977bfb 100644
--- a/crates/ra_parser/src/grammar/expressions/atom.rs
+++ b/crates/ra_parser/src/grammar/expressions/atom.rs
@@ -392,9 +392,9 @@ fn match_arm(p: &mut Parser) -> BlockLike {
392 match_guard(p); 392 match_guard(p);
393 } 393 }
394 p.expect(FAT_ARROW); 394 p.expect(FAT_ARROW);
395 let ret = expr_stmt(p); 395 let blocklike = expr_stmt(p).1;
396 m.complete(p, MATCH_ARM); 396 m.complete(p, MATCH_ARM);
397 ret 397 blocklike
398} 398}
399 399
400// test match_guard 400// test match_guard