diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 8ddf50db043a..bf8430294110 100644 --- a/crates/parser/src/grammar.rs +++ b/crates/parser/src/grammar.rs @@ -94,7 +94,17 @@ pub(crate) mod entry { pub(crate) fn source_file(p: &mut Parser<'_>) { let m = p.start(); + // test frontmatter + // #!/usr/bin/env cargo + // + // --- + // [dependencies] + // clap = { version = "4.2", features = ["derive"] } + // --- + // + // fn main() {} p.eat(SHEBANG); + p.eat(FRONTMATTER); items::mod_contents(p, false); m.complete(p, SOURCE_FILE); } diff --git a/crates/parser/test_data/generated/runner.rs b/crates/parser/test_data/generated/runner.rs index c56eb5090cee..7f5ff0ec0735 100644 --- a/crates/parser/test_data/generated/runner.rs +++ b/crates/parser/test_data/generated/runner.rs @@ -265,6 +265,8 @@ mod ok { #[test] fn for_type() { run_and_expect_no_errors("test_data/parser/inline/ok/for_type.rs"); } #[test] + fn frontmatter() { run_and_expect_no_errors("test_data/parser/inline/ok/frontmatter.rs"); } + #[test] fn full_range_expr() { run_and_expect_no_errors("test_data/parser/inline/ok/full_range_expr.rs"); } diff --git a/crates/parser/test_data/parser/inline/ok/frontmatter.rast b/crates/parser/test_data/parser/inline/ok/frontmatter.rast new file mode 100644 index 000000000000..bad895929316 --- /dev/null +++ b/crates/parser/test_data/parser/inline/ok/frontmatter.rast @@ -0,0 +1,18 @@ +SOURCE_FILE + SHEBANG "#!/usr/bin/env cargo\n" + FRONTMATTER "\n---\n[dependencies]\nclap = { version = \"4.2\", features = [\"derive\"] }\n---\n" + WHITESPACE "\n" + FN + FN_KW "fn" + WHITESPACE " " + NAME + IDENT "main" + PARAM_LIST + L_PAREN "(" + R_PAREN ")" + WHITESPACE " " + BLOCK_EXPR + STMT_LIST + L_CURLY "{" + R_CURLY "}" + WHITESPACE "\n" diff --git a/crates/parser/test_data/parser/inline/ok/frontmatter.rs b/crates/parser/test_data/parser/inline/ok/frontmatter.rs new file mode 100644 index 000000000000..1f9f7a76284c --- /dev/null +++ b/crates/parser/test_data/parser/inline/ok/frontmatter.rs @@ -0,0 +1,8 @@ +#!/usr/bin/env cargo + +--- +[dependencies] +clap = { version = "4.2", features = ["derive"] } +--- + +fn main() {}