Skip to content

Commit f7de8ae

Browse files
authored
Merge pull request #20942 from ShoyuVanilla/frontmatter-err
fix: Do not make false positive syntax errors on frontmatter
2 parents 00ace81 + 3d636a6 commit f7de8ae

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

crates/parser/src/grammar.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,17 @@ pub(crate) mod entry {
9494

9595
pub(crate) fn source_file(p: &mut Parser<'_>) {
9696
let m = p.start();
97+
// test frontmatter
98+
// #!/usr/bin/env cargo
99+
//
100+
// ---
101+
// [dependencies]
102+
// clap = { version = "4.2", features = ["derive"] }
103+
// ---
104+
//
105+
// fn main() {}
97106
p.eat(SHEBANG);
107+
p.eat(FRONTMATTER);
98108
items::mod_contents(p, false);
99109
m.complete(p, SOURCE_FILE);
100110
}

crates/parser/test_data/generated/runner.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ mod ok {
265265
#[test]
266266
fn for_type() { run_and_expect_no_errors("test_data/parser/inline/ok/for_type.rs"); }
267267
#[test]
268+
fn frontmatter() { run_and_expect_no_errors("test_data/parser/inline/ok/frontmatter.rs"); }
269+
#[test]
268270
fn full_range_expr() {
269271
run_and_expect_no_errors("test_data/parser/inline/ok/full_range_expr.rs");
270272
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
SOURCE_FILE
2+
SHEBANG "#!/usr/bin/env cargo\n"
3+
FRONTMATTER "\n---\n[dependencies]\nclap = { version = \"4.2\", features = [\"derive\"] }\n---\n"
4+
WHITESPACE "\n"
5+
FN
6+
FN_KW "fn"
7+
WHITESPACE " "
8+
NAME
9+
IDENT "main"
10+
PARAM_LIST
11+
L_PAREN "("
12+
R_PAREN ")"
13+
WHITESPACE " "
14+
BLOCK_EXPR
15+
STMT_LIST
16+
L_CURLY "{"
17+
R_CURLY "}"
18+
WHITESPACE "\n"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env cargo
2+
3+
---
4+
[dependencies]
5+
clap = { version = "4.2", features = ["derive"] }
6+
---
7+
8+
fn main() {}

0 commit comments

Comments
 (0)