Skip to content

Commit

Permalink
Revert to f6f7c5
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Dec 19, 2018
1 parent 1cb0194 commit ad00d0c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 36 deletions.
39 changes: 13 additions & 26 deletions crates/ra_syntax/src/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,18 @@ fn current_op(p: &Parser) -> (u8, Op) {
// Parses expression with binding power of at least bp.
fn expr_bp(p: &mut Parser, r: Restrictions, bp: u8) -> BlockLike {
let mut lhs = match lhs(p, r) {
(Some(lhs), macro_blocklike) => {
Some(lhs) => {
// test stmt_bin_expr_ambiguity
// fn foo() {
// let _ = {1} & 2;
// {1} &2;
// }
if r.prefer_stmt && (is_block(lhs.kind()) || macro_blocklike == Some(BlockLike::Block))
{
if r.prefer_stmt && is_block(lhs.kind()) {
return BlockLike::Block;
}
lhs
}
(None, _) => return BlockLike::NotBlock,
None => return BlockLike::NotBlock,
};

loop {
Expand Down Expand Up @@ -214,7 +213,7 @@ const LHS_FIRST: TokenSet = token_set_union![
atom::ATOM_EXPR_FIRST,
];

fn lhs(p: &mut Parser, r: Restrictions) -> (Option<CompletedMarker>, Option<BlockLike>) {
fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
let m;
let kind = match p.current() {
// test ref_expr
Expand Down Expand Up @@ -247,29 +246,18 @@ fn lhs(p: &mut Parser, r: Restrictions) -> (Option<CompletedMarker>, Option<Bloc
if p.at_ts(EXPR_FIRST) {
expr_bp(p, r, 2);
}
return (Some(m.complete(p, RANGE_EXPR)), None);
return Some(m.complete(p, RANGE_EXPR));
}
_ => {
let (lhs_marker, macro_block_like) = atom::atom_expr(p, r);

if macro_block_like == Some(BlockLike::Block) {
return (lhs_marker, macro_block_like);
}
if let Some(lhs_marker) = lhs_marker {
return (Some(postfix_expr(p, r, lhs_marker)), macro_block_like);
} else {
return (None, None);
}
let lhs = atom::atom_expr(p, r)?;
return Some(postfix_expr(p, r, lhs));
}
};
expr_bp(p, r, 255);
(Some(m.complete(p, kind)), None)
Some(m.complete(p, kind))
}

fn postfix_expr(p: &mut Parser, r: Restrictions, mut lhs: CompletedMarker) -> CompletedMarker {
// Calls are disallowed if the type is a block and we prefer statements because the call cannot be disambiguated from a tuple
// E.g. `while true {break}();` is parsed as
// `while true {break}; ();`
let mut allow_calls = !r.prefer_stmt || !is_block(lhs.kind());
loop {
lhs = match p.current() {
Expand Down Expand Up @@ -418,22 +406,21 @@ fn arg_list(p: &mut Parser) {
// let _ = ::a::<b>;
// let _ = format!();
// }
fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, Option<BlockLike>) {
fn path_expr(p: &mut Parser, r: Restrictions) -> CompletedMarker {
assert!(paths::is_path_start(p) || p.at(L_ANGLE));
let m = p.start();
paths::expr_path(p);
let res = match p.current() {
match p.current() {
L_CURLY if !r.forbid_structs => {
named_field_list(p);
m.complete(p, STRUCT_LIT)
}
EXCL => {
let block_like = items::macro_call_after_excl(p); // TODO: Use return type (BlockLike)
return (m.complete(p, MACRO_CALL), Some(block_like));
items::macro_call_after_excl(p); // TODO: Use return type (BlockLike)
m.complete(p, MACRO_CALL)
}
_ => m.complete(p, PATH_EXPR),
};
(res, None)
}
}

// test struct_lit
Expand Down
16 changes: 6 additions & 10 deletions crates/ra_syntax/src/grammar/expressions/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,12 @@ pub(super) const ATOM_EXPR_FIRST: TokenSet = token_set_union![

const EXPR_RECOVERY_SET: TokenSet = token_set![LET_KW];

pub(super) fn atom_expr(
p: &mut Parser,
r: Restrictions,
) -> (Option<CompletedMarker>, Option<BlockLike>) {
pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
if let Some(m) = literal(p) {
return (Some(m), None);
return Some(m);
}
if paths::is_path_start(p) || p.at(L_ANGLE) {
let path_expr = path_expr(p, r);
return (Some(path_expr.0), path_expr.1);
return Some(path_expr(p, r));
}
let la = p.nth(1);
let done = match p.current() {
Expand Down Expand Up @@ -98,7 +94,7 @@ pub(super) fn atom_expr(
// }
p.error("expected a loop");
m.complete(p, ERROR);
return (None, None);
return None;
}
}
}
Expand All @@ -115,10 +111,10 @@ pub(super) fn atom_expr(
BREAK_KW => break_expr(p),
_ => {
p.err_recover("expected expression", EXPR_RECOVERY_SET);
return (None, None);
return None;
}
};
(Some(done), None)
Some(done)
}

// test tuple_expr
Expand Down
3 changes: 3 additions & 0 deletions crates/ra_syntax/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn parser_fuzz_tests() {
fn self_hosting_parsing() {
let empty_vec = vec![];
let dir = project_dir();
let mut count = 0u32;
for entry in walkdir::WalkDir::new(dir)
.into_iter()
.filter_entry(|entry| {
Expand All @@ -63,6 +64,7 @@ fn self_hosting_parsing() {
!entry.path().is_dir() && (entry.path().extension() == Some(std::ffi::OsStr::new("rs")))
})
{
count += 1;
let text = read_text(entry.path());
let node = SourceFileNode::parse(&text);
let errors = node.errors();
Expand All @@ -72,6 +74,7 @@ fn self_hosting_parsing() {
entry
);
}
panic!("{}", count)
}
/// Read file and normalize newlines.
///
Expand Down

0 comments on commit ad00d0c

Please sign in to comment.