diff options
Diffstat (limited to 'crates/libsyntax2')
-rw-r--r-- | crates/libsyntax2/src/grammar/expressions/atom.rs | 10 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar/expressions/mod.rs | 4 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar/params.rs | 2 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar/patterns.rs | 2 | ||||
-rw-r--r-- | crates/libsyntax2/src/parser_api.rs | 5 |
5 files changed, 14 insertions, 9 deletions
diff --git a/crates/libsyntax2/src/grammar/expressions/atom.rs b/crates/libsyntax2/src/grammar/expressions/atom.rs index 1488e12a4..fdb4718ba 100644 --- a/crates/libsyntax2/src/grammar/expressions/atom.rs +++ b/crates/libsyntax2/src/grammar/expressions/atom.rs | |||
@@ -18,7 +18,7 @@ pub(crate) const LITERAL_FIRST: TokenSet = | |||
18 | STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; | 18 | STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING]; |
19 | 19 | ||
20 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { | 20 | pub(crate) fn literal(p: &mut Parser) -> Option<CompletedMarker> { |
21 | if !LITERAL_FIRST.contains(p.current()) { | 21 | if !p.at_ts(LITERAL_FIRST) { |
22 | return None; | 22 | return None; |
23 | } | 23 | } |
24 | let m = p.start(); | 24 | let m = p.start(); |
@@ -108,7 +108,7 @@ fn tuple_expr(p: &mut Parser) -> CompletedMarker { | |||
108 | let mut saw_expr = false; | 108 | let mut saw_expr = false; |
109 | while !p.at(EOF) && !p.at(R_PAREN) { | 109 | while !p.at(EOF) && !p.at(R_PAREN) { |
110 | saw_expr = true; | 110 | saw_expr = true; |
111 | if !EXPR_FIRST.contains(p.current()) { | 111 | if !p.at_ts(EXPR_FIRST) { |
112 | p.error("expected expression"); | 112 | p.error("expected expression"); |
113 | break; | 113 | break; |
114 | } | 114 | } |
@@ -147,7 +147,7 @@ fn array_expr(p: &mut Parser) -> CompletedMarker { | |||
147 | if p.at(R_BRACK) { | 147 | if p.at(R_BRACK) { |
148 | break; | 148 | break; |
149 | } | 149 | } |
150 | if !EXPR_FIRST.contains(p.current()) { | 150 | if !p.at_ts(EXPR_FIRST) { |
151 | p.error("expected expression"); | 151 | p.error("expected expression"); |
152 | break; | 152 | break; |
153 | } | 153 | } |
@@ -360,7 +360,7 @@ fn return_expr(p: &mut Parser) -> CompletedMarker { | |||
360 | assert!(p.at(RETURN_KW)); | 360 | assert!(p.at(RETURN_KW)); |
361 | let m = p.start(); | 361 | let m = p.start(); |
362 | p.bump(); | 362 | p.bump(); |
363 | if EXPR_FIRST.contains(p.current()) { | 363 | if p.at_ts(EXPR_FIRST) { |
364 | expr(p); | 364 | expr(p); |
365 | } | 365 | } |
366 | m.complete(p, RETURN_EXPR) | 366 | m.complete(p, RETURN_EXPR) |
@@ -395,7 +395,7 @@ fn break_expr(p: &mut Parser) -> CompletedMarker { | |||
395 | let m = p.start(); | 395 | let m = p.start(); |
396 | p.bump(); | 396 | p.bump(); |
397 | p.eat(LIFETIME); | 397 | p.eat(LIFETIME); |
398 | if EXPR_FIRST.contains(p.current()) { | 398 | if p.at_ts(EXPR_FIRST) { |
399 | expr(p); | 399 | expr(p); |
400 | } | 400 | } |
401 | m.complete(p, BREAK_EXPR) | 401 | m.complete(p, BREAK_EXPR) |
diff --git a/crates/libsyntax2/src/grammar/expressions/mod.rs b/crates/libsyntax2/src/grammar/expressions/mod.rs index f7b9f7086..d5ee91ad8 100644 --- a/crates/libsyntax2/src/grammar/expressions/mod.rs +++ b/crates/libsyntax2/src/grammar/expressions/mod.rs | |||
@@ -236,7 +236,7 @@ fn lhs(p: &mut Parser, r: Restrictions) -> Option<CompletedMarker> { | |||
236 | DOTDOT => { | 236 | DOTDOT => { |
237 | m = p.start(); | 237 | m = p.start(); |
238 | p.bump(); | 238 | p.bump(); |
239 | if EXPR_FIRST.contains(p.current()) { | 239 | if p.at_ts(EXPR_FIRST) { |
240 | expr_bp(p, r, 2); | 240 | expr_bp(p, r, 2); |
241 | } | 241 | } |
242 | return Some(m.complete(p, RANGE_EXPR)); | 242 | return Some(m.complete(p, RANGE_EXPR)); |
@@ -376,7 +376,7 @@ fn arg_list(p: &mut Parser) { | |||
376 | let m = p.start(); | 376 | let m = p.start(); |
377 | p.bump(); | 377 | p.bump(); |
378 | while !p.at(R_PAREN) && !p.at(EOF) { | 378 | while !p.at(R_PAREN) && !p.at(EOF) { |
379 | if !EXPR_FIRST.contains(p.current()) { | 379 | if !p.at_ts(EXPR_FIRST) { |
380 | p.error("expected expression"); | 380 | p.error("expected expression"); |
381 | break; | 381 | break; |
382 | } | 382 | } |
diff --git a/crates/libsyntax2/src/grammar/params.rs b/crates/libsyntax2/src/grammar/params.rs index bc0cb44ba..903c25939 100644 --- a/crates/libsyntax2/src/grammar/params.rs +++ b/crates/libsyntax2/src/grammar/params.rs | |||
@@ -48,7 +48,7 @@ fn list_(p: &mut Parser, flavor: Flavor) { | |||
48 | opt_self_param(p); | 48 | opt_self_param(p); |
49 | } | 49 | } |
50 | while !p.at(EOF) && !p.at(ket) { | 50 | while !p.at(EOF) && !p.at(ket) { |
51 | if !VALUE_PARAMETER_FIRST.contains(p.current()) { | 51 | if !p.at_ts(VALUE_PARAMETER_FIRST) { |
52 | p.error("expected value parameter"); | 52 | p.error("expected value parameter"); |
53 | break; | 53 | break; |
54 | } | 54 | } |
diff --git a/crates/libsyntax2/src/grammar/patterns.rs b/crates/libsyntax2/src/grammar/patterns.rs index aa20ae8e4..6dd3ab2fa 100644 --- a/crates/libsyntax2/src/grammar/patterns.rs +++ b/crates/libsyntax2/src/grammar/patterns.rs | |||
@@ -102,7 +102,7 @@ fn tuple_pat_fields(p: &mut Parser) { | |||
102 | match p.current() { | 102 | match p.current() { |
103 | DOTDOT => p.bump(), | 103 | DOTDOT => p.bump(), |
104 | _ => { | 104 | _ => { |
105 | if !PATTERN_FIRST.contains(p.current()) { | 105 | if !p.at_ts(PATTERN_FIRST) { |
106 | p.error("expected a pattern"); | 106 | p.error("expected a pattern"); |
107 | break; | 107 | break; |
108 | } | 108 | } |
diff --git a/crates/libsyntax2/src/parser_api.rs b/crates/libsyntax2/src/parser_api.rs index c4753140e..7d97159dd 100644 --- a/crates/libsyntax2/src/parser_api.rs +++ b/crates/libsyntax2/src/parser_api.rs | |||
@@ -35,6 +35,11 @@ impl<'t> Parser<'t> { | |||
35 | self.current() == kind | 35 | self.current() == kind |
36 | } | 36 | } |
37 | 37 | ||
38 | /// Checks if the current token is `kind`. | ||
39 | pub(crate) fn at_ts(&self, kinds: TokenSet) -> bool { | ||
40 | kinds.contains(self.current()) | ||
41 | } | ||
42 | |||
38 | pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> { | 43 | pub(crate) fn next2(&self) -> Option<(SyntaxKind, SyntaxKind)> { |
39 | self.0.next2() | 44 | self.0.next2() |
40 | } | 45 | } |