mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
simplify
This commit is contained in:
parent
febbc9acdd
commit
749907d330
5 changed files with 14 additions and 9 deletions
|
@ -18,7 +18,7 @@ pub(crate) const LITERAL_FIRST: TokenSet =
|
|||
STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING];
|
||||
|
||||
pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> {
|
||||
if !LITERAL_FIRST.contains(p.current()) {
|
||||
if !p.at_ts(LITERAL_FIRST) {
|
||||
return None;
|
||||
}
|
||||
let m = p.start();
|
||||
|
@ -108,7 +108,7 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker {
|
|||
let mut saw_expr = false;
|
||||
while !p.at(EOF) && !p.at(R_PAREN) {
|
||||
saw_expr = true;
|
||||
if !EXPR_FIRST.contains(p.current()) {
|
||||
if !p.at_ts(EXPR_FIRST) {
|
||||
p.error("expected expression");
|
||||
break;
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker {
|
|||
if p.at(R_BRACK) {
|
||||
break;
|
||||
}
|
||||
if !EXPR_FIRST.contains(p.current()) {
|
||||
if !p.at_ts(EXPR_FIRST) {
|
||||
p.error("expected expression");
|
||||
break;
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ fn return_expr(p: &mut Parser) -> CompletedMarker {
|
|||
assert!(p.at(RETURN_KW));
|
||||
let m = p.start();
|
||||
p.bump();
|
||||
if EXPR_FIRST.contains(p.current()) {
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
}
|
||||
m.complete(p, RETURN_EXPR)
|
||||
|
@ -395,7 +395,7 @@ fn break_expr(p: &mut Parser) -> CompletedMarker {
|
|||
let m = p.start();
|
||||
p.bump();
|
||||
p.eat(LIFETIME);
|
||||
if EXPR_FIRST.contains(p.current()) {
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
}
|
||||
m.complete(p, BREAK_EXPR)
|
||||
|
|
|
@ -236,7 +236,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> {
|
|||
DOTDOT => {
|
||||
m = p.start();
|
||||
p.bump();
|
||||
if EXPR_FIRST.contains(p.current()) {
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr_bp(p, r, 2);
|
||||
}
|
||||
return Some(m.complete(p, RANGE_EXPR));
|
||||
|
@ -376,7 +376,7 @@ fn arg_list(p: &mut Parser) {
|
|||
let m = p.start();
|
||||
p.bump();
|
||||
while !p.at(R_PAREN) && !p.at(EOF) {
|
||||
if !EXPR_FIRST.contains(p.current()) {
|
||||
if !p.at_ts(EXPR_FIRST) {
|
||||
p.error("expected expression");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ fn list_(p: &mut Parser, flavor: Flavor) {
|
|||
opt_self_param(p);
|
||||
}
|
||||
while !p.at(EOF) && !p.at(ket) {
|
||||
if !VALUE_PARAMETER_FIRST.contains(p.current()) {
|
||||
if !p.at_ts(VALUE_PARAMETER_FIRST) {
|
||||
p.error("expected value parameter");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ fn tuple_pat_fields(p: &mut Parser) {
|
|||
match p.current() {
|
||||
DOTDOT => p.bump(),
|
||||
_ => {
|
||||
if !PATTERN_FIRST.contains(p.current()) {
|
||||
if !p.at_ts(PATTERN_FIRST) {
|
||||
p.error("expected a pattern");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,11 @@ impl<'t> Parser<'t> {
|
|||
self.current() == kind
|
||||
}
|
||||
|
||||
/// Checks if the current token is `kind`.
|
||||
pub(crate) fn at_ts(&self, kinds: TokenSet) -> bool {
|
||||
kinds.contains(self.current())
|
||||
}
|
||||
|
||||
pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> {
|
||||
self.0.next2()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue