Skip to content

Commit 288b931

Browse files
committed
Strip frontmatter in fewer places
1 parent 0911650 commit 288b931

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/parse/parser.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::{Path, PathBuf};
33

44
use rustc_ast::{ast, attr};
55
use rustc_errors::Diag;
6+
use rustc_parse::lexer::StripTokens;
67
use rustc_parse::parser::Parser as RawParser;
78
use rustc_parse::{exp, new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
89
use rustc_span::{Span, sym};
@@ -64,11 +65,14 @@ impl<'a> ParserBuilder<'a> {
6465
input: Input,
6566
) -> Result<RawParser<'a>, Vec<Diag<'a>>> {
6667
match input {
67-
Input::File(ref file) => new_parser_from_file(psess, file, None),
68+
Input::File(ref file) => {
69+
new_parser_from_file(psess, file, StripTokens::ShebangAndFrontmatter, None)
70+
}
6871
Input::Text(text) => new_parser_from_source_str(
6972
psess,
7073
rustc_span::FileName::Custom("stdin".to_owned()),
7174
text,
75+
StripTokens::ShebangAndFrontmatter,
7276
),
7377
}
7478
}
@@ -104,8 +108,12 @@ impl<'a> Parser<'a> {
104108
span: Span,
105109
) -> Result<(ast::AttrVec, ThinVec<Box<ast::Item>>, Span), ParserError> {
106110
let result = catch_unwind(AssertUnwindSafe(|| {
107-
let mut parser =
108-
unwrap_or_emit_fatal(new_parser_from_file(psess.inner(), path, Some(span)));
111+
let mut parser = unwrap_or_emit_fatal(new_parser_from_file(
112+
psess.inner(),
113+
path,
114+
StripTokens::ShebangAndFrontmatter,
115+
Some(span),
116+
));
109117
match parser.parse_mod(exp!(Eof)) {
110118
Ok((a, i, spans)) => Some((a, i, spans.inner_span)),
111119
Err(e) => {

0 commit comments

Comments
 (0)