Unnamed repository; edit this file 'description' to name the repository.
rename
Aleksey Kladov 2021-12-29
parent 8234a85 · commit f5cfc05
-rw-r--r--crates/parser/src/grammar.rs4
-rw-r--r--crates/parser/src/grammar/expressions.rs35
2 files changed, 19 insertions, 20 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs
index 234e584eeb..b704242065 100644
--- a/crates/parser/src/grammar.rs
+++ b/crates/parser/src/grammar.rs
@@ -59,7 +59,7 @@ pub(crate) mod entry {
}
pub(crate) fn stmt(p: &mut Parser) {
- expressions::stmt(p, expressions::StmtWithSemi::No);
+ expressions::stmt(p, expressions::Semicolon::Forbidden);
}
pub(crate) fn pat(p: &mut Parser) {
@@ -103,7 +103,7 @@ pub(crate) mod entry {
continue;
}
- expressions::stmt(p, expressions::StmtWithSemi::Optional);
+ expressions::stmt(p, expressions::Semicolon::Optional);
}
m.complete(p, MACRO_STMTS);
diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs
index 3238b6e9f4..c585fdb096 100644
--- a/crates/parser/src/grammar/expressions.rs
+++ b/crates/parser/src/grammar/expressions.rs
@@ -6,10 +6,10 @@ pub(crate) use self::atom::{block_expr, match_arm_list};
pub(super) use self::atom::{literal, LITERAL_FIRST};
#[derive(PartialEq, Eq)]
-pub(super) enum StmtWithSemi {
- Yes,
- No,
+pub(super) enum Semicolon {
+ Required,
Optional,
+ Forbidden,
}
const EXPR_FIRST: TokenSet = LHS_FIRST;
@@ -29,7 +29,7 @@ fn expr_no_struct(p: &mut Parser) {
expr_bp(p, None, r, 1);
}
-pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
+pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) {
let m = p.start();
// test attr_on_expr_stmt
// fn foo() {
@@ -41,7 +41,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
attributes::outer_attrs(p);
if p.at(T![let]) {
- let_stmt(p, m, with_semi);
+ let_stmt(p, m, semicolon);
return;
}
@@ -53,7 +53,7 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
};
if let Some((cm, blocklike)) = expr_stmt(p, Some(m)) {
- if !(p.at(T!['}']) || (with_semi != StmtWithSemi::Yes && p.at(EOF))) {
+ if !(p.at(T!['}']) || (semicolon != Semicolon::Required && p.at(EOF))) {
// test no_semi_after_block
// fn foo() {
// if true {}
@@ -69,27 +69,26 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
// test!{}
// }
let m = cm.precede(p);
- match with_semi {
- StmtWithSemi::No => (),
- StmtWithSemi::Optional => {
- p.eat(T![;]);
- }
- StmtWithSemi::Yes => {
+ match semicolon {
+ Semicolon::Required => {
if blocklike.is_block() {
p.eat(T![;]);
} else {
p.expect(T![;]);
}
}
+ Semicolon::Optional => {
+ p.eat(T![;]);
+ }
+ Semicolon::Forbidden => (),
}
-
m.complete(p, EXPR_STMT);
}
}
// test let_stmt
// fn f() { let x: i32 = 92; }
- fn let_stmt(p: &mut Parser, m: Marker, with_semi: StmtWithSemi) {
+ fn let_stmt(p: &mut Parser, m: Marker, with_semi: Semicolon) {
p.bump(T![let]);
patterns::pattern(p);
if p.at(T![:]) {
@@ -114,11 +113,11 @@ pub(super) fn stmt(p: &mut Parser, with_semi: StmtWithSemi) {
}
match with_semi {
- StmtWithSemi::No => (),
- StmtWithSemi::Optional => {
+ Semicolon::Forbidden => (),
+ Semicolon::Optional => {
p.eat(T![;]);
}
- StmtWithSemi::Yes => {
+ Semicolon::Required => {
p.expect(T![;]);
}
}
@@ -150,7 +149,7 @@ pub(super) fn expr_block_contents(p: &mut Parser) {
continue;
}
- stmt(p, StmtWithSemi::Yes);
+ stmt(p, Semicolon::Required);
}
}