Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More lexer improvements #102302

Merged
merged 15 commits into from
Sep 28, 2022
17 changes: 8 additions & 9 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ pub struct UnmatchedBrace {

pub(crate) fn parse_token_trees<'a>(
sess: &'a ParseSess,
src: &'a str,
start_pos: BytePos,
mut src: &'a str,
mut start_pos: BytePos,
override_span: Option<Span>,
) -> (PResult<'a, TokenStream>, Vec<UnmatchedBrace>) {
// Skip `#!`, if present.
if let Some(shebang_len) = rustc_lexer::strip_shebang(src) {
nnethercote marked this conversation as resolved.
Show resolved Hide resolved
src = &src[shebang_len..];
start_pos = start_pos + BytePos::from_usize(shebang_len);
}

StringReader { sess, start_pos, pos: start_pos, src, override_span }.into_token_trees()
}

Expand All @@ -65,13 +71,6 @@ impl<'a> StringReader<'a> {
fn next_token(&mut self) -> (Spacing, Token) {
let mut spacing = Spacing::Joint;

// Skip `#!` at the start of the file
if self.pos == self.start_pos
&& let Some(shebang_len) = rustc_lexer::strip_shebang(self.src)
{
self.pos = self.pos + BytePos::from_usize(shebang_len);
}

// Skip trivial (whitespace & comments) tokens
loop {
let start_src_index = self.src_index(self.pos);
Expand Down