diff options
author | Marijn Suijten <[email protected]> | 2020-11-17 19:02:46 +0000 |
---|---|---|
committer | Marijn Suijten <[email protected]> | 2021-01-03 11:05:52 +0000 |
commit | 42da26e9597443812da5a59b3fa48bdcbf619666 (patch) | |
tree | 8332cb8b91cd04fe0c15eec11f659b6095408112 /crates | |
parent | cc081b7e1c68360ec157a31fa7fa32a38345e8d6 (diff) |
parser,syntax: Add separate parser for stmt with optional semicolon
Adjusting `grammar::fragments::stmt` to Optional or Yes will break
original functionality and tests.
Diffstat (limited to 'crates')
15 files changed, 72 insertions, 5 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 63cc90027..bb9ffea8b 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs | |||
@@ -66,6 +66,10 @@ pub(crate) mod fragments { | |||
66 | expressions::stmt(p, expressions::StmtWithSemi::No) | 66 | expressions::stmt(p, expressions::StmtWithSemi::No) |
67 | } | 67 | } |
68 | 68 | ||
69 | pub(crate) fn stmt_optional_semi(p: &mut Parser) { | ||
70 | expressions::stmt(p, expressions::StmtWithSemi::Optional) | ||
71 | } | ||
72 | |||
69 | pub(crate) fn opt_visibility(p: &mut Parser) { | 73 | pub(crate) fn opt_visibility(p: &mut Parser) { |
70 | let _ = super::opt_visibility(p); | 74 | let _ = super::opt_visibility(p); |
71 | } | 75 | } |
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 811e740f9..9dfe63028 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs | |||
@@ -88,6 +88,7 @@ pub enum FragmentKind { | |||
88 | Path, | 88 | Path, |
89 | Expr, | 89 | Expr, |
90 | Statement, | 90 | Statement, |
91 | StatementOptionalSemi, | ||
91 | Type, | 92 | Type, |
92 | Pattern, | 93 | Pattern, |
93 | Item, | 94 | Item, |
@@ -118,6 +119,7 @@ pub fn parse_fragment( | |||
118 | FragmentKind::Visibility => grammar::fragments::opt_visibility, | 119 | FragmentKind::Visibility => grammar::fragments::opt_visibility, |
119 | FragmentKind::MetaItem => grammar::fragments::meta_item, | 120 | FragmentKind::MetaItem => grammar::fragments::meta_item, |
120 | FragmentKind::Statement => grammar::fragments::stmt, | 121 | FragmentKind::Statement => grammar::fragments::stmt, |
122 | FragmentKind::StatementOptionalSemi => grammar::fragments::stmt_optional_semi, | ||
121 | FragmentKind::Items => grammar::fragments::macro_items, | 123 | FragmentKind::Items => grammar::fragments::macro_items, |
122 | FragmentKind::Statements => grammar::fragments::macro_stmts, | 124 | FragmentKind::Statements => grammar::fragments::macro_stmts, |
123 | FragmentKind::Attr => grammar::fragments::attr, | 125 | FragmentKind::Attr => grammar::fragments::attr, |
diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 51ae3da07..da151e328 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs | |||
@@ -215,7 +215,7 @@ impl ast::Attr { | |||
215 | impl ast::Stmt { | 215 | impl ast::Stmt { |
216 | /// Returns `text`, parsed as statement, but only if it has no errors. | 216 | /// Returns `text`, parsed as statement, but only if it has no errors. |
217 | pub fn parse(text: &str) -> Result<Self, ()> { | 217 | pub fn parse(text: &str) -> Result<Self, ()> { |
218 | parsing::parse_text_fragment(text, parser::FragmentKind::Statement) | 218 | parsing::parse_text_fragment(text, parser::FragmentKind::StatementOptionalSemi) |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_fn_call.rast b/crates/syntax/test_data/parser/fragments/stmt/err/0000_fn_call.rast deleted file mode 100644 index 5df7507e2..000000000 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_fn_call.rast +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | ERROR | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_let_stmt.rast b/crates/syntax/test_data/parser/fragments/stmt/err/0000_let_stmt.rast deleted file mode 100644 index 5df7507e2..000000000 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_let_stmt.rast +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | ERROR | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_let_stmt.rast b/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_let_stmt.rast deleted file mode 100644 index 5df7507e2..000000000 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_let_stmt.rast +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | ERROR | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_unterminated_let_stmt.rast b/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_unterminated_let_stmt.rast deleted file mode 100644 index 5df7507e2..000000000 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_unterminated_let_stmt.rast +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | ERROR | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/ok/0000_fn_call.rast b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_fn_call.rast new file mode 100644 index 000000000..8c186da93 --- /dev/null +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_fn_call.rast | |||
@@ -0,0 +1,11 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] | ||
4 | [email protected] | ||
5 | [email protected] | ||
6 | [email protected] | ||
7 | [email protected] "foo" | ||
8 | [email protected] | ||
9 | [email protected] "(" | ||
10 | [email protected] ")" | ||
11 | [email protected] ";" | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_fn_call.rs b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_fn_call.rs index a280f9a5c..a280f9a5c 100644 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_fn_call.rs +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_fn_call.rs | |||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/ok/0000_let_stmt.rast b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_let_stmt.rast new file mode 100644 index 000000000..8ab38da21 --- /dev/null +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_let_stmt.rast | |||
@@ -0,0 +1,12 @@ | |||
1 | [email protected] | ||
2 | [email protected] "let" | ||
3 | [email protected] " " | ||
4 | [email protected] | ||
5 | [email protected] | ||
6 | [email protected] "x" | ||
7 | [email protected] " " | ||
8 | [email protected] "=" | ||
9 | [email protected] " " | ||
10 | [email protected] | ||
11 | [email protected] "10" | ||
12 | [email protected] ";" | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_let_stmt.rs b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_let_stmt.rs index de8a7f1fc..de8a7f1fc 100644 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_let_stmt.rs +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_let_stmt.rs | |||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_let_stmt.rast b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_let_stmt.rast new file mode 100644 index 000000000..81d6df29a --- /dev/null +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_let_stmt.rast | |||
@@ -0,0 +1,21 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] | ||
4 | [email protected] | ||
5 | [email protected] | ||
6 | [email protected] "m1" | ||
7 | [email protected] "!" | ||
8 | [email protected] | ||
9 | [email protected] "{" | ||
10 | [email protected] " " | ||
11 | [email protected] "let" | ||
12 | [email protected] " " | ||
13 | [email protected] "a" | ||
14 | [email protected] " " | ||
15 | [email protected] "=" | ||
16 | [email protected] " " | ||
17 | [email protected] "0" | ||
18 | [email protected] ";" | ||
19 | [email protected] " " | ||
20 | [email protected] "}" | ||
21 | [email protected] ";" | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_let_stmt.rs b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_let_stmt.rs index 075f30159..075f30159 100644 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_let_stmt.rs +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_let_stmt.rs | |||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_unterminated_let_stmt.rast b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_unterminated_let_stmt.rast new file mode 100644 index 000000000..81d6df29a --- /dev/null +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_unterminated_let_stmt.rast | |||
@@ -0,0 +1,21 @@ | |||
1 | [email protected] | ||
2 | [email protected] | ||
3 | [email protected] | ||
4 | [email protected] | ||
5 | [email protected] | ||
6 | [email protected] "m1" | ||
7 | [email protected] "!" | ||
8 | [email protected] | ||
9 | [email protected] "{" | ||
10 | [email protected] " " | ||
11 | [email protected] "let" | ||
12 | [email protected] " " | ||
13 | [email protected] "a" | ||
14 | [email protected] " " | ||
15 | [email protected] "=" | ||
16 | [email protected] " " | ||
17 | [email protected] "0" | ||
18 | [email protected] ";" | ||
19 | [email protected] " " | ||
20 | [email protected] "}" | ||
21 | [email protected] ";" | ||
diff --git a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_unterminated_let_stmt.rs b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_unterminated_let_stmt.rs index 075f30159..075f30159 100644 --- a/crates/syntax/test_data/parser/fragments/stmt/err/0000_macro_unterminated_let_stmt.rs +++ b/crates/syntax/test_data/parser/fragments/stmt/ok/0000_macro_unterminated_let_stmt.rs | |||