Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor expression parsing thoroughly #67112

Merged
merged 32 commits into from
Dec 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e77b9d3
refactor parse_field
Centril Dec 4, 2019
8480b31
extract recover_struct_comma_after_dotdot
Centril Dec 4, 2019
701b974
extract find_struct_error_after_field_looking_code
Centril Dec 4, 2019
66b8ae4
extract error_struct_lit_not_allowed_here
Centril Dec 4, 2019
f6e2bdc
extract is_certainly_not_a_block
Centril Dec 4, 2019
de2e443
make parse_async_block conventional
Centril Dec 6, 2019
7262dcc
refactor loop parsing a bit
Centril Dec 6, 2019
44ff4df
more recovery in if-parsing
Centril Dec 6, 2019
7bcc325
refactor parse_if_expr
Centril Dec 6, 2019
ad6f91a
refactor parse_fn_block_param
Centril Dec 6, 2019
f647c11
simplify parse_fn_block_decl
Centril Dec 6, 2019
aa8adba
simplify parse_literal_maybe_minus
Centril Dec 6, 2019
0bb3dad
extract error_float_lits-must_have_int_part
Centril Dec 6, 2019
98701b2
extract parse_index_expr & refactor parse_dot_suffix
Centril Dec 6, 2019
287ba5d
extract parse_fn_call_expr
Centril Dec 6, 2019
a15d0cd
extract parse_tuple_field_access_expr
Centril Dec 6, 2019
ff5762b
extract recover_field_access_by_float_lit
Centril Dec 6, 2019
9c6bbf1
extract error_unexpected_after_dot and de-fatalize
Centril Dec 6, 2019
bc95228
extract parse_dot_suffix_expr
Centril Dec 7, 2019
7ae12c9
extract parse_dot_base_expr
Centril Dec 7, 2019
af5ac23
simplify parse_dot_call_or_expr
Centril Dec 7, 2019
84f9bf1
refactor parse_address_of -> parse_borrow_expr
Centril Dec 7, 2019
00cc8a1
simplify parse_assoc_op_cast
Centril Dec 7, 2019
80eeefb
extract recover_not_expr
Centril Dec 7, 2019
ada388b
extract is_mistaken_not_ident_negation
Centril Dec 7, 2019
f6ab439
extract parse_deref_expr
Centril Dec 7, 2019
4cfcfe9
extract parse_neg_expr
Centril Dec 7, 2019
efdea63
extract parse_prefix_expr
Centril Dec 7, 2019
8456c40
extract parse_not_expr
Centril Dec 7, 2019
e43a7ef
simplify parse_prefix_range_expr
Centril Dec 7, 2019
05c26a4
refactor assoc op parsing
Centril Dec 7, 2019
7a246ac
fix rebase fallout
Centril Dec 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/librustc_parse/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{Parser, PathStyle, TokenType};
use rustc_errors::PResult;
use syntax::ast;
use syntax::attr;
use syntax::print::pprust;
use syntax::token::{self, Nonterminal};
use syntax::util::comments;
use syntax_pos::{Span, Symbol};
Expand Down Expand Up @@ -154,7 +155,7 @@ impl<'a> Parser<'a> {
(attr_sp, item, style)
}
_ => {
let token_str = self.this_token_to_string();
let token_str = pprust::token_to_string(&self.token);
return Err(self.fatal(&format!("expected `#`, found `{}`", token_str)));
}
};
Expand Down Expand Up @@ -329,7 +330,7 @@ impl<'a> Parser<'a> {
Err(ref mut err) => err.cancel(),
}

let found = self.this_token_to_string();
let found = pprust::token_to_string(&self.token);
let msg = format!("expected unsuffixed literal or identifier, found `{}`", found);
Err(self.diagnostic().struct_span_err(self.token.span, &msg))
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'a> Parser<'a> {
pub(super) fn expected_ident_found(&self) -> DiagnosticBuilder<'a> {
let mut err = self.struct_span_err(
self.token.span,
&format!("expected identifier, found {}", self.this_token_descr()),
&format!("expected identifier, found {}", super::token_descr(&self.token)),
);
let valid_follow = &[
TokenKind::Eq,
Expand All @@ -225,7 +225,7 @@ impl<'a> Parser<'a> {
);
}
}
if let Some(token_descr) = self.token_descr() {
if let Some(token_descr) = super::token_descr_opt(&self.token) {
err.span_label(self.token.span, format!("expected identifier, found {}", token_descr));
} else {
err.span_label(self.token.span, "expected identifier");
Expand Down Expand Up @@ -272,7 +272,7 @@ impl<'a> Parser<'a> {
expected.sort_by_cached_key(|x| x.to_string());
expected.dedup();
let expect = tokens_to_string(&expected[..]);
let actual = self.this_token_descr();
let actual = super::token_descr(&self.token);
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {
let short_expect = if expected.len() > 6 {
format!("{} possible tokens", expected.len())
Expand Down Expand Up @@ -815,7 +815,7 @@ impl<'a> Parser<'a> {
t: &TokenKind,
) -> PResult<'a, bool /* recovered */> {
let token_str = pprust::token_kind_to_string(t);
let this_token_str = self.this_token_descr();
let this_token_str = super::token_descr(&self.token);
let (prev_sp, sp) = match (&self.token.kind, self.subparser_name) {
// Point at the end of the macro call when reaching end of macro arguments.
(token::Eof, Some(_)) => {
Expand Down Expand Up @@ -862,7 +862,7 @@ impl<'a> Parser<'a> {
return Ok(());
}
let sm = self.sess.source_map();
let msg = format!("expected `;`, found `{}`", self.this_token_descr());
let msg = format!("expected `;`, found `{}`", super::token_descr(&self.token));
let appl = Applicability::MachineApplicable;
if self.token.span == DUMMY_SP || self.prev_span == DUMMY_SP {
// Likely inside a macro, can't provide meaninful suggestions.
Expand Down Expand Up @@ -1270,7 +1270,7 @@ impl<'a> Parser<'a> {
}

pub(super) fn expected_semi_or_open_brace<T>(&mut self) -> PResult<'a, T> {
let token_str = self.this_token_descr();
let token_str = super::token_descr(&self.token);
let mut err = self.fatal(&format!("expected `;` or `{{`, found {}", token_str));
err.span_label(self.token.span, "expected `;` or `{`");
Err(err)
Expand Down Expand Up @@ -1447,7 +1447,7 @@ impl<'a> Parser<'a> {
}
_ => (
self.token.span,
format!("expected expression, found {}", self.this_token_descr(),),
format!("expected expression, found {}", super::token_descr(&self.token),),
),
};
let mut err = self.struct_span_err(span, &msg);
Expand Down
Loading