Unnamed repository; edit this file 'description' to name the repository.
fix: Do not make false positive syntax errors on frontmatter
| -rw-r--r-- | crates/parser/src/grammar.rs | 10 | ||||
| -rw-r--r-- | crates/parser/test_data/generated/runner.rs | 2 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/frontmatter.rast | 18 | ||||
| -rw-r--r-- | crates/parser/test_data/parser/inline/ok/frontmatter.rs | 8 |
4 files changed, 38 insertions, 0 deletions
diff --git a/crates/parser/src/grammar.rs b/crates/parser/src/grammar.rs index 8ddf50db04..bf84302941 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 c56eb5090c..7f5ff0ec07 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 0000000000..bad8959293 --- /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 0000000000..1f9f7a7628 --- /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() {} |